[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/38] linux-user: fix readlinkat handling with magic exe symlink
From: |
Laurent Vivier |
Subject: |
[PULL 02/38] linux-user: fix readlinkat handling with magic exe symlink |
Date: |
Wed, 28 Sep 2022 10:14:41 +0200 |
From: Jameson Nash <vtjnash@gmail.com>
Exactly the same as f17f4989fa193fa8279474c5462289a3cfe69aea before was
for readlink. I suppose this was simply missed at the time.
Signed-off-by: Jameson Nash <vtjnash@gmail.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220808190727.875155-1-vtjnash@gmail.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/syscall.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index f4091212027c..abf82bab2a18 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -9912,11 +9912,22 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int
num, abi_long arg1,
p2 = lock_user(VERIFY_WRITE, arg3, arg4, 0);
if (!p || !p2) {
ret = -TARGET_EFAULT;
+ } else if (!arg4) {
+ /* Short circuit this for the magic exe check. */
+ ret = -TARGET_EINVAL;
} else if (is_proc_myself((const char *)p, "exe")) {
char real[PATH_MAX], *temp;
temp = realpath(exec_path, real);
- ret = temp == NULL ? get_errno(-1) : strlen(real) ;
- snprintf((char *)p2, arg4, "%s", real);
+ /* Return value is # of bytes that we wrote to the buffer. */
+ if (temp == NULL) {
+ ret = get_errno(-1);
+ } else {
+ /* Don't worry about sign mismatch as earlier mapping
+ * logic would have thrown a bad address error. */
+ ret = MIN(strlen(real), arg4);
+ /* We cannot NUL terminate the string. */
+ memcpy(p2, real, ret);
+ }
} else {
ret = get_errno(readlinkat(arg1, path(p), p2, arg4));
}
--
2.37.3
- [PULL 00/38] Linux user for 7.2 patches, Laurent Vivier, 2022/09/28
- [PULL 03/38] linux-user: Add missing signals in strace output, Laurent Vivier, 2022/09/28
- [PULL 09/38] linux-user: Fix strace of chmod() if mode == 0, Laurent Vivier, 2022/09/28
- [PULL 08/38] linux-user/hppa: Dump IIR on register dump, Laurent Vivier, 2022/09/28
- [PULL 04/38] linux-user: Add missing clock_gettime64() syscall strace, Laurent Vivier, 2022/09/28
- [PULL 07/38] linux-user/hppa: Use EXCP_DUMP() to show enhanced debug info, Laurent Vivier, 2022/09/28
- [PULL 02/38] linux-user: fix readlinkat handling with magic exe symlink,
Laurent Vivier <=
- [PULL 18/38] linux-user: Fix TARGET_PROT_SEM for XTENSA, Laurent Vivier, 2022/09/28
- [PULL 19/38] linux-user: Add proper strace format strings for getdents()/getdents64(), Laurent Vivier, 2022/09/28
- [PULL 14/38] linux-user: Fix madvise(MADV_DONTNEED) on alpha, Laurent Vivier, 2022/09/28
- [PULL 05/38] linux-user: Add pidfd_open(), pidfd_send_signal() and pidfd_getfd() syscalls, Laurent Vivier, 2022/09/28
- [PULL 10/38] linux-user/hppa: Set TASK_UNMAPPED_BASE to 0xfa000000 for hppa arch, Laurent Vivier, 2022/09/28
- [PULL 13/38] linux-user: Provide MADV_* definitions, Laurent Vivier, 2022/09/28
- [PULL 23/38] linux-user/hppa: Allow PROT_GROWSUP and PROT_GROWSDOWN in mprotect(), Laurent Vivier, 2022/09/28
- [PULL 17/38] tests/tcg/linux-test: Add linux-madvise test, Laurent Vivier, 2022/09/28
- [PULL 12/38] linux-user: Show timespec on strace for futex(), Laurent Vivier, 2022/09/28
- [PULL 01/38] linux-user: use 'max' instead of 'qemu32' / 'qemu64' by default, Laurent Vivier, 2022/09/28