From: Ilya Leoshkevich <iii@linux.ibm.com>
To: "Richard Henderson" <richard.henderson@linaro.org>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Laurent Vivier" <laurent@vivier.eu>
Cc: qemu-devel@nongnu.org, Christian Borntraeger <borntraeger@linux.ibm.com>
Subject: Re: [PATCH 1/2] linux-user: Fix unaligned memory access in prlimit64 syscall
Date: Thu, 23 Feb 2023 23:45:24 +0100 [thread overview]
Message-ID: <c372cbd88605a19f4d5840cf5d7719f7a8165adb.camel@linux.ibm.com> (raw)
In-Reply-To: <f4d837ce-1a2a-9e7d-4499-76820d6fdc36@linaro.org>
On Thu, 2023-02-23 at 12:31 -1000, Richard Henderson wrote:
> On 2/23/23 11:58, Ilya Leoshkevich wrote:
> > 32-bit guests may enforce only 4-byte alignment for
> > target_rlimit64,
> > whereas 64-bit hosts normally require the 8-byte one. Therefore
> > accessing this struct directly is UB.
> >
> > Fix by adding a local copy.
> >
> > 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/syscall.c | 12 +++++++-----
> > 1 file changed, 7 insertions(+), 5 deletions(-)
> >
> > diff --git a/linux-user/syscall.c b/linux-user/syscall.c
> > index a6c426d73cf..8ae7696d8f1 100644
> > --- a/linux-user/syscall.c
> > +++ b/linux-user/syscall.c
> > @@ -12876,7 +12876,7 @@ static abi_long do_syscall1(CPUArchState
> > *cpu_env, int num, abi_long arg1,
> > case TARGET_NR_prlimit64:
> > {
> > /* args: pid, resource number, ptr to new rlimit, ptr to
> > old rlimit */
> > - struct target_rlimit64 *target_rnew, *target_rold;
> > + struct target_rlimit64 *target_rnew, *target_rold, tmp;
>
> The bug is that target_rlimit64 uses uint64_t (64-bit host
> alignment), when it should be
> using abi_ullong (64-bit target alignment). There are quite a number
> of these sorts of
> bugs in linux-user.
>
>
> r~
Thanks, this helps.
I thought that unaligned accesses were illegal no matter what, e.g., on
sparc64, but turns out the compiler is actually smart enough to handle
them:
#include <stdint.h>
typedef uint64_t abi_ullong __attribute__((aligned(4)));
abi_ullong load(abi_ullong *x) { return *x; }
produces
load:
save %sp, -176, %sp
lduw [%i0], %g1
lduw [%i0+4], %i0
sllx %g1, 32, %g1
return %i7+8
or %o0, %g1, %o0
instead of just
load:
save %sp, -176, %sp
return %i7+8
ldx [%o0], %o0
I'll send a v2.
Best regards,
Ilya
next prev parent reply other threads:[~2023-02-23 22:46 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-23 21:58 [PATCH 0/2] linux-user: Fix unaligned memory access in prlimit64 syscall Ilya Leoshkevich
2023-02-23 21:58 ` [PATCH 1/2] " Ilya Leoshkevich
2023-02-23 22:17 ` Philippe Mathieu-Daudé
2023-02-23 22:24 ` Ilya Leoshkevich
2023-02-23 22:31 ` Richard Henderson
2023-02-23 22:45 ` Ilya Leoshkevich [this message]
2023-02-23 21:58 ` [PATCH 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=c372cbd88605a19f4d5840cf5d7719f7a8165adb.camel@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=alex.bennee@linaro.org \
--cc=borntraeger@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).