From: Christophe Leroy <christophe.leroy@csgroup.eu>
To: Linus Torvalds <torvalds@linux-foundation.org>,
Andreas Schwab <schwab@linux-m68k.org>
Cc: Josh Poimboeuf <jpoimboe@kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
x86@kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH] futex: improve user space accesses
Date: Mon, 9 Dec 2024 09:00:07 +0100 [thread overview]
Message-ID: <ca5559b9-16fe-4808-a28b-b87129b0e6b8@csgroup.eu> (raw)
In-Reply-To: <CAHk-=wjnvFU3sMjjKyqtgvPe6EMu3M4f1qyZncJR5=QDQsV=ng@mail.gmail.com>
Le 09/12/2024 à 01:32, Linus Torvalds a écrit :
> On Sun, 8 Dec 2024 at 14:54, Andreas Schwab <schwab@linux-m68k.org> wrote:
>>
>> This breaks userspace on ppc32. As soon as /init in the initrd is
>> started the kernel hangs (without any messages).
>
> Funky, funky. Most of the diff is the code movement (and some small
> x86-specific stuff), so for ppc, the only part that should be relevant
> is the futex_get_value_locked().
>
> And since ppc doesn't do the masked user access thing, so it
> *literally* boils down to just that
>
> if (!user_read_access_begin(from, sizeof(*from)))
> return -EFAULT;
> unsafe_get_user(val, from, Efault);
> user_access_end();
>
> path.
>
> Ahh... And now that I write that out, the bug is obvious: it should be using
>
> user_read_access_end();
>
> to match up with the user_read_access_begin().
Yes indeed, especially on book3s/32, which is only able to write-protect
user accesses. On that platform user_read_access_...() are no-ops.
user_access_end() and user_write_access_end() are similar, and rely on a
thread var stored by user_access_begin(). When calling that
user_access_end() without prior call to user_access_begin(), that var
has value ~0 instead of the address of the user segment being accessed,
and ~0 is a kernel address so user_access_end() applies some user
segment flags to a kernel segment which most likely leads to a complete
mess allthough I'm not able to trigger the hang with QEMU.
>
> And yeah, ppc is the only platform that has that
> "read-vs-write-vs-both" thing, so this bug is not visible anywhere
> else.
>
> IOW, does this one-liner fix it for you?
>
> --- a/kernel/futex/futex.h
> +++ b/kernel/futex/futex.h
> @@ -265,7 +265,7 @@
> else if (!user_read_access_begin(from, sizeof(*from)))
> return -EFAULT;
> unsafe_get_user(val, from, Efault);
> - user_access_end();
> + user_read_access_end();
> *dest = val;
> return 0;
> Efault:
>
> I bet it does, but I'll wait for confirmation before actually
> committing that fix.
>
You'll need the same change in the Efault leg.
Christophe
next prev parent reply other threads:[~2024-12-09 8:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-22 19:33 Linus Torvalds
2024-11-23 2:47 ` Josh Poimboeuf
2024-12-08 22:54 ` Andreas Schwab
2024-12-09 0:32 ` Linus Torvalds
2024-12-09 8:00 ` Christophe Leroy [this message]
2024-12-09 18:32 ` Andreas Schwab
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=ca5559b9-16fe-4808-a28b-b87129b0e6b8@csgroup.eu \
--to=christophe.leroy@csgroup.eu \
--cc=jpoimboe@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=schwab@linux-m68k.org \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.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
all inboxes | Powered by JetHome®