linux/Documentation
Peter Collingbourne 60dbbd76f1 userfaultfd: do not untag user pointers
commit e71e2ace5721a8b921dca18b045069e7bb411277 upstream.

Patch series "userfaultfd: do not untag user pointers", v5.

If a user program uses userfaultfd on ranges of heap memory, it may end
up passing a tagged pointer to the kernel in the range.start field of
the UFFDIO_REGISTER ioctl.  This can happen when using an MTE-capable
allocator, or on Android if using the Tagged Pointers feature for MTE
readiness [1].

When a fault subsequently occurs, the tag is stripped from the fault
address returned to the application in the fault.address field of struct
uffd_msg.  However, from the application's perspective, the tagged
address *is* the memory address, so if the application is unaware of
memory tags, it may get confused by receiving an address that is, from
its point of view, outside of the bounds of the allocation.  We observed
this behavior in the kselftest for userfaultfd [2] but other
applications could have the same problem.

Address this by not untagging pointers passed to the userfaultfd ioctls.
Instead, let the system call fail.  Also change the kselftest to use
mmap so that it doesn't encounter this problem.

[1] https://source.android.com/devices/tech/debug/tagged-pointers
[2] tools/testing/selftests/vm/userfaultfd.c

This patch (of 2):

Do not untag pointers passed to the userfaultfd ioctls.  Instead, let
the system call fail.  This will provide an early indication of problems
with tag-unaware userspace code instead of letting the code get confused
later, and is consistent with how we decided to handle brk/mmap/mremap
in commit dcde237319 ("mm: Avoid creating virtual address aliases in
brk()/mmap()/mremap()"), as well as being consistent with the existing
tagged address ABI documentation relating to how ioctl arguments are
handled.

The code change is a revert of commit 7d0325749a ("userfaultfd: untag
user pointers") plus some fixups to some additional calls to
validate_range that have appeared since then.

[1] https://source.android.com/devices/tech/debug/tagged-pointers
[2] tools/testing/selftests/vm/userfaultfd.c

Link: https://lkml.kernel.org/r/20210714195437.118982-1-pcc@google.com
Link: https://lkml.kernel.org/r/20210714195437.118982-2-pcc@google.com
Link: https://linux-review.googlesource.com/id/I761aa9f0344454c482b83fcfcce547db0a25501b
Fixes: 63f0c60379 ("arm64: Introduce prctl() options to control the tagged user addresses ABI")
Signed-off-by: Peter Collingbourne <pcc@google.com>
Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Alistair Delva <adelva@google.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: Dave Martin <Dave.Martin@arm.com>
Cc: Evgenii Stepanov <eugenis@google.com>
Cc: Lokesh Gidra <lokeshgidra@google.com>
Cc: Mitch Phillips <mitchp@google.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Cc: Will Deacon <will@kernel.org>
Cc: William McVicker <willmcvicker@google.com>
Cc: <stable@vger.kernel.org>	[5.4]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-07-28 13:31:01 +02:00
..
ABI evm: Refuse EVM_ALLOW_METADATA_WRITES only if an HMAC key is loaded 2021-07-14 16:53:08 +02:00
EDID
PCI
RCU
accounting
admin-guide clocksource: Retry clock read if long delays detected 2021-07-14 16:53:18 +02:00
arm ARM: 9012/1: move device tree mapping out of linear region 2021-05-19 10:08:32 +02:00
arm64 userfaultfd: do not untag user pointers 2021-07-28 13:31:01 +02:00
block
bpf
cdrom
core-api XArray: add xas_split 2021-06-10 13:37:14 +02:00
cpu-freq
crypto
dev-tools mm, page_owner: decouple freeing stack trace from debug_pagealloc 2019-10-14 15:04:00 -07:00
devicetree dt-bindings: net: ethernet-controller: fix typo in NVMEM 2021-04-14 08:24:18 +02:00
doc-guide
driver-api ata: make qc_prep return ata_completion_errors 2020-10-01 13:18:26 +02:00
fault-injection
fb fbdev: fix numbering of fbcon options 2020-02-24 08:36:42 +01:00
features
filesystems sysfs: Add sysfs_emit and sysfs_emit_at to format sysfs output 2021-03-07 12:20:48 +01:00
firmware-guide
firmware_class
fpga
gpu
hid
hwmon hwmon: (max31790) Fix pwmX_enable attributes 2021-07-14 16:53:14 +02:00
i2c
ia64
ide
iio
infiniband
input
ioctl
isdn
kbuild kbuild: support LLVM=1 to switch the default tools to Clang/LLVM 2020-08-26 10:40:47 +02:00
kernel-hacking
leds
livepatch
locking
m68k
maintainer
media media: videodev2.h: RGB BT2020 and HSV are always full range 2020-11-05 11:43:15 +01:00
mic
mips
misc-devices
netlabel
networking can: j1939: swap addr and pgn in the send example 2020-11-18 19:20:19 +01:00
nios2
openrisc
parisc
pcmcia
power
powerpc
process Documentation/process: Add fallthrough pseudo-keyword 2019-10-11 09:26:05 -07:00
riscv
s390
scheduler
scsi scsi: smartpqi: Update attribute name to `driver_version` 2020-01-17 19:48:27 +01:00
security Merge branch 'next-integrity' of git://git.kernel.org/pub/scm/linux/kernel/git/zohar/linux-integrity 2019-09-27 19:37:27 -07:00
sh
sound ALSA: hda/realtek - Remove now-unnecessary XPS 13 headphone noise fixups 2020-04-17 10:50:08 +02:00
sparc
sphinx tweewide: Fix most Shebang lines 2021-05-22 11:38:30 +02:00
sphinx-static
spi
target tweewide: Fix most Shebang lines 2021-05-22 11:38:30 +02:00
timers
trace tracing/histogram: Rename "cpu" to "common_cpu" 2021-07-28 13:31:00 +02:00
translations
usb USB: rio500: Remove Rio 500 kernel driver 2019-10-04 10:53:36 +02:00
userspace-api Documentation: seccomp: Fix user notification documentation 2021-06-03 08:59:03 +02:00
virt KVM: arm64: Reject VM creation when the default IPA size is unsupported 2021-03-17 17:03:57 +01:00
virtual
vm mm/slub: clarify verification reporting 2021-06-23 14:41:30 +02:00
w1
watchdog linux-watchdog 5.4-rc1 tag 2019-09-27 11:17:38 -07:00
x86 x86/CPU/AMD: Save AMD NodeId as cpu_die_id 2020-12-30 11:51:47 +01:00
xtensa xtensa: fix TLBTEMP area placement 2020-11-24 13:29:22 +01:00
.gitignore
COPYING-logo
Changes
CodingStyle
DMA-API-HOWTO.txt
DMA-API.txt
DMA-ISA-LPC.txt
DMA-attributes.txt
IPMI.txt
IRQ-affinity.txt
IRQ-domain.txt
IRQ.txt
Kconfig
Makefile
SubmittingPatches
asm-annotations.rst linkage: Introduce new macros for assembler symbols 2020-11-10 12:37:24 +01:00
atomic_bitops.txt
atomic_t.txt
bus-virt-phys-mapping.txt
conf.py
crc32.txt
debugging-modules.txt
debugging-via-ohci1394.txt
digsig.txt
docutils.conf
dontdiff
futex-requeue-pi.txt
hwspinlock.txt
index.rst linkage: Introduce new macros for assembler symbols 2020-11-10 12:37:24 +01:00
io-mapping.txt
io_ordering.txt
irqflags-tracing.txt
kobject.txt
kprobes.txt
kref.txt
logo.gif
lzo.txt lib/lzo: fix ambiguous encoding bug in lzo-rle 2020-06-17 16:40:28 +02:00
mailbox.txt
memory-barriers.txt
nommu-mmap.txt
padata.txt
percpu-rw-semaphore.txt
pi-futex.txt
preempt-locking.txt
rbtree.txt
remoteproc.txt
robust-futex-ABI.txt
robust-futexes.txt
rpmsg.txt
speculation.txt
static-keys.txt
tee.txt
this_cpu_ops.txt
unaligned-memory-access.txt
xz.txt