linux/arch
Linus Torvalds 6014bc2756 x86-64: make access_ok() independent of LAM
The linear address masking (LAM) code made access_ok() more complicated,
in that it now needs to untag the address in order to verify the access
range.  See commit 74c228d20a ("x86/uaccess: Provide untagged_addr()
and remove tags before address check").

We were able to avoid that overhead in the get_user/put_user code paths
by simply using the sign bit for the address check, and depending on the
GP fault if the address was non-canonical, which made it all independent
of LAM.

And we can do the same thing for access_ok(): simply check that the user
pointer range has the high bit clear.  No need to bother with any
address bit masking.

In fact, we can go a bit further, and just check the starting address
for known small accesses ranges: any accesses that overflow will still
be in the non-canonical area and will still GP fault.

To still make syzkaller catch any potentially unchecked user addresses,
we'll continue to warn about GP faults that are caused by accesses in
the non-canonical range.  But we'll limit that to purely "high bit set
and past the one-page 'slop' area".

We could probably just do that "check only starting address" for any
arbitrary range size: realistically all kernel accesses to user space
will be done starting at the low address.  But let's leave that kind of
optimization for later.  As it is, this already allows us to generate
simpler code and not worry about any tag bits in the address.

The one thing to look out for is the GUP address check: instead of
actually copying data in the virtual address range (and thus bad
addresses being caught by the GP fault), GUP will look up the page
tables manually.  As a result, the page table limits need to be checked,
and that was previously implicitly done by the access_ok().

With the relaxed access_ok() check, we need to just do an explicit check
for TASK_SIZE_MAX in the GUP code instead.  The GUP code already needs
to do the tag bit unmasking anyway, so there this is all very
straightforward, and there are no LAM issues.

Cc: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2023-05-03 10:37:22 -07:00
..
alpha SMP cross-CPU function-call updates for v6.4: 2023-04-28 15:03:43 -07:00
arc SMP cross-CPU function-call updates for v6.4: 2023-04-28 15:03:43 -07:00
arm Input updates for 6.4 merge window: 2023-05-01 17:18:56 -07:00
arm64 s390: 2023-05-01 12:06:20 -07:00
csky SMP cross-CPU function-call updates for v6.4: 2023-04-28 15:03:43 -07:00
hexagon treewide: Trace IPIs sent via smp_send_reschedule() 2023-03-24 11:01:28 +01:00
ia64 SMP cross-CPU function-call updates for v6.4: 2023-04-28 15:03:43 -07:00
loongarch SMP cross-CPU function-call updates for v6.4: 2023-04-28 15:03:43 -07:00
m68k m68knommu: updates and fixes for v6.4 2023-04-28 16:37:54 -07:00
microblaze Kconfig: introduce HAS_IOPORT option and select it as necessary 2023-04-05 22:15:19 +02:00
mips s390: 2023-05-01 12:06:20 -07:00
nios2 - Nick Piggin's "shoot lazy tlbs" series, to improve the peformance of 2023-04-27 19:42:02 -07:00
openrisc OpenRISC update for 6.4 2023-05-01 11:52:32 -07:00
parisc SMP cross-CPU function-call updates for v6.4: 2023-04-28 15:03:43 -07:00
powerpc s390: 2023-05-01 12:06:20 -07:00
riscv s390: 2023-05-01 12:06:20 -07:00
s390 s390: 2023-05-01 12:06:20 -07:00
sh SMP cross-CPU function-call updates for v6.4: 2023-04-28 15:03:43 -07:00
sparc Kbuild updates for v6.4 2023-04-30 11:32:53 -07:00
um ELF: fix all "Elf" typos 2023-04-08 13:45:37 -07:00
x86 x86-64: make access_ok() independent of LAM 2023-05-03 10:37:22 -07:00
xtensa SMP cross-CPU function-call updates for v6.4: 2023-04-28 15:03:43 -07:00
.gitignore
Kconfig lazy tlb: shoot lazies, non-refcounting lazy tlb mm reference handling scheme 2023-03-28 16:20:08 -07:00