On Wed, Dec 2, 2026 at 11:06 AM Christophe Leroy (CS GROUP)
<[email protected]> wrote:
> Le 02/12/2026 à 16:24, Dave Hansen a écrit :
> > On 12/2/26 07:04, Christophe Leroy (CS GROUP) wrote:
> >> Also about the masked user access path, the principle of that path is to
> >> be branch-less, the whole purpose was the remove the test/branch from
> >> access_ok(). With your new check it is not anymore branch-less
> >
> > Branches themselves are OK. The problem branches are around access
> > checks because they potentially allow transient execution paths to skip
> > the checking.
> >
> > In this case, the new check forces a return before any accesses happen
> > or any bounds checks are done. If the new check was incorrectly
> > speculated, we'd just have transient execution doing what the
> > *architectural* path is allowed to do today.
> >
> > I _think_ that's OK, at least from a spectre v1 perspective. But it
> > could definitely use some more eyeballs on it.
>
> Thanks for the explanation.
Hi Christophe, Dave,
Thanks for taking a look! (I didn't know that the masked access
functions were intended to avoid spectre issues... interesting.)
I am happy to go back to how v1 was doing it, putting the checks in
the routines that actually do copying (and already have branches). v1
also added the check in __scoped_user_access_begin(); I won't add that
one back.
I could put the uaccess_ok() check behind a Kconfig (that perhaps
depends on CONFIG_DEBUG_VM?). What do you think?
> >
> > I do agree with you about the code size concerns.
> >
>
> Behind the code size, my worry is that for a simple get_user() with is
> more or less a simple memory read, we end up with 3 memory reads because
> we first need to read paca->__current, then paca->__current->mm
For what it's worth, I did some text size measurements. :) From the
(quite long) cover letter:
With defconfig + KVM, patches 10-12 grow vmlinux by +11,702 B (+0.027%)
on x86_64 and +65,428 B (+0.15%) on arm64. v1's last patch, which moved
he warning out of line, is dropped: it would save ~25 KB of __bug_table
on arm64 (but add ~4 KB of text, and ~3 KB overall on x86_64), at the
cost of warning only once system-wide, and of fuzzers like syzkaller
reporting every such bug as a warning in the same helper, instead of
in its caller.
I did some measurements of v1[1] as well.
inline WARN_ON_ONCE() out-of-line warning
x86_64 total +5,884 B (+0.014%) +9,714 B (+0.023%)
arm64 total +40,948 B (+0.10%) +24,609 B (+0.06%)
I was quite surprised that v2's text size increase wasn't *that* much
more than v1's. I'm probably going to go back to v1's approach given
the feedback I've received so far, so if v1's measurements are also
concerning, let me know.
> Other point, is current->mm == NULL the only problematic situation ? No
> risk to have ->mm not NULL yet not the right one ? Isn't it this that
> had to be fixed by commit 2520694e6048 ("KVM: Reject user accesses to
> guest memory if current->mm != kvm->mm") ?
That's right, current->mm == NULL not the only problematic situation;
current->mm can just be wrong. I don't think there's a good way to
check that generically. In the KVM case, the current->mm == NULL check
would have found the bug, even though it was *also* possible that
current->mm could be non-NULL and wrong.
[1] https://lore.kernel.org/all/[email protected]/