From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: "Ilya Leoshkevich" <iii@linux.ibm.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Laurent Vivier" <laurent@vivier.eu>
Cc: qemu-devel@nongnu.org,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Richard Henderson <richard.henderson@linaro.org>
Subject: Re: [PATCH v2 1/2] linux-user: Fix unaligned memory access in prlimit64 syscall
Date: Fri, 24 Feb 2023 00:20:02 +0100 [thread overview]
Message-ID: <d9c11ba1-a6b2-ad93-7485-4b0953895b90@linaro.org> (raw)
In-Reply-To: <20230223231137.186344-2-iii@linux.ibm.com>
On 24/2/23 00:11, Ilya Leoshkevich wrote:
> 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>
> ---
> 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 539d8c46772..37d3eb09b3b 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 a6c426d73cf..1f7a272799b 100644
> --- a/linux-user/syscall.c
> +++ b/linux-user/syscall.c
> @@ -12886,8 +12886,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);
Thanks,
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
next prev parent reply other threads:[~2023-02-23 23:20 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-23 23:11 [PATCH v2 0/2] linux-user: Fix unaligned memory access in prlimit64 syscall Ilya Leoshkevich
2023-02-23 23:11 ` [PATCH v2 1/2] " Ilya Leoshkevich
2023-02-23 23:14 ` Richard Henderson
2023-02-23 23:20 ` Philippe Mathieu-Daudé [this message]
2023-02-23 23:11 ` [PATCH v2 2/2] tests/tcg/linux-test: Add linux-fork-trap test Ilya Leoshkevich
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=d9c11ba1-a6b2-ad93-7485-4b0953895b90@linaro.org \
--to=philmd@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=borntraeger@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=laurent@vivier.eu \
--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).