From: Sean Christopherson <seanjc@google.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Mateusz Guzik <mjguzik@gmail.com>,
"the arch/x86 maintainers" <x86@kernel.org>,
brauner@kernel.org, viro@zeniv.linux.org.uk, jack@suse.cz,
linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
tglx@linutronix.de, pfalcato@suse.de
Subject: Re: [PATCH 1/3] x86: fix access_ok() and valid_user_address() using wrong USER_PTR_MAX in modules
Date: Tue, 4 Nov 2025 09:09:31 -0800 [thread overview]
Message-ID: <aQozS2ZHX4x1APvb@google.com> (raw)
In-Reply-To: <CAHk-=wimh_3jM9Xe8Zx0rpuf8CPDu6DkRCGb44azk0Sz5yqSnw@mail.gmail.com>
On Tue, Nov 04, 2025, Linus Torvalds wrote:
> [ Adding x86 maintainers - I had added Thomas earlier, but I guess at
> least Borislav might actually care and have input too ]
>
> So I think the patch I will commit would look like the attached: it's
> similar to your suggestion, but without the renaming of USER_PTR_MAX,
> and with just a
>
> #ifdef MODULE
> #define runtime_const_ptr(sym) (sym)
> #else
> #include <asm/runtime-const.h>
> #endif
>
> in the x86 asm/uaccess_64.h header file and an added '#error' for the
> MODULE case in the actual x86 runtime-const.h file.
>
> As it is, this bug really only affects modular code that uses
What exactly is the bug? Is the problem that module usage of runtime_const_ptr()
doesn't get patched on module load, and so module code ends up using the
0x0123456789abcdef placeholder?
> access_ok() and __{get,put}_user(), which is a really broken pattern
> to begin with these days, and is happily fairly rare.
Just to make sure I understand the impact, doesn't this also affect all flavors
of "nocheck" uaccesses? E.g. access_ok() + __copy_{from,to}_user()?
> That is an old optimization that is no longer an optimization at all
> (since a plain "get_user()" is actually *faster* than the access_ok()
> and __get_user() these days), and I wish we didn't have any such code
> any more, but there are a handful of things that have never been
> converted to the modern world order.
Looking at the assembly, I assume get_user() is faster than __get_user() due to
the LFENCE in ASM_BARRIER_NOSPEC?
> So it is what it is, and we have to deal with it.
Assuming __{get,put}_user() are slower on x86 in all scenarios, would it make
sense to kill them off entirely for x86? E.g. could we reroute them to the
"checked" variants?
For KVM x86, I'm more than happy to switch all two __{get,put}_user() calls to
the checked variants if they're faster.
> Also, even that kind of rare and broken code actually *works*,
> although the whole "non-canonical reads can speculatively leak
> possibly kernel data" does end up being an issue (largely theoretical
> because it's now limited to just a couple of odd-ball code sequences)
>
> And yes, it works just because I picked a runtime-const value that is
> non-canonical. I'd say it's "by luck", but I did pick that value
> partly *because* it's non-canonical, so it's not _entirely_ just luck.
> But mostly.
>
> That was all a long explanation for why I am planning on committing
> this as a real fix, even if the actual impact of it is largely
> theoretical.
>
> Borislav - comments? Generating this patch took longer than it should
> have, but I had travel and jetlag and a flight that I expected to have
> wifi but didn't... And properly it should probably be committed by
> x86 maintainers rather than me, but I did mess this code up in the
> first place.
>
> The patch *looks* very straightforward, but since I'm on the road I am
> doing this on my laptop and haven't actually tested it yet (well, I've
> built this, and booted it, but nothing past that).
FWIW, AFAICT it doesn't cause any regressions for KVM's usage of access_ok().
next prev parent reply other threads:[~2025-11-04 17:09 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-30 10:52 [PATCH v4] fs: hide names_cachep behind runtime access machinery Mateusz Guzik
2025-10-30 13:13 ` kernel test robot
2025-10-30 13:19 ` Mateusz Guzik
2025-10-30 16:15 ` Linus Torvalds
2025-10-30 16:35 ` Mateusz Guzik
2025-10-30 18:07 ` Linus Torvalds
2025-10-30 18:25 ` Linus Torvalds
2025-10-30 21:39 ` Mateusz Guzik
2025-10-30 22:06 ` Mateusz Guzik
2025-10-31 12:08 ` Christian Brauner
2025-10-31 15:13 ` Mateusz Guzik
2025-10-31 16:04 ` Linus Torvalds
2025-10-31 16:25 ` Mateusz Guzik
2025-10-31 16:31 ` Linus Torvalds
2025-10-31 17:42 ` [WIP RFC PATCH 0/3] runtime-const header split and whatnot Mateusz Guzik
2025-10-31 17:42 ` [PATCH 1/3] x86: fix access_ok() and valid_user_address() using wrong USER_PTR_MAX in modules Mateusz Guzik
2025-10-31 21:46 ` Linus Torvalds
2025-10-31 22:01 ` Mateusz Guzik
2025-11-01 11:26 ` David Laight
2025-11-04 6:25 ` Linus Torvalds
2025-11-04 8:56 ` Mateusz Guzik
2025-11-04 9:37 ` Linus Torvalds
2025-11-04 10:25 ` Borislav Petkov
2025-11-04 16:13 ` Borislav Petkov
2025-11-05 1:50 ` Linus Torvalds
2025-11-05 11:37 ` Borislav Petkov
2025-11-05 20:50 ` Mateusz Guzik
2025-11-06 11:14 ` Borislav Petkov
2025-11-06 12:06 ` Mateusz Guzik
2025-11-06 13:10 ` Borislav Petkov
2025-11-06 13:19 ` Mateusz Guzik
2025-11-06 13:36 ` Borislav Petkov
2025-11-06 14:49 ` Mateusz Guzik
2025-11-06 19:26 ` David Laight
2025-11-06 19:49 ` Linus Torvalds
2025-11-04 17:09 ` Sean Christopherson [this message]
2025-11-04 19:07 ` Linus Torvalds
2025-11-04 19:34 ` Linus Torvalds
2025-11-04 21:53 ` Sean Christopherson
2025-11-04 20:17 ` Borislav Petkov
2025-11-04 22:06 ` Linus Torvalds
2025-11-05 11:49 ` Borislav Petkov
2025-10-31 17:42 ` [PATCH 2/3] runtime-const: split headers between accessors and fixup; disable for modules Mateusz Guzik
2025-10-31 17:42 ` [PATCH 3/3] fs: hide names_cachep behind runtime access machinery Mateusz Guzik
2025-10-31 23:30 ` kernel test robot
2025-10-31 23:30 ` kernel test robot
2025-10-31 23:41 ` kernel test robot
2025-11-01 17:49 ` kernel test robot
2025-10-31 13:30 ` [PATCH v4] " kernel test robot
2025-10-31 22:43 ` kernel test robot
2025-11-01 23:06 ` kernel test robot
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=aQozS2ZHX4x1APvb@google.com \
--to=seanjc@google.com \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjguzik@gmail.com \
--cc=pfalcato@suse.de \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
--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;
as well as URLs for NNTP newsgroup(s).