Skip to content

userfaultfd: do not untag user pointers

Peter Collingbourne linux-arm-kernel linux-mm stable 3 versions – Applied

Status from this message: [merged] selftest-use-mmap-instead-of-posix_memalign-to-allocate-memory.patch removed from -mm tree

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest2 patches 0 repliesApplied 2/2
  2. v42 patches 3 repliesSuperseded
  3. v32 patches 1 replySuperseded

Patches in v5 All 2 applied

#Subject and filesSizeRepliesApplied
1/2userfaultfd: do not untag user pointersDocumentation/arm64/tagged-address-abi.rst fs/userfaultfd.c+30 -220 repliesApplied
2/2selftest: use mmap instead of posix_memalign to allocate memorytools/testing/selftests/vm/userfaultfd.c+4 -20 repliesApplied

Reviews trailers per patch

All 2 patches have a Reviewed-by or Acked-by.

PatchAndrey KonovalovCatalin Marinas
1/2R-b R-b
2/2R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v5 thread

Cover letter [PATCH v5 0/2] userfaultfd: do not untag user pointers

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

Peter Collingbourne (2):
userfaultfd: do not untag user pointers
selftest: use mmap instead of posix_memalign to allocate memory

 Documentation/arm64/tagged-address-abi.rst | 26 +++++++++++++++-------
 fs/userfaultfd.c                           | 26 ++++++++++------------
 tools/testing/selftests/vm/userfaultfd.c   |  6 +++--
 3 files changed, 34 insertions(+), 24 deletions(-)
Signature · 1 line
2.32.0.93.g670b81a890-goog