From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: "Laurent Vivier" <laurent@vivier.eu>,
"Ilya Leoshkevich" <iii@linux.ibm.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PULL 04/28] linux-user: Fix unaligned memory access in prlimit64 syscall
Date: Fri, 10 Mar 2023 23:09:03 +0100 [thread overview]
Message-ID: <20230310220927.326606-5-laurent@vivier.eu> (raw)
In-Reply-To: <20230310220927.326606-1-laurent@vivier.eu>
From: Ilya Leoshkevich <iii@linux.ibm.com>
target_rlimit64 contains uint64_t fields, so it's 8-byte aligned on
some hosts, while some guests may align their respective type on a
4-byte boundary. This may lead to an unaligned access, which is an UB.
Fix by defining the fields as abi_ullong. This makes the host alignment
match that of the guest, and lets the compiler know that it should emit
code that can deal with the guest alignment.
While at it, also use __get_user() and __put_user() instead of
tswap64().
Fixes: 163a05a8398b ("linux-user: Implement prlimit64 syscall")
Reported-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20230224003907.263914-2-iii@linux.ibm.com>
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
linux-user/generic/target_resource.h | 4 ++--
linux-user/syscall.c | 8 ++++----
2 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/linux-user/generic/target_resource.h b/linux-user/generic/target_resource.h
index 539d8c46772e..37d3eb09b3b3 100644
--- a/linux-user/generic/target_resource.h
+++ b/linux-user/generic/target_resource.h
@@ -12,8 +12,8 @@ struct target_rlimit {
};
struct target_rlimit64 {
- uint64_t rlim_cur;
- uint64_t rlim_max;
+ abi_ullong rlim_cur;
+ abi_ullong rlim_max;
};
#define TARGET_RLIM_INFINITY ((abi_ulong)-1)
diff --git a/linux-user/syscall.c b/linux-user/syscall.c
index 64b71b1ff94b..69cc4b6e4219 100644
--- a/linux-user/syscall.c
+++ b/linux-user/syscall.c
@@ -12876,8 +12876,8 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
if (!lock_user_struct(VERIFY_READ, target_rnew, arg3, 1)) {
return -TARGET_EFAULT;
}
- rnew.rlim_cur = tswap64(target_rnew->rlim_cur);
- rnew.rlim_max = tswap64(target_rnew->rlim_max);
+ __get_user(rnew.rlim_cur, &target_rnew->rlim_cur);
+ __get_user(rnew.rlim_max, &target_rnew->rlim_max);
unlock_user_struct(target_rnew, arg3, 0);
rnewp = &rnew;
}
@@ -12887,8 +12887,8 @@ static abi_long do_syscall1(CPUArchState *cpu_env, int num, abi_long arg1,
if (!lock_user_struct(VERIFY_WRITE, target_rold, arg4, 1)) {
return -TARGET_EFAULT;
}
- target_rold->rlim_cur = tswap64(rold.rlim_cur);
- target_rold->rlim_max = tswap64(rold.rlim_max);
+ __put_user(rold.rlim_cur, &target_rold->rlim_cur);
+ __put_user(rold.rlim_max, &target_rold->rlim_max);
unlock_user_struct(target_rold, arg4, 1);
}
return ret;
--
2.39.2
next prev parent reply other threads:[~2023-03-10 22:11 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-10 22:08 [PULL 00/28] Linux user for 8.0 patches Laurent Vivier
2023-03-10 22:09 ` [PULL 01/28] linux-user: Fix access to /proc/self/exe Laurent Vivier
2023-03-10 22:09 ` [PULL 02/28] linux-user: fix timerfd read endianness conversion Laurent Vivier
2023-03-10 22:09 ` [PULL 03/28] linux-user: add target to host netlink conversions Laurent Vivier
2023-03-10 22:09 ` Laurent Vivier [this message]
2023-03-10 22:09 ` [PULL 05/28] linux-user: add support for xtensa FDPIC Laurent Vivier
2023-03-10 22:09 ` [PULL 06/28] linux-user: fill out task state in /proc/self/stat Laurent Vivier
2023-03-10 22:09 ` [PULL 07/28] linux-user: Fix brk() to release pages Laurent Vivier
2023-03-10 22:09 ` [PULL 08/28] linux-user: Provide print_raw_param64() for 64-bit values Laurent Vivier
2023-03-10 22:09 ` [PULL 09/28] linux-user: Add strace for prlimit64() syscall Laurent Vivier
2023-03-10 22:09 ` [PULL 10/28] linux-user: fix sockaddr_in6 endianness Laurent Vivier
2023-03-10 22:09 ` [PULL 11/28] linux-user: handle netlink flag NLA_F_NESTED Laurent Vivier
2023-03-10 22:09 ` [PULL 12/28] linux-user: Add translation for argument of msync() Laurent Vivier
2023-03-10 22:09 ` [PULL 13/28] linux-user: Emulate CLONE_PIDFD flag in clone() Laurent Vivier
2023-03-10 22:09 ` [PULL 14/28] linux-user/sparc: Tidy syscall trap Laurent Vivier
2023-03-10 22:09 ` [PULL 15/28] linux-user/sparc: Tidy syscall error return Laurent Vivier
2023-03-10 22:09 ` [PULL 16/28] linux-user/sparc: Use TT_TRAP for flush windows Laurent Vivier
2023-03-10 22:09 ` [PULL 17/28] linux-user/sparc: Tidy window spill/fill traps Laurent Vivier
2023-03-10 22:09 ` [PULL 18/28] linux-user/sparc: Fix sparc64_{get, set}_context traps Laurent Vivier
2023-03-10 22:09 ` [PULL 19/28] linux-user/sparc: Handle software breakpoint trap Laurent Vivier
2023-03-10 22:09 ` [PULL 20/28] linux-user/sparc: Handle division by zero traps Laurent Vivier
2023-03-10 22:09 ` [PULL 21/28] linux-user/sparc: Handle getcc, setcc, getpsr traps Laurent Vivier
2023-03-10 22:09 ` [PULL 22/28] linux-user/sparc: Handle priviledged opcode trap Laurent Vivier
2023-03-10 22:09 ` [PULL 23/28] linux-user/sparc: Handle privilidged action trap Laurent Vivier
2023-03-10 22:09 ` [PULL 24/28] linux-user/sparc: Handle coprocessor disabled trap Laurent Vivier
2023-03-10 22:09 ` [PULL 25/28] linux-user/sparc: Handle unimplemented flush trap Laurent Vivier
2023-03-10 22:09 ` [PULL 26/28] linux-user/sparc: Handle floating-point exceptions Laurent Vivier
2023-03-10 22:09 ` [PULL 27/28] linux-user/sparc: Handle tag overflow traps Laurent Vivier
2023-03-10 22:09 ` [PULL 28/28] linux-user: fix bug about incorrect base addresss of gdt on i386 and x86_64 Laurent Vivier
2023-03-12 17:42 ` [PULL 00/28] Linux user for 8.0 patches Peter Maydell
-- strict thread matches above, loose matches on Subject: below --
2023-03-08 13:28 Laurent Vivier
2023-03-08 13:28 ` [PULL 04/28] linux-user: Fix unaligned memory access in prlimit64 syscall Laurent Vivier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230310220927.326606-5-laurent@vivier.eu \
--to=laurent@vivier.eu \
--cc=iii@linux.ibm.com \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).