Hi James,

Le 02/12/2026 à 03:39, James Houghton a écrit :
Hi everyone,

This series comes out of a set of bugs that were found in KVM where the
kernel can sometimes write to a random process's user memory[1]. Sean's
KVM fixes for those have since been merged, e.g. commit 2520694e6048
("KVM: Reject user accesses to guest memory if current->mm != kvm->mm").
They are still required with this series, as they also handle the case
where the VM is destroyed from another process, which this series can't
detect.

We hit one of the KVM bugs in production, and it was challenging to
debug. This series makes such bugs, where the kernel is doing uaccess
without an mm, much more obvious.

The beginning of this series includes fixes for similar bugs found
through static analysis with Claude Opus 5.5.

The main change in v2 is where the new check lives. Following Arnd's
suggestion[2], it is now in access_ok() itself, plus the masked user
access paths and the unchecked __copy_{from,to}_user{,_inatomic}()
accessors, instead of in each generic copy helper. This covers more
(e.g. get_user(), put_user() and clear_user() on most architectures),
and makes most new user access code get the check automatically. See
"Changes in v2" below for the full list.

I'm a bit concerned with this change. It impacts hot pathes. All has been done to get access_ok() as light as possible over the years, and nowadays we are on the way of removing __get_user() with the argument that access_ok() is so light that there is almost no difference between get_user() and __get_user(). It looks like your series goes in the opposite direction.

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

For a very simple function like:

long mytest(long *ptr);
long mytest(long *ptr)
{
        long val;

        if (get_user(val, ptr))
                return 0;

        return val;
}

Without your patch it is:

00000000000030b0 <mytest>:
    30b0:       39 20 ff ff     li      r9,-1
    30b4:       79 29 04 80     clrldi  r9,r9,18
    30b8:       7c 23 48 40     cmpld   r3,r9
    30bc:       41 c1 00 14     bgt-    30d0 <mytest+0x20>
    30c0:       e8 63 00 00     ld      r3,0(r3)
    30c4:       4e 80 00 20     blr

    30d0:       38 60 00 00     li      r3,0
    30d4:       4e 80 00 20     blr

With your patch it adds two memory reads to read paca->__current->mm:

00000000000030e0 <mytest>:
    30e0:       e9 2d 06 58     ld      r9,1624(r13)
    30e4:       e9 29 04 b0     ld      r9,1200(r9)
    30e8:       2c 29 00 00     cmpdi   r9,0
    30ec:       41 c2 00 24     beq-    3110 <mytest+0x30>

    30f0:       39 20 ff ff     li      r9,-1
    30f4:       79 29 04 80     clrldi  r9,r9,18
    30f8:       7c 23 48 40     cmpld   r3,r9
    30fc:       41 c1 00 18     bgt-    3114 <mytest+0x34>
    3100:       e8 63 00 00     ld      r3,0(r3)
    3104:       4e 80 00 20     blr

    3110:       0f e0 00 00     twui    r0,0

    3114:       38 60 00 00     li      r3,0
    3118:       4e 80 00 20     blr



Reply via email to