arm64: untag user pointers passed to the kernel
Subsystems (16)
v10 cover arm64: untag user pointers passed to the kernel
This patchset is meant to be merged together with "arm64 relaxed ABI" [1].
arm64 has a feature called Top Byte Ignore, which allows to embed pointer tags into the top byte of each pointer. Userspace programs (such as HWASan, a memory debugging tool [2]) might use this feature and pass tagged user pointers to the kernel through syscalls or other interfaces.
Right now the kernel is already able to handle user faults with tagged pointers, due to these patches:
1. 81cddd65 ("arm64: traps: fix userspace cache maintenance emulation on a tagged pointer")
2. 7dcd9dd8 ("arm64: hw_breakpoint: fix watchpoint matching for tagged pointers")
3. 276e9327 ("arm64: entry: improve data abort handling of tagged pointers")
This patchset extends tagged pointer support to syscall arguments.
For non-memory syscalls this is done by untaging user pointers when the kernel performs pointer checking to find out whether the pointer comes from userspace (most notably in access_ok). The untagging is done only when the pointer is being checked, the tag is preserved as the pointer makes its way through the kernel.
Since memory syscalls (mmap, mprotect, etc.) don't do memory accesses but rather deal with memory ranges, untagged pointers are better suited to describe memory ranges internally. Thus for memory syscalls we untag pointers completely when they enter the kernel.
One of the alternative approaches to untagging that was considered is to completely strip the pointer tag as the pointer enters the kernel with some kind of a syscall wrapper, but that won't work with the countless number of different ioctl calls. With this approach we would need a custom wrapper for each ioctl variation, which doesn't seem practical.
The following testing approaches has been taken to find potential issues with user pointer untagging:
1. Static testing (with sparse [3] and separately with a custom static analyzer based on Clang) to track casts of __user pointers to integer types to find places where untagging needs to be done.
2. Static testing with grep to find parts of the kernel that call find_vma() (and other similar functions) or directly compare against vm_start/vm_end fields of vma.
3. Static testing with grep to find parts of the kernel that compare user pointers with TASK_SIZE or other similar consts and macros.
4. Dynamic testing: adding BUG_ON(has_tag(addr)) to find_vma() and running a modified syzkaller version that passes tagged pointers to the kernel.
Based on the results of the testing the requried patches have been added to the patchset.
This patchset has been merged into the Pixel 2 kernel tree and is now being used to enable testing of Pixel 2 phones with HWASan.
This patchset is a prerequisite for ARM's memory tagging hardware feature support [4].
Thanks!
[1] https://lkml.org/lkml/2018/12/10/402
[2] http://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html
[3] https://github.com/lucvoo/sparse-dev/commit/5f960cb10f56ec2017c128ef9d16060e0145f292
Changes in v10:
- Added "mm, arm64: untag user pointers passed to memory syscalls" back.
- New patch "fs, arm64: untag user pointers in fs/userfaultfd.c".
- New patch "net, arm64: untag user pointers in tcp_zerocopy_receive".
- New patch "kernel, arm64: untag user pointers in prctl_set_mm*".
- New patch "tracing, arm64: untag user pointers in seq_print_user_ip".
Changes in v9:
- Rebased onto 4.20-rc6.
- Used u64 instead of __u64 in type casts in the untagged_addr macro for arm64.
- Added braces around (addr) in the untagged_addr macro for other arches.
Changes in v8:
- Rebased onto 65102238 (4.20-rc1).
- Added a note to the cover letter on why syscall wrappers/shims that untag user pointers won't work.
- Added a note to the cover letter that this patchset has been merged into the Pixel 2 kernel tree.
- Documentation fixes, in particular added a list of syscalls that don't support tagged user pointers.
Changes in v7:
- Rebased onto 17b57b18 (4.19-rc6).
- Dropped the "arm64: untag user address in __do_user_fault" patch, since the existing patches already handle user faults properly.
- Dropped the "usb, arm64: untag user addresses in devio" patch, since the passed pointer must come from a vma and therefore be untagged.
- Dropped the "arm64: annotate user pointers casts detected by sparse" patch (see the discussion to the replies of the v6 of this patchset).
- Added more context to the cover letter.
- Updated Documentation/arm64/tagged-pointers.txt.
Changes in v6:
- Added annotations for user pointer casts found by sparse.
- Rebased onto 050cdc6c (4.19-rc1+).
Changes in v5:
- Added 3 new patches that add untagging to places found with static analysis.
- Rebased onto 44c929e1 (4.18-rc8).
Changes in v4:
- Added a selftest for checking that passing tagged pointers to the kernel succeeds.
- Rebased onto 81e97f013 (4.18-rc1+).
Changes in v3:
- Rebased onto e5c51f30 (4.17-rc6+).
- Added linux-arch@ to the list of recipients.
Changes in v2:
- Rebased onto 2d618bdf (4.17-rc3+).
- Removed excessive untagging in gup.c.
- Removed untagging pointers returned from __uaccess_mask_ptr.
Changes in v1:
- Rebased onto 4.17-rc1.
Changes in RFC v2:
- Added "#ifndef untagged_addr..." fallback in linux/uaccess.h instead of defining it for each arch individually.
- Updated Documentation/arm64/tagged-pointers.txt.
- Dropped "mm, arm64: untag user addresses in memory syscalls".
- Rebased onto 3eb2ce82 (4.16-rc7).
Andrey Konovalov (12):
uaccess: add untagged_addr definition for other arches
arm64: untag user pointers in access_ok and __uaccess_mask_ptr lib, arm64: untag user pointers in strn*_user
mm, arm64: untag user pointers passed to memory syscalls mm, arm64: untag user pointers in mm/gup.c
fs, arm64: untag user pointers in copy_mount_options
fs, arm64: untag user pointers in fs/userfaultfd.c
net, arm64: untag user pointers in tcp_zerocopy_receive kernel, arm64: untag user pointers in prctl_set_mm* tracing, arm64: untag user pointers in seq_print_user_ip
arm64: update Documentation/arm64/tagged-pointers.txt selftests, arm64: add a selftest for passing tagged pointers to kernel
Documentation/arm64/tagged-pointers.txt | 25 +++++++++++-------- arch/arm64/include/asm/uaccess.h | 10 +++++--- fs/namespace.c | 2 +- fs/userfaultfd.c | 5 ++++ include/linux/memory.h | 4 +++ ipc/shm.c | 2 ++ kernel/sys.c | 14 +++++++++++ kernel/trace/trace_output.c | 2 +- lib/strncpy_from_user.c | 2 ++ lib/strnlen_user.c | 2 ++ mm/gup.c | 4 +++ mm/madvise.c | 2 ++ mm/mempolicy.c | 5 ++++ mm/migrate.c | 1 + mm/mincore.c | 2 ++ mm/mlock.c | 5 ++++ mm/mmap.c | 7 ++++++ mm/mprotect.c | 2 ++ mm/mremap.c | 2 ++ mm/msync.c | 2 ++ net/ipv4/tcp.c | 2 ++ tools/testing/selftests/arm64/.gitignore | 1 + tools/testing/selftests/arm64/Makefile | 11 ++++++++ .../testing/selftests/arm64/run_tags_test.sh | 12 +++++++++ tools/testing/selftests/arm64/tags_test.c | 19 ++++++++++++++ 25 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 tools/testing/selftests/arm64/.gitignore create mode 100644 tools/testing/selftests/arm64/Makefile create mode 100755 tools/testing/selftests/arm64/run_tags_test.sh create mode 100644 tools/testing/selftests/arm64/tags_test.c
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v10 1/12 uaccess: add untagged_addr definition for other arches
To allow arm64 syscalls to accept tagged pointers from userspace, we must untag them when they are passed to the kernel. Since untagging is done in generic parts of the kernel, the untagged_addr macro needs to be defined for all architectures.
Define it as a noop for architectures other than arm64.
--- include/linux/memory.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/memory.h +4 -0
@@ -21,6 +21,10 @@#include <linux/mutex.h> #include <linux/notifier.h> +#ifndef untagged_addr +#define untagged_addr (addr) (addr) +#endif +#define MIN_MEMORY_BLOCK_SIZE (1UL << SECTION_SIZE_BITS)struct memory_block {
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v10 2/12 arm64: untag user pointers in access_ok and __uaccess_mask_ptr
In reply to Andrey Konovalovcopy_from_user (and a few other similar functions) are used to copy data from user memory into the kernel memory or vice versa. Since a user can provided a tagged pointer to one of the syscalls that use copy_from_user, we need to correctly handle such pointers.
Do this by untagging user pointers in access_ok and in __uaccess_mask_ptr, before performing access validity checks.
Note, that this patch only temporarily untags the pointers to perform the checks, but then passes them as is into the kernel internals.
--- arch/arm64/include/asm/uaccess.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
arch/arm64/include/asm/uaccess.h +6 -4
@@ -95,7 +95,7 @@ static inline unsigned long __range_ok(const void __user *addr, unsigned long sireturn ret; } -#define access_ok (addr, size) __range_ok(addr, size) +#define access_ok (addr, size) __range_ok(untagged_addr(addr), size)#define user_addr_max get_fs#define _ASM_EXTABLE (from, to) \
@@ -227,7 +227,8 @@ static inline void uaccess_enable_not_uao(void)/* * Sanitise a uaccess pointer such that it becomes NULL if above the -* current addr_limit. +* current addr_limit. In case the pointer is tagged (has the top byte set), +* untag the pointer before checking. */ #define uaccess_mask_ptr (ptr) (__typeof__(ptr))__uaccess_mask_ptr(ptr)static inline void __user *__uaccess_mask_ptr (const void __user *ptr)
@@ -235,10 +236,11 @@ static inline void __user *__uaccess_mask_ptr(const void __user *ptr)void __user *safe_ptr; asmvolatile ( -" bics xzr, %1, %2\n" +" bics xzr, %3, %2\n" " csel %0, %1, xzr, eq\n" :"=&r" (safe_ptr) - :"r" (ptr),"r" (current_thread_info ()->addr_limit) + :"r" (ptr),"r" (current_thread_info ()->addr_limit), +"r" (untagged_addr (ptr)) :"cc" );csdb ();
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v10 3/12 lib, arm64: untag user pointers in strn*_user
In reply to Andrey Konovalovstrncpy_from_user and strnlen_user accept user addresses as arguments, and do not go through the same path as copy_from_user and others, so here we need to handle the case of tagged user addresses separately.
Untag user pointers passed to these functions.
--- lib/strncpy_from_user.c | 2 ++ lib/strnlen_user.c | 2 ++ 2 files changed, 4 insertions(+)
lib/strncpy_from_user.c +2 -0
@@ -106,6 +106,8 @@ long strncpy_from_user(char *dst, const char __user *src, long count)if (unlikely (count <=0 ))return 0 ; + src =untagged_addr (src); + max_addr =user_addr_max (); src_addr = (unsigned long )src;if (likely (src_addr < max_addr)) {
lib/strnlen_user.c +2 -0
@@ -108,6 +108,8 @@ long strnlen_user(const char __user *str, long count)if (unlikely (count <=0 ))return 0 ; + str =untagged_addr (str); + max_addr =user_addr_max (); src_addr = (unsigned long )str;if (likely (src_addr < max_addr)) {
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v10 4/12 mm, arm64: untag user pointers passed to memory syscalls
In reply to Andrey KonovalovThis commit allows tagged pointers to be passed to the following memory
syscalls: madvise, mbind, get_mempolicy, mincore, mlock, mlock2, brk, mmap_pgoff, old_mmap, munmap, remap_file_pages, mprotect, pkey_mprotect, mremap, msync and shmdt.
--- ipc/shm.c | 2 ++ mm/madvise.c | 2 ++ mm/mempolicy.c | 5 +++++ mm/migrate.c | 1 + mm/mincore.c | 2 ++ mm/mlock.c | 5 +++++ mm/mmap.c | 7 +++++++ mm/mprotect.c | 2 ++ mm/mremap.c | 2 ++ mm/msync.c | 2 ++ 10 files changed, 30 insertions(+)
ipc/shm.c +2 -0
@@ -1567,6 +1567,7 @@ SYSCALL_DEFINE3(shmat, int, shmid, char __user *, shmaddr, int, shmflg)unsigned long ret;long err; + shmaddr =untagged_addr (shmaddr); err =do_shmat (shmid, shmaddr, shmflg, &ret,SHMLBA );if (err)return err;
@@ -1706,6 +1707,7 @@ long ksys_shmdt(char __user *shmaddr) SYSCALL_DEFINE1(shmdt, char __user *, shmaddr) { + shmaddr =untagged_addr (shmaddr);return ksys_shmdt (shmaddr); }
mm/madvise.c +2 -0
@@ -809,6 +809,8 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)size_t len;struct blk_plug plug; + start =untagged_addr (start); +if (!madvise_behavior_valid (behavior))return error;
mm/mempolicy.c +5 -0
@@ -1334,6 +1334,7 @@ static long kernel_mbind(unsigned long start, unsigned long len,int err;unsigned short mode_flags; + start =untagged_addr (start); mode_flags = mode &MPOL_MODE_FLAGS ; mode &= ~MPOL_MODE_FLAGS ;if (mode >=MPOL_MAX )
@@ -1491,6 +1492,8 @@ static int kernel_get_mempolicy(int __user *policy,int uninitialized_var (pval );nodemask_t nodes; + addr =untagged_addr (addr); +if (nmask !=NULL && maxnode < nr_node_ids)return -EINVAL ;
@@ -1576,6 +1579,8 @@ COMPAT_SYSCALL_DEFINE6(mbind, compat_ulong_t, start, compat_ulong_t, len,unsigned long nr_bits, alloc_size;nodemask_t bm; + start =untagged_addr (start); + nr_bits = min_t(unsigned long, maxnode-1, MAX_NUMNODES); alloc_size =ALIGN (nr_bits,BITS_PER_LONG ) /8 ;
mm/migrate.c +1 -0
@@ -1601,6 +1601,7 @@ static int do_pages_move(struct mm_struct *mm, nodemask_t task_nodes,if (get_user (node, nodes + i)) goto out_flush; addr = (unsigned long )p; + addr =untagged_addr (addr); err = -ENODEV ;if (node <0 || node >=MAX_NUMNODES )
mm/mincore.c +2 -0
@@ -228,6 +228,8 @@ SYSCALL_DEFINE3(mincore, unsigned long, start, size_t, len,unsigned long pages;unsigned char *tmp; + start =untagged_addr (start); +/* Check the start address: needs to be page-aligned.. */ if (start & ~PAGE_MASK )return -EINVAL ;
mm/mlock.c +5 -0
@@ -715,6 +715,7 @@ static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t fla SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len) { + start =untagged_addr (start);return do_mlock (start, len,VM_LOCKED ); }
@@ -722,6 +723,8 @@ SYSCALL_DEFINE3(mlock2, unsigned long, start, size_t, len, int, flags) {vm_flags_t vm_flags =VM_LOCKED ; + start =untagged_addr (start); +if (flags & ~MLOCK_ONFAULT )return -EINVAL ;
@@ -735,6 +738,8 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len) {int ret; + start =untagged_addr (start); + len =PAGE_ALIGN (len + (offset_in_page (start))); start &=PAGE_MASK ;
mm/mmap.c +7 -0
@@ -199,6 +199,8 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)bool downgraded = false;LIST_HEAD (uf); + brk =untagged_addr (brk); +if (down_write_killable (&mm->mmap_sem))return -EINTR ;
@@ -1571,6 +1573,8 @@ unsigned long ksys_mmap_pgoff(unsigned long addr, unsigned long len,struct file *file =NULL ;unsigned long retval; + addr =untagged_addr (addr); +if (!(flags &MAP_ANONYMOUS )) {audit_mmap_fd (fd, flags); file =fget (fd);
@@ -2869,6 +2873,7 @@ EXPORT_SYMBOL(vm_munmap); SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len) { + addr =untagged_addr (addr);profile_munmap (addr);return __vm_munmap (addr, len, true); }
@@ -2887,6 +2892,8 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,unsigned long ret = -EINVAL ;struct file *file; + start =untagged_addr (start); +pr_warn_once ("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n" , current->comm, current->pid);
mm/mprotect.c +2 -0
@@ -578,6 +578,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, unsigned long, prot) { + start =untagged_addr (start);return do_mprotect_pkey (start, len, prot,-1 ); }
@@ -586,6 +587,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, SYSCALL_DEFINE4(pkey_mprotect, unsigned long, start, size_t, len, unsigned long, prot, int, pkey) { + start =untagged_addr (start);return do_mprotect_pkey (start, len, prot, pkey); }
mm/mremap.c +2 -0
@@ -588,6 +588,8 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,LIST_HEAD (uf_unmap_early);LIST_HEAD (uf_unmap); + addr =untagged_addr (addr); +if (flags & ~(MREMAP_FIXED |MREMAP_MAYMOVE ))return ret;
mm/msync.c +2 -0
@@ -37,6 +37,8 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)int unmapped_error =0 ;int error = -EINVAL ; + start =untagged_addr (start); +if (flags & ~(MS_ASYNC |MS_INVALIDATE |MS_SYNC )) goto out;if (offset_in_page (start))
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
Re: [PATCH v10 04/12] mm, arm64: untag user pointers passed to memory syscalls
Quoted 11 lines · Andrey Konovalov
mm/mprotect.c +1
-0@@ -578,6 +578,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, unsigned long, prot) { + start =untagged_addr (start);return do_mprotect_pkey (start, len, prot,-1 ); }
mm/mprotect.c SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, · line 592
Quoted 6 lines
mm/mprotect.c +1
-0@@ -586,6 +587,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, SYSCALL_DEFINE4(pkey_mprotect, unsigned long, start, size_t, len, unsigned long, prot, int, pkey) { + start =untagged_addr (start);return do_mprotect_pkey (start, len, prot, pkey); }
This seems to have taken the approach of going as close as possible to the syscall boundary and untagging the pointer there. I guess that's OK, but it does lead to more churn than necessary. For instance, why not just do the untagging in do_mprotect_pkey()?
I think that's an overall design question. I kinda asked the same thing about patching call sites vs. VMA lookup functions.
Re: [PATCH v10 04/12] mm, arm64: untag user pointers passed to memory syscalls
Quoted 12 lines · Dave Hansen
Quoted 10 lines · Andrey Konovalov
mm/mprotect.c +1
-0@@ -578,6 +578,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, unsigned long, prot) { + start =untagged_addr (start);return do_mprotect_pkey (start, len, prot,-1 ); }
Quoted 12 lines
mm/mprotect.c SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, · line 592
Quoted 7 lines
mm/mprotect.c +1
-0@@ -586,6 +587,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len, SYSCALL_DEFINE4(pkey_mprotect, unsigned long, start, size_t, len, unsigned long, prot, int, pkey) { + start =untagged_addr (start);return do_mprotect_pkey (start, len, prot, pkey); }This seems to have taken the approach of going as close as possible to the syscall boundary and untagging the pointer there. I guess that's OK, but it does lead to more churn than necessary. For instance, why not just do the untagging in
do_mprotect_pkey()?
I think that makes more sense, will do in the next version, thanks!
Quoted 3 lines
I think that's an overall design question. I kinda asked the same thing about patching call sites vs. VMA lookup functions.
Replied in the other thread.
PATCH v10 5/12 mm, arm64: untag user pointers in mm/gup.c
In reply to Andrey Konovalovmm/gup.c provides a kernel interface that accepts user addresses and manipulates user pages directly (for example get_user_pages, that is used by the futex syscall). Since a user can provided tagged addresses, we need to handle such case.
Add untagging to gup.c functions that use user addresses for vma lookup.
--- mm/gup.c | 4 ++++ 1 file changed, 4 insertions(+)
mm/gup.c +4 -0
@@ -683,6 +683,8 @@ static long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,if (!nr_pages)return 0 ; + start =untagged_addr (start); +VM_BUG_ON (!!pages != !!(gup_flags &FOLL_GET ));/*
@@ -845,6 +847,8 @@ int fixup_user_fault(struct task_struct *tsk, struct mm_struct *mm,struct vm_area_struct *vma;vm_fault_t ret, major =0 ; + address =untagged_addr (address); +if (unlocked) fault_flags |=FAULT_FLAG_ALLOW_RETRY ;
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v10 6/12 fs, arm64: untag user pointers in copy_mount_options
In reply to Andrey KonovalovIn copy_mount_options a user address is being subtracted from TASK_SIZE. If the address is lower than TASK_SIZE, the size is calculated to not allow the exact_copy_from_user() call to cross TASK_SIZE boundary. However if the address is tagged, then the size will be calculated incorrectly.
Untag the address before subtracting.
--- fs/namespace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/namespace.c +1 -1
@@ -2730,7 +2730,7 @@ void *copy_mount_options(const void __user * data)* the remainder of the page. */ /* copy_from_user cannot cross TASK_SIZE ! */ - size =TASK_SIZE - (unsigned long )data; + size =TASK_SIZE - (unsigned long )untagged_addr (data);if (size >PAGE_SIZE ) size =PAGE_SIZE ;
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
Re: [PATCH v10 06/12] fs, arm64: untag user pointers in copy_mount_options
fs/namespace.c void *copy_mount_options(const void __user * data) · line 2735
Quoted 10 lines · Andrey Konovalov
fs/namespace.c +1
-1@@ -2730,7 +2730,7 @@ void *copy_mount_options(const void __user * data)* the remainder of the page. */ /* copy_from_user cannot cross TASK_SIZE ! */ - size =TASK_SIZE - (unsigned long )data; + size =TASK_SIZE - (unsigned long )untagged_addr (data);if (size >PAGE_SIZE ) size =PAGE_SIZE ;
I would have thought that copy_from_user() *is* entirely capable of detecting and returning an error in the case that its arguments cross TASK_SIZE. It will fail and return an error, but that's what it's supposed to do.
I'd question why this code needs to be doing its own checking in the first place. Is there something subtle going on?
Re: [PATCH v10 06/12] fs, arm64: untag user pointers in copy_mount_options
Quoted 18 lines · Dave Hansen
fs/namespace.c void *copy_mount_options(const void __user * data) · line 2735
Quoted 10 lines · Andrey Konovalov
fs/namespace.c +1
-1@@ -2730,7 +2730,7 @@ void *copy_mount_options(const void __user * data)* the remainder of the page. */ /* copy_from_user cannot cross TASK_SIZE ! */ - size =TASK_SIZE - (unsigned long )data; + size =TASK_SIZE - (unsigned long )untagged_addr (data);if (size >PAGE_SIZE ) size =PAGE_SIZE ;I would have thought that
copy_from_user()*is* entirely capable of detecting and returning an error in the case that its arguments crossTASK_SIZE. It will fail and return an error, but that's what it's supposed to do.
Quoted 2 lines
I'd question why this code needs to be doing its own checking in the first place. Is there something subtle going on?
The comment above exact_copy_from_user() states:
Some copy_from_user() implementations do not return the exact number of bytes remaining to copy on a fault. But copy_mount_options() requires that. Note that this function differs from copy_from_user() in that it will oops on bad values of `to', rather than returning a short copy.
PATCH v10 7/12 fs, arm64: untag user pointers in fs/userfaultfd.c
In reply to Andrey Konovalovuserfaultfd_register() and userfaultfd_unregister() use provided user pointers for vma lookups, which can only by done with untagged pointers.
Untag user pointers in these functions.
--- fs/userfaultfd.c | 5 +++++ 1 file changed, 5 insertions(+)
fs/userfaultfd.c +5 -0
@@ -1320,6 +1320,9 @@ static int userfaultfd_register(struct userfaultfd_ctx *ctx, goto out; } + uffdio_register.range.start = +untagged_addr (uffdio_register.range.start); + ret =validate_range (mm, uffdio_register.range.start, uffdio_register.range.len);if (ret)
@@ -1507,6 +1510,8 @@ static int userfaultfd_unregister(struct userfaultfd_ctx *ctx,if (copy_from_user (&uffdio_unregister, buf,sizeof (uffdio_unregister))) goto out; + uffdio_unregister.start =untagged_addr (uffdio_unregister.start); + ret =validate_range (mm, uffdio_unregister.start, uffdio_unregister.len);if (ret)
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
Re: [PATCH v10 07/12] fs, arm64: untag user pointers in fs/userfaultfd.c
Quoted 2 lines · Andrey Konovalov
userfaultfd_register()anduserfaultfd_unregister()use provided user pointers for vma lookups, which can only by done with untagged pointers.
So, we have to patch all these sites before the tagged values get to the point of hitting the vma lookup functions. Dumb question: Why don't we just patch the vma lookup functions themselves instead of all of these callers?
Re: [PATCH v10 07/12] fs, arm64: untag user pointers in fs/userfaultfd.c
Quoted 9 lines · Dave Hansen
Quoted 2 lines · Andrey Konovalov
userfaultfd_register()anduserfaultfd_unregister()use provided user pointers for vma lookups, which can only by done with untagged pointers.So, we have to patch all these sites before the tagged values get to the point of hitting the vma lookup functions. Dumb question: Why don't we just patch the vma lookup functions themselves instead of all of these callers?
That might be a working approach as well. We'll still need to fix up places where the vma fields are accessed directly. Catalin, what do you think?
Catalin Marinas
maintainerRe: [PATCH v10 07/12] fs, arm64: untag user pointers in fs/userfaultfd.c
Quoted 6 lines · Andrey Konovalov
Quoted 5 lines · Dave Hansen
Quoted 2 lines · Andrey Konovalov
userfaultfd_register()anduserfaultfd_unregister()use provided user pointers for vma lookups, which can only by done with untagged pointers.
Quoted 8 lines
Quoted 4 lines
So, we have to patch all these sites before the tagged values get to the point of hitting the vma lookup functions. Dumb question: Why don't we just patch the vma lookup functions themselves instead of all of these callers?
That might be a working approach as well. We'll still need to fix up places where the vma fields are accessed directly. Catalin, what do you think?
Most callers of find_vma*() always follow it by a check of vma->vma_start against some tagged address ('end' in the userfaultfd_(un)register()) case. So it's not sufficient to untag it in find_vma().
Signature · 1 line
Catalin
Re: [PATCH v10 07/12] fs, arm64: untag user pointers in fs/userfaultfd.c
Quoted 11 lines · Catalin Marinas
Quoted 7 lines
Quoted 4 lines
So, we have to patch all these sites before the tagged values get to the point of hitting the vma lookup functions. Dumb question: Why don't we just patch the vma lookup functions themselves instead of all of these callers?
That might be a working approach as well. We'll still need to fix up places where the vma fields are accessed directly. Catalin, what do you think?
Most callers of find_vma*() always follow it by a check of
vma->vma_startagainst some tagged address ('end' in the userfaultfd_(un)register()) case. So it's not sufficient to untag it infind_vma().
If that's truly the common case, sounds like we should have a find_vma() that does the vma_end checking as well. Then at least the common case would not have to worry about tagging.
Re: [PATCH v10 07/12] fs, arm64: untag user pointers in fs/userfaultfd.c
Quoted 9 lines · Dave Hansen
Quoted 7 lines · Catalin Marinas
Quoted 7 lines
Quoted 4 lines
So, we have to patch all these sites before the tagged values get to the point of hitting the vma lookup functions. Dumb question: Why don't we just patch the vma lookup functions themselves instead of all of these callers?
That might be a working approach as well. We'll still need to fix up places where the vma fields are accessed directly. Catalin, what do you think?
Quoted 8 lines
Quoted 4 lines
Most callers of find_vma*() always follow it by a check of
vma->vma_startagainst some tagged address ('end' in the userfaultfd_(un)register()) case. So it's not sufficient to untag it infind_vma().If that's truly the common case, sounds like we should have a
find_vma()that does thevma_endchecking as well. Then at least the common case would not have to worry about tagging.
It seems that a lot of find_vma() callers indeed do different kinds of checking/subtractions of vma->vma_start and a tagged address, which look hardly unifiable. So untagging the addresses in find_vma() callers looks like a more suitable solution.
PATCH v10 8/12 net, arm64: untag user pointers in tcp_zerocopy_receive
In reply to Andrey Konovalovtcp_zerocopy_receive() uses provided user pointers for vma lookups, which can only by done with untagged pointers.
Untag user pointers in this function.
--- net/ipv4/tcp.c | 2 ++ 1 file changed, 2 insertions(+)
net/ipv4/tcp.c +2 -0
@@ -1756,6 +1756,8 @@ static int tcp_zerocopy_receive(struct sock *sk,int inq;int ret; + address =untagged_addr (address); +if (address & (PAGE_SIZE -1 ) || address != zc->address)return -EINVAL ;
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v10 9/12 kernel, arm64: untag user pointers in prctl_set_mm*
In reply to Andrey Konovalovprctl_set_mm() and prctl_set_mm_map() use provided user pointers for vma lookups, which can only by done with untagged pointers.
Untag user pointers in these functions.
--- kernel/sys.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
kernel/sys.c +14 -0
@@ -1992,6 +1992,18 @@ static int prctl_set_mm_map(int opt, const void __user *addr, unsigned long dataif (copy_from_user (&prctl_map, addr,sizeof (prctl_map)))return -EFAULT ; + prctl_map->start_code =untagged_addr (prctl_map.start_code); + prctl_map->end_code =untagged_addr (prctl_map.end_code); + prctl_map->start_data =untagged_addr (prctl_map.start_data); + prctl_map->end_data =untagged_addr (prctl_map.end_data); + prctl_map->start_brk =untagged_addr (prctl_map.start_brk); + prctl_map->brk =untagged_addr (prctl_map.brk); + prctl_map->start_stack =untagged_addr (prctl_map.start_stack); + prctl_map->arg_start =untagged_addr (prctl_map.arg_start); + prctl_map->arg_end =untagged_addr (prctl_map.arg_end); + prctl_map->env_start =untagged_addr (prctl_map.env_start); + prctl_map->env_end =untagged_addr (prctl_map.env_end); + error =validate_prctl_map (&prctl_map);if (error)return error;
@@ -2105,6 +2117,8 @@ static int prctl_set_mm(int opt, unsigned long addr, opt != PR_SET_MM_MAP_SIZE)))return -EINVAL ; + addr =untagged_addr (addr); +#ifdef CONFIG_CHECKPOINT_RESTORE if (opt ==PR_SET_MM_MAP || opt ==PR_SET_MM_MAP_SIZE )return prctl_set_mm_map (opt, (const void __user *)addr, arg4);
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v10 10/12 tracing, arm64: untag user pointers in seq_print_user_ip
In reply to Andrey Konovalovseq_print_user_ip() uses provided user pointers for vma lookups, which can only by done with untagged pointers.
Untag user pointers in this function.
--- kernel/trace/trace_output.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_output.c +1 -1
@@ -379,7 +379,7 @@ static int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,const struct vm_area_struct *vma;down_read (&mm->mmap_sem); - vma =find_vma (mm, ip); + vma =find_vma (mm,untagged_addr (ip));if (vma) { file = vma->vm_file; vmstart = vma->vm_start;
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v10 11/12 arm64: update Documentation/arm64/tagged-pointers.txt
In reply to Andrey KonovalovDocument the changes in Documentation/arm64/tagged-pointers.txt.
--- Documentation/arm64/tagged-pointers.txt | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-)
Documentation/arm64/tagged-pointers.txt +15 -10
@@ -17,13 +17,22 @@ this byte for application use. Passing tagged addresses to the kernel -------------------------------------- -All interpretation of userspace memory addresses by the kernel assumes -an address tag of 0x00. +The kernel supports tags in pointer arguments (including pointers in +structures) for a limited set of syscalls, the exceptions are: -This includes, but is not limited to, addresses found in: + - memory syscalls: brk, madvise, mbind, mincore, mlock, mlock2, move_pages, + mprotect, mremap, msync, munlock, munmap, pkey_mprotect, process_vm_readv, + process_vm_writev, remap_file_pages; - - pointer arguments to system calls, including pointers in structures - passed to system calls, + - ioctls that accept user pointers that describe virtual memory ranges; + + - TCP_ZEROCOPY_RECEIVE setsockopt. + +The kernel supports tags in user fault addresses. However the fault_address +field in the sigcontext struct will contain an untagged address. + +All other interpretations of userspace memory addresses by the kernel +assume an address tag of 0x00, in particular: - the stack pointer (sp), e.g. when interpreting it to deliver a signal,
@@ -33,11 +42,7 @@ This includes, but is not limited to, addresses found in: Using non-zero address tags in any of these locations may result in an error code being returned, a (fatal) signal being raised, or other modes -of failure. - -For these reasons, passing non-zero address tags to the kernel via -system calls is forbidden, and using a non-zero address tag for sp is -strongly discouraged. +of failure. Using a non-zero address tag for sp is strongly discouraged. Programs maintaining a frame pointer and frame records that use non-zero address tags may suffer impaired or inaccurate debug and profiling
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
PATCH v10 12/12 selftests, arm64: add a selftest for passing tagged pointers to kernel
In reply to Andrey KonovalovThis patch adds a simple test, that calls the uname syscall with a tagged user pointer as an argument. Without the kernel accepting tagged user pointers the test fails with EFAULT.
--- tools/testing/selftests/arm64/.gitignore | 1 + tools/testing/selftests/arm64/Makefile | 11 +++++++++++ .../testing/selftests/arm64/run_tags_test.sh | 12 ++++++++++++ tools/testing/selftests/arm64/tags_test.c | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100644 tools/testing/selftests/arm64/.gitignore create mode 100644 tools/testing/selftests/arm64/Makefile create mode 100755 tools/testing/selftests/arm64/run_tags_test.sh create mode 100644 tools/testing/selftests/arm64/tags_test.c
tools/testing/selftests/arm64/.gitignore new file +1 -0
@@ -0,0 +1 @@ +tags_test
tools/testing/selftests/arm64/Makefile new file +11 -0
@@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 + +# ARCH can be overridden by the user for cross compiling +ARCH ?= $(shell uname -m 2>/dev/null || echo not) + +ifneq (,$(filter $(ARCH),aarch64 arm64)) +TEST_GEN_PROGS := tags_test +TEST_PROGS := run_tags_test.sh +endif + +include ../lib.mk
tools/testing/selftests/arm64/run_tags_test.sh new file +12 -0
@@ -0,0 +1,12 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 + +echo "--------------------" +echo "running tags test" +echo "--------------------" +./tags_test +if [ $? -ne 0 ]; then + echo "[FAIL]" +else + echo "[PASS]" +fi
tools/testing/selftests/arm64/tags_test.c new file +19 -0
@@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <stdio.h> +#include <unistd.h> +#include <stdint.h> +#include <sys/utsname.h> + +#define SHIFT_TAG (tag) ((uint64_t)(tag) << 56) +#define SET_TAG (ptr, tag) (((uint64_t)(ptr) & ~SHIFT_TAG(0xff)) | \ + SHIFT_TAG(tag)) + +int main (void ) +{ +struct utsname utsname; +void *ptr = &utsname; +void *tagged_ptr = (void *)SET_TAG (ptr,0x42 ); +int err =uname (tagged_ptr); +return err; +}
Signature · 1 line
2.21.0.rc0.258.g878e2cd30e-goog
Quoted 25 lines · Andrey Konovalov
This patchset is meant to be merged together with "arm64 relaxed ABI" [1].
arm64 has a feature called Top Byte Ignore, which allows to embed pointer tags into the top byte of each pointer. Userspace programs (such as HWASan, a memory debugging tool [2]) might use this feature and pass tagged user pointers to the kernel through syscalls or other interfaces.
Right now the kernel is already able to handle user faults with tagged pointers, due to these patches:
1.
81cddd65("arm64: traps: fix userspace cache maintenance emulation on a tagged pointer")
2.7dcd9dd8("arm64:hw_breakpoint: fix watchpoint matching for tagged pointers")
3.276e9327("arm64: entry: improve data abort handling of tagged pointers")This patchset extends tagged pointer support to syscall arguments.
For non-memory syscalls this is done by untaging user pointers when the kernel performs pointer checking to find out whether the pointer comes from userspace (most notably in
access_ok). The untagging is done only when the pointer is being checked, the tag is preserved as the pointer makes its way through the kernel.
Quoted 4 lines
Since memory syscalls (mmap, mprotect, etc.) don't do memory accesses but rather deal with memory ranges, untagged pointers are better suited to describe memory ranges internally. Thus for memory syscalls we untag pointers completely when they enter the kernel.
i think the same is true when user pointers are compared.
e.g. i suspect there may be issues with tagged robust mutex list pointers because the kernel does
futex.c:3541: while (entry != &head->list) {
where entry is a user pointer that may be tagged, and &head->list is probably not tagged.
Quoted 156 lines
One of the alternative approaches to untagging that was considered is to completely strip the pointer tag as the pointer enters the kernel with some kind of a syscall wrapper, but that won't work with the countless number of different ioctl calls. With this approach we would need a custom wrapper for each ioctl variation, which doesn't seem practical.
The following testing approaches has been taken to find potential issues with user pointer untagging:
1. Static testing (with sparse [3] and separately with a custom static analyzer based on Clang) to track casts of
__userpointers to integer types to find places where untagging needs to be done.2. Static testing with grep to find parts of the kernel that call
find_vma()(and other similar functions) or directly compare against vm_start/vm_end fields of vma.3. Static testing with grep to find parts of the kernel that compare user pointers with
TASK_SIZEor other similar consts and macros.4. Dynamic testing: adding BUG_ON(has_tag(addr)) to
find_vma()and running a modified syzkaller version that passes tagged pointers to the kernel.Based on the results of the testing the requried patches have been added to the patchset.
This patchset has been merged into the Pixel 2 kernel tree and is now being used to enable testing of Pixel 2 phones with HWASan.
This patchset is a prerequisite for ARM's memory tagging hardware feature support [4].
Thanks!
[1] https://lkml.org/lkml/2018/12/10/402
[2] http://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html
[3] https://github.com/lucvoo/sparse-dev/commit/5f960cb10f56ec2017c128ef9d16060e0145f292
Changes in v10:
- Added "mm, arm64: untag user pointers passed to memory syscalls" back.
- New patch "fs, arm64: untag user pointers infs/userfaultfd.c".
- New patch "net, arm64: untag user pointers intcp_zerocopy_receive".
- New patch "kernel, arm64: untag user pointers in prctl_set_mm*".
- New patch "tracing, arm64: untag user pointers inseq_print_user_ip".Changes in v9:
- Rebased onto 4.20-rc6.
- Used u64 instead of__u64in type casts in theuntagged_addrmacro for arm64.
- Added braces around (addr) in theuntagged_addrmacro for other arches.Changes in v8:
- Rebased onto 65102238 (4.20-rc1).
- Added a note to the cover letter on why syscall wrappers/shims that untag user pointers won't work.
- Added a note to the cover letter that this patchset has been merged into the Pixel 2 kernel tree.
- Documentation fixes, in particular added a list of syscalls that don't support tagged user pointers.Changes in v7:
- Rebased onto17b57b18(4.19-rc6).
- Dropped the "arm64: untag user address in__do_user_fault" patch, since the existing patches already handle user faults properly.
- Dropped the "usb, arm64: untag user addresses in devio" patch, since the passed pointer must come from a vma and therefore be untagged.
- Dropped the "arm64: annotate user pointers casts detected by sparse" patch (see the discussion to the replies of the v6 of this patchset).
- Added more context to the cover letter.
- UpdatedDocumentation/arm64/tagged-pointers.txt.Changes in v6:
- Added annotations for user pointer casts found by sparse.
- Rebased onto050cdc6c(4.19-rc1+).Changes in v5:
- Added 3 new patches that add untagging to places found with static analysis.
- Rebased onto44c929e1(4.18-rc8).Changes in v4:
- Added a selftest for checking that passing tagged pointers to the kernel succeeds.
- Rebased onto81e97f013(4.18-rc1+).Changes in v3:
- Rebased ontoe5c51f30(4.17-rc6+).
- Added linux-arch@ to the list of recipients.Changes in v2:
- Rebased onto2d618bdf(4.17-rc3+).
- Removed excessive untagging ingup.c.
- Removed untagging pointers returned from__uaccess_mask_ptr.Changes in v1:
- Rebased onto 4.17-rc1.Changes in RFC v2:
- Added "#ifndefuntagged_addr..." fallback inlinux/uaccess.hinstead of defining it for each arch individually.
- UpdatedDocumentation/arm64/tagged-pointers.txt.
- Dropped "mm, arm64: untag user addresses in memory syscalls".
- Rebased onto3eb2ce82(4.16-rc7).Reviewed-by Luc Van Oostenryck <[email protected]>Signed-off-by Andrey Konovalov <[email protected]>Andrey Konovalov (12):
uaccess: adduntagged_addrdefinition for other arches
arm64: untag user pointers inaccess_okand__uaccess_mask_ptrlib, arm64: untag user pointers in strn*_user
mm, arm64: untag user pointers passed to memory syscalls mm, arm64: untag user pointers inmm/gup.c
fs, arm64: untag user pointers incopy_mount_options
fs, arm64: untag user pointers infs/userfaultfd.c
net, arm64: untag user pointers intcp_zerocopy_receivekernel, arm64: untag user pointers in prctl_set_mm* tracing, arm64: untag user pointers inseq_print_user_ip
arm64: updateDocumentation/arm64/tagged-pointers.txtselftests, arm64: add a selftest for passing tagged pointers to kernelDocumentation/arm64/tagged-pointers.txt | 25 +++++++++++-------- arch/arm64/include/asm/uaccess.h | 10 +++++--- fs/namespace.c | 2 +- fs/userfaultfd.c | 5 ++++ include/linux/memory.h | 4 +++ ipc/shm.c | 2 ++ kernel/sys.c | 14 +++++++++++ kernel/trace/trace_output.c | 2 +- lib/strncpy_from_user.c | 2 ++ lib/strnlen_user.c | 2 ++ mm/gup.c | 4 +++ mm/madvise.c | 2 ++ mm/mempolicy.c | 5 ++++ mm/migrate.c | 1 + mm/mincore.c | 2 ++ mm/mlock.c | 5 ++++ mm/mmap.c | 7 ++++++ mm/mprotect.c | 2 ++ mm/mremap.c | 2 ++ mm/msync.c | 2 ++ net/ipv4/tcp.c | 2 ++ tools/testing/selftests/arm64/.gitignore | 1 + tools/testing/selftests/arm64/Makefile | 11 ++++++++ .../testing/selftests/arm64/run_tags_test.sh | 12 +++++++++ tools/testing/selftests/arm64/tags_test.c | 19 ++++++++++++++ 25 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 tools/testing/selftests/arm64/.gitignore create mode 100644 tools/testing/selftests/arm64/Makefile create mode 100755 tools/testing/selftests/arm64/run_tags_test.sh create mode 100644 tools/testing/selftests/arm64/tags_test.c
Quoted 34 lines · Szabolcs Nagy
Quoted 25 lines · Andrey Konovalov
This patchset is meant to be merged together with "arm64 relaxed ABI" [1].
arm64 has a feature called Top Byte Ignore, which allows to embed pointer tags into the top byte of each pointer. Userspace programs (such as HWASan, a memory debugging tool [2]) might use this feature and pass tagged user pointers to the kernel through syscalls or other interfaces.
Right now the kernel is already able to handle user faults with tagged pointers, due to these patches:
1.
81cddd65("arm64: traps: fix userspace cache maintenance emulation on a tagged pointer")
2.7dcd9dd8("arm64:hw_breakpoint: fix watchpoint matching for tagged pointers")
3.276e9327("arm64: entry: improve data abort handling of tagged pointers")This patchset extends tagged pointer support to syscall arguments.
For non-memory syscalls this is done by untaging user pointers when the kernel performs pointer checking to find out whether the pointer comes from userspace (most notably in
access_ok). The untagging is done only when the pointer is being checked, the tag is preserved as the pointer makes its way through the kernel.Quoted 4 lines
Since memory syscalls (mmap, mprotect, etc.) don't do memory accesses but rather deal with memory ranges, untagged pointers are better suited to describe memory ranges internally. Thus for memory syscalls we untag pointers completely when they enter the kernel.
i think the same is true when user pointers are compared.
Quoted 7 lines
e.g. i suspect there may be issues with tagged robust mutex list pointers because the kernel does
futex.c:3541: while (entry !=
&head->list) {where entry is a user pointer that may be tagged, and
&head->listis probably not tagged.
You're right. I'll expand the cover letter in the next version to describe this more accurately. The patchset however contains "mm,
arm64: untag user pointers in mm/gup.c" that should take care of futex pointers.
Thanks!
Quoted 158 lines
Quoted 157 lines
One of the alternative approaches to untagging that was considered is to completely strip the pointer tag as the pointer enters the kernel with some kind of a syscall wrapper, but that won't work with the countless number of different ioctl calls. With this approach we would need a custom wrapper for each ioctl variation, which doesn't seem practical.
The following testing approaches has been taken to find potential issues with user pointer untagging:
1. Static testing (with sparse [3] and separately with a custom static analyzer based on Clang) to track casts of
__userpointers to integer types to find places where untagging needs to be done.2. Static testing with grep to find parts of the kernel that call
find_vma()(and other similar functions) or directly compare against vm_start/vm_end fields of vma.3. Static testing with grep to find parts of the kernel that compare user pointers with
TASK_SIZEor other similar consts and macros.4. Dynamic testing: adding BUG_ON(has_tag(addr)) to
find_vma()and running a modified syzkaller version that passes tagged pointers to the kernel.Based on the results of the testing the requried patches have been added to the patchset.
This patchset has been merged into the Pixel 2 kernel tree and is now being used to enable testing of Pixel 2 phones with HWASan.
This patchset is a prerequisite for ARM's memory tagging hardware feature support [4].
Thanks!
[1] https://lkml.org/lkml/2018/12/10/402
[2] http://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html
[3] https://github.com/lucvoo/sparse-dev/commit/5f960cb10f56ec2017c128ef9d16060e0145f292
Changes in v10:
- Added "mm, arm64: untag user pointers passed to memory syscalls" back.
- New patch "fs, arm64: untag user pointers infs/userfaultfd.c".
- New patch "net, arm64: untag user pointers intcp_zerocopy_receive".
- New patch "kernel, arm64: untag user pointers in prctl_set_mm*".
- New patch "tracing, arm64: untag user pointers inseq_print_user_ip".Changes in v9:
- Rebased onto 4.20-rc6.
- Used u64 instead of__u64in type casts in theuntagged_addrmacro for arm64.
- Added braces around (addr) in theuntagged_addrmacro for other arches.Changes in v8:
- Rebased onto 65102238 (4.20-rc1).
- Added a note to the cover letter on why syscall wrappers/shims that untag user pointers won't work.
- Added a note to the cover letter that this patchset has been merged into the Pixel 2 kernel tree.
- Documentation fixes, in particular added a list of syscalls that don't support tagged user pointers.Changes in v7:
- Rebased onto17b57b18(4.19-rc6).
- Dropped the "arm64: untag user address in__do_user_fault" patch, since the existing patches already handle user faults properly.
- Dropped the "usb, arm64: untag user addresses in devio" patch, since the passed pointer must come from a vma and therefore be untagged.
- Dropped the "arm64: annotate user pointers casts detected by sparse" patch (see the discussion to the replies of the v6 of this patchset).
- Added more context to the cover letter.
- UpdatedDocumentation/arm64/tagged-pointers.txt.Changes in v6:
- Added annotations for user pointer casts found by sparse.
- Rebased onto050cdc6c(4.19-rc1+).Changes in v5:
- Added 3 new patches that add untagging to places found with static analysis.
- Rebased onto44c929e1(4.18-rc8).Changes in v4:
- Added a selftest for checking that passing tagged pointers to the kernel succeeds.
- Rebased onto81e97f013(4.18-rc1+).Changes in v3:
- Rebased ontoe5c51f30(4.17-rc6+).
- Added linux-arch@ to the list of recipients.Changes in v2:
- Rebased onto2d618bdf(4.17-rc3+).
- Removed excessive untagging ingup.c.
- Removed untagging pointers returned from__uaccess_mask_ptr.Changes in v1:
- Rebased onto 4.17-rc1.Changes in RFC v2:
- Added "#ifndefuntagged_addr..." fallback inlinux/uaccess.hinstead of defining it for each arch individually.
- UpdatedDocumentation/arm64/tagged-pointers.txt.
- Dropped "mm, arm64: untag user addresses in memory syscalls".
- Rebased onto3eb2ce82(4.16-rc7).Reviewed-by Luc Van Oostenryck <[email protected]>Signed-off-by Andrey Konovalov <[email protected]>Andrey Konovalov (12):
uaccess: adduntagged_addrdefinition for other arches
arm64: untag user pointers inaccess_okand__uaccess_mask_ptrlib, arm64: untag user pointers in strn*_user
mm, arm64: untag user pointers passed to memory syscalls mm, arm64: untag user pointers inmm/gup.c
fs, arm64: untag user pointers incopy_mount_options
fs, arm64: untag user pointers infs/userfaultfd.c
net, arm64: untag user pointers intcp_zerocopy_receivekernel, arm64: untag user pointers in prctl_set_mm* tracing, arm64: untag user pointers inseq_print_user_ip
arm64: updateDocumentation/arm64/tagged-pointers.txtselftests, arm64: add a selftest for passing tagged pointers to kernelDocumentation/arm64/tagged-pointers.txt | 25 +++++++++++-------- arch/arm64/include/asm/uaccess.h | 10 +++++--- fs/namespace.c | 2 +- fs/userfaultfd.c | 5 ++++ include/linux/memory.h | 4 +++ ipc/shm.c | 2 ++ kernel/sys.c | 14 +++++++++++ kernel/trace/trace_output.c | 2 +- lib/strncpy_from_user.c | 2 ++ lib/strnlen_user.c | 2 ++ mm/gup.c | 4 +++ mm/madvise.c | 2 ++ mm/mempolicy.c | 5 ++++ mm/migrate.c | 1 + mm/mincore.c | 2 ++ mm/mlock.c | 5 ++++ mm/mmap.c | 7 ++++++ mm/mprotect.c | 2 ++ mm/mremap.c | 2 ++ mm/msync.c | 2 ++ net/ipv4/tcp.c | 2 ++ tools/testing/selftests/arm64/.gitignore | 1 + tools/testing/selftests/arm64/Makefile | 11 ++++++++ .../testing/selftests/arm64/run_tags_test.sh | 12 +++++++++ tools/testing/selftests/arm64/tags_test.c | 19 ++++++++++++++ 25 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 tools/testing/selftests/arm64/.gitignore create mode 100644 tools/testing/selftests/arm64/Makefile create mode 100755 tools/testing/selftests/arm64/run_tags_test.sh create mode 100644 tools/testing/selftests/arm64/tags_test.c
Quoted 40 lines · Andrey Konovalov
Quoted 39 lines · Szabolcs Nagy
Quoted 25 lines · Andrey Konovalov
This patchset is meant to be merged together with "arm64 relaxed ABI" [1].
arm64 has a feature called Top Byte Ignore, which allows to embed pointer tags into the top byte of each pointer. Userspace programs (such as HWASan, a memory debugging tool [2]) might use this feature and pass tagged user pointers to the kernel through syscalls or other interfaces.
Right now the kernel is already able to handle user faults with tagged pointers, due to these patches:
1.
81cddd65("arm64: traps: fix userspace cache maintenance emulation on a tagged pointer")
2.7dcd9dd8("arm64:hw_breakpoint: fix watchpoint matching for tagged pointers")
3.276e9327("arm64: entry: improve data abort handling of tagged pointers")This patchset extends tagged pointer support to syscall arguments.
For non-memory syscalls this is done by untaging user pointers when the kernel performs pointer checking to find out whether the pointer comes from userspace (most notably in
access_ok). The untagging is done only when the pointer is being checked, the tag is preserved as the pointer makes its way through the kernel.Quoted 4 lines
Since memory syscalls (mmap, mprotect, etc.) don't do memory accesses but rather deal with memory ranges, untagged pointers are better suited to describe memory ranges internally. Thus for memory syscalls we untag pointers completely when they enter the kernel.
i think the same is true when user pointers are compared.
e.g. i suspect there may be issues with tagged robust mutex list pointers because the kernel does
futex.c:3541: while (entry !=
&head->list) {
Quoted 7 lines
Quoted 2 lines
where entry is a user pointer that may be tagged, and
&head->listis probably not tagged.You're right. I'll expand the cover letter in the next version to describe this more accurately. The patchset however contains "mm,
arm64: untag user pointers inmm/gup.c" that should take care of futex pointers.
the robust mutex list pointer is not a futex pointer, i'm not sure how the mm/gup.c patch helps.
Quoted 158 lines
Quoted 158 lines
Quoted 157 lines
One of the alternative approaches to untagging that was considered is to completely strip the pointer tag as the pointer enters the kernel with some kind of a syscall wrapper, but that won't work with the countless number of different ioctl calls. With this approach we would need a custom wrapper for each ioctl variation, which doesn't seem practical.
The following testing approaches has been taken to find potential issues with user pointer untagging:
1. Static testing (with sparse [3] and separately with a custom static analyzer based on Clang) to track casts of
__userpointers to integer types to find places where untagging needs to be done.2. Static testing with grep to find parts of the kernel that call
find_vma()(and other similar functions) or directly compare against vm_start/vm_end fields of vma.3. Static testing with grep to find parts of the kernel that compare user pointers with
TASK_SIZEor other similar consts and macros.4. Dynamic testing: adding BUG_ON(has_tag(addr)) to
find_vma()and running a modified syzkaller version that passes tagged pointers to the kernel.Based on the results of the testing the requried patches have been added to the patchset.
This patchset has been merged into the Pixel 2 kernel tree and is now being used to enable testing of Pixel 2 phones with HWASan.
This patchset is a prerequisite for ARM's memory tagging hardware feature support [4].
Thanks!
[1] https://lkml.org/lkml/2018/12/10/402
[2] http://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html
[3] https://github.com/lucvoo/sparse-dev/commit/5f960cb10f56ec2017c128ef9d16060e0145f292
Changes in v10:
- Added "mm, arm64: untag user pointers passed to memory syscalls" back.
- New patch "fs, arm64: untag user pointers infs/userfaultfd.c".
- New patch "net, arm64: untag user pointers intcp_zerocopy_receive".
- New patch "kernel, arm64: untag user pointers in prctl_set_mm*".
- New patch "tracing, arm64: untag user pointers inseq_print_user_ip".Changes in v9:
- Rebased onto 4.20-rc6.
- Used u64 instead of__u64in type casts in theuntagged_addrmacro for arm64.
- Added braces around (addr) in theuntagged_addrmacro for other arches.Changes in v8:
- Rebased onto 65102238 (4.20-rc1).
- Added a note to the cover letter on why syscall wrappers/shims that untag user pointers won't work.
- Added a note to the cover letter that this patchset has been merged into the Pixel 2 kernel tree.
- Documentation fixes, in particular added a list of syscalls that don't support tagged user pointers.Changes in v7:
- Rebased onto17b57b18(4.19-rc6).
- Dropped the "arm64: untag user address in__do_user_fault" patch, since the existing patches already handle user faults properly.
- Dropped the "usb, arm64: untag user addresses in devio" patch, since the passed pointer must come from a vma and therefore be untagged.
- Dropped the "arm64: annotate user pointers casts detected by sparse" patch (see the discussion to the replies of the v6 of this patchset).
- Added more context to the cover letter.
- UpdatedDocumentation/arm64/tagged-pointers.txt.Changes in v6:
- Added annotations for user pointer casts found by sparse.
- Rebased onto050cdc6c(4.19-rc1+).Changes in v5:
- Added 3 new patches that add untagging to places found with static analysis.
- Rebased onto44c929e1(4.18-rc8).Changes in v4:
- Added a selftest for checking that passing tagged pointers to the kernel succeeds.
- Rebased onto81e97f013(4.18-rc1+).Changes in v3:
- Rebased ontoe5c51f30(4.17-rc6+).
- Added linux-arch@ to the list of recipients.Changes in v2:
- Rebased onto2d618bdf(4.17-rc3+).
- Removed excessive untagging ingup.c.
- Removed untagging pointers returned from__uaccess_mask_ptr.Changes in v1:
- Rebased onto 4.17-rc1.Changes in RFC v2:
- Added "#ifndefuntagged_addr..." fallback inlinux/uaccess.hinstead of defining it for each arch individually.
- UpdatedDocumentation/arm64/tagged-pointers.txt.
- Dropped "mm, arm64: untag user addresses in memory syscalls".
- Rebased onto3eb2ce82(4.16-rc7).Reviewed-by Luc Van Oostenryck <[email protected]>Signed-off-by Andrey Konovalov <[email protected]>Andrey Konovalov (12):
uaccess: adduntagged_addrdefinition for other arches
arm64: untag user pointers inaccess_okand__uaccess_mask_ptrlib, arm64: untag user pointers in strn*_user
mm, arm64: untag user pointers passed to memory syscalls mm, arm64: untag user pointers inmm/gup.c
fs, arm64: untag user pointers incopy_mount_options
fs, arm64: untag user pointers infs/userfaultfd.c
net, arm64: untag user pointers intcp_zerocopy_receivekernel, arm64: untag user pointers in prctl_set_mm* tracing, arm64: untag user pointers inseq_print_user_ip
arm64: updateDocumentation/arm64/tagged-pointers.txtselftests, arm64: add a selftest for passing tagged pointers to kernelDocumentation/arm64/tagged-pointers.txt | 25 +++++++++++-------- arch/arm64/include/asm/uaccess.h | 10 +++++--- fs/namespace.c | 2 +- fs/userfaultfd.c | 5 ++++ include/linux/memory.h | 4 +++ ipc/shm.c | 2 ++ kernel/sys.c | 14 +++++++++++ kernel/trace/trace_output.c | 2 +- lib/strncpy_from_user.c | 2 ++ lib/strnlen_user.c | 2 ++ mm/gup.c | 4 +++ mm/madvise.c | 2 ++ mm/mempolicy.c | 5 ++++ mm/migrate.c | 1 + mm/mincore.c | 2 ++ mm/mlock.c | 5 ++++ mm/mmap.c | 7 ++++++ mm/mprotect.c | 2 ++ mm/mremap.c | 2 ++ mm/msync.c | 2 ++ net/ipv4/tcp.c | 2 ++ tools/testing/selftests/arm64/.gitignore | 1 + tools/testing/selftests/arm64/Makefile | 11 ++++++++ .../testing/selftests/arm64/run_tags_test.sh | 12 +++++++++ tools/testing/selftests/arm64/tags_test.c | 19 ++++++++++++++ 25 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 tools/testing/selftests/arm64/.gitignore create mode 100644 tools/testing/selftests/arm64/Makefile create mode 100755 tools/testing/selftests/arm64/run_tags_test.sh create mode 100644 tools/testing/selftests/arm64/tags_test.c
Quoted 45 lines · Szabolcs Nagy
Quoted 43 lines · Andrey Konovalov
Quoted 41 lines · Szabolcs Nagy
Quoted 25 lines · Andrey Konovalov
This patchset is meant to be merged together with "arm64 relaxed ABI" [1].
arm64 has a feature called Top Byte Ignore, which allows to embed pointer tags into the top byte of each pointer. Userspace programs (such as HWASan, a memory debugging tool [2]) might use this feature and pass tagged user pointers to the kernel through syscalls or other interfaces.
Right now the kernel is already able to handle user faults with tagged pointers, due to these patches:
1.
81cddd65("arm64: traps: fix userspace cache maintenance emulation on a tagged pointer")
2.7dcd9dd8("arm64:hw_breakpoint: fix watchpoint matching for tagged pointers")
3.276e9327("arm64: entry: improve data abort handling of tagged pointers")This patchset extends tagged pointer support to syscall arguments.
For non-memory syscalls this is done by untaging user pointers when the kernel performs pointer checking to find out whether the pointer comes from userspace (most notably in
access_ok). The untagging is done only when the pointer is being checked, the tag is preserved as the pointer makes its way through the kernel.Quoted 4 lines
Since memory syscalls (mmap, mprotect, etc.) don't do memory accesses but rather deal with memory ranges, untagged pointers are better suited to describe memory ranges internally. Thus for memory syscalls we untag pointers completely when they enter the kernel.
i think the same is true when user pointers are compared.
e.g. i suspect there may be issues with tagged robust mutex list pointers because the kernel does
futex.c:3541: while (entry !=
&head->list) {where entry is a user pointer that may be tagged, and
&head->listis probably not tagged.
Quoted 7 lines
Quoted 4 lines
You're right. I'll expand the cover letter in the next version to describe this more accurately. The patchset however contains "mm,
arm64: untag user pointers inmm/gup.c" that should take care of futex pointers.the robust mutex list pointer is not a futex pointer, i'm not sure how the
mm/gup.cpatch helps.
Oh, I've misinterpreted what you said, sorry.
I've looked at the robust futex list implementation, and I'm not sure if we need to add untagging here.
Quoted 1 line
Quoted 1 line
Quoted 1 line
futex.c:3541: while (entry !=
&head->list) {
Here head has whatever value user has set via the set_robust_list syscall and it might be tagged. AFAIU this loop iterates over the robust list stored in userspace, until it encounters the head pointer again, at which point the kernel decides that it has iterated over the whole list and stops. The question is whether we want the user to use the same tag for the pointer that is passed to the set_robust_list syscall and the pointer that is used to mark the end of the robust list.
Catalin, what do you think?
Quoted 160 lines
Quoted 159 lines
Quoted 159 lines
Quoted 158 lines
One of the alternative approaches to untagging that was considered is to completely strip the pointer tag as the pointer enters the kernel with some kind of a syscall wrapper, but that won't work with the countless number of different ioctl calls. With this approach we would need a custom wrapper for each ioctl variation, which doesn't seem practical.
The following testing approaches has been taken to find potential issues with user pointer untagging:
1. Static testing (with sparse [3] and separately with a custom static analyzer based on Clang) to track casts of
__userpointers to integer types to find places where untagging needs to be done.2. Static testing with grep to find parts of the kernel that call
find_vma()(and other similar functions) or directly compare against vm_start/vm_end fields of vma.3. Static testing with grep to find parts of the kernel that compare user pointers with
TASK_SIZEor other similar consts and macros.4. Dynamic testing: adding BUG_ON(has_tag(addr)) to
find_vma()and running a modified syzkaller version that passes tagged pointers to the kernel.Based on the results of the testing the requried patches have been added to the patchset.
This patchset has been merged into the Pixel 2 kernel tree and is now being used to enable testing of Pixel 2 phones with HWASan.
This patchset is a prerequisite for ARM's memory tagging hardware feature support [4].
Thanks!
[1] https://lkml.org/lkml/2018/12/10/402
[2] http://clang.llvm.org/docs/HardwareAssistedAddressSanitizerDesign.html
[3] https://github.com/lucvoo/sparse-dev/commit/5f960cb10f56ec2017c128ef9d16060e0145f292
Changes in v10:
- Added "mm, arm64: untag user pointers passed to memory syscalls" back.
- New patch "fs, arm64: untag user pointers infs/userfaultfd.c".
- New patch "net, arm64: untag user pointers intcp_zerocopy_receive".
- New patch "kernel, arm64: untag user pointers in prctl_set_mm*".
- New patch "tracing, arm64: untag user pointers inseq_print_user_ip".Changes in v9:
- Rebased onto 4.20-rc6.
- Used u64 instead of__u64in type casts in theuntagged_addrmacro for arm64.
- Added braces around (addr) in theuntagged_addrmacro for other arches.Changes in v8:
- Rebased onto 65102238 (4.20-rc1).
- Added a note to the cover letter on why syscall wrappers/shims that untag user pointers won't work.
- Added a note to the cover letter that this patchset has been merged into the Pixel 2 kernel tree.
- Documentation fixes, in particular added a list of syscalls that don't support tagged user pointers.Changes in v7:
- Rebased onto17b57b18(4.19-rc6).
- Dropped the "arm64: untag user address in__do_user_fault" patch, since the existing patches already handle user faults properly.
- Dropped the "usb, arm64: untag user addresses in devio" patch, since the passed pointer must come from a vma and therefore be untagged.
- Dropped the "arm64: annotate user pointers casts detected by sparse" patch (see the discussion to the replies of the v6 of this patchset).
- Added more context to the cover letter.
- UpdatedDocumentation/arm64/tagged-pointers.txt.Changes in v6:
- Added annotations for user pointer casts found by sparse.
- Rebased onto050cdc6c(4.19-rc1+).Changes in v5:
- Added 3 new patches that add untagging to places found with static analysis.
- Rebased onto44c929e1(4.18-rc8).Changes in v4:
- Added a selftest for checking that passing tagged pointers to the kernel succeeds.
- Rebased onto81e97f013(4.18-rc1+).Changes in v3:
- Rebased ontoe5c51f30(4.17-rc6+).
- Added linux-arch@ to the list of recipients.Changes in v2:
- Rebased onto2d618bdf(4.17-rc3+).
- Removed excessive untagging ingup.c.
- Removed untagging pointers returned from__uaccess_mask_ptr.Changes in v1:
- Rebased onto 4.17-rc1.Changes in RFC v2:
- Added "#ifndefuntagged_addr..." fallback inlinux/uaccess.hinstead of defining it for each arch individually.
- UpdatedDocumentation/arm64/tagged-pointers.txt.
- Dropped "mm, arm64: untag user addresses in memory syscalls".
- Rebased onto3eb2ce82(4.16-rc7).Reviewed-by Luc Van Oostenryck <[email protected]>Signed-off-by Andrey Konovalov <[email protected]>Andrey Konovalov (12):
uaccess: adduntagged_addrdefinition for other arches
arm64: untag user pointers inaccess_okand__uaccess_mask_ptrlib, arm64: untag user pointers in strn*_user
mm, arm64: untag user pointers passed to memory syscalls mm, arm64: untag user pointers inmm/gup.c
fs, arm64: untag user pointers incopy_mount_options
fs, arm64: untag user pointers infs/userfaultfd.c
net, arm64: untag user pointers intcp_zerocopy_receivekernel, arm64: untag user pointers in prctl_set_mm* tracing, arm64: untag user pointers inseq_print_user_ip
arm64: updateDocumentation/arm64/tagged-pointers.txtselftests, arm64: add a selftest for passing tagged pointers to kernelDocumentation/arm64/tagged-pointers.txt | 25 +++++++++++-------- arch/arm64/include/asm/uaccess.h | 10 +++++--- fs/namespace.c | 2 +- fs/userfaultfd.c | 5 ++++ include/linux/memory.h | 4 +++ ipc/shm.c | 2 ++ kernel/sys.c | 14 +++++++++++ kernel/trace/trace_output.c | 2 +- lib/strncpy_from_user.c | 2 ++ lib/strnlen_user.c | 2 ++ mm/gup.c | 4 +++ mm/madvise.c | 2 ++ mm/mempolicy.c | 5 ++++ mm/migrate.c | 1 + mm/mincore.c | 2 ++ mm/mlock.c | 5 ++++ mm/mmap.c | 7 ++++++ mm/mprotect.c | 2 ++ mm/mremap.c | 2 ++ mm/msync.c | 2 ++ net/ipv4/tcp.c | 2 ++ tools/testing/selftests/arm64/.gitignore | 1 + tools/testing/selftests/arm64/Makefile | 11 ++++++++ .../testing/selftests/arm64/run_tags_test.sh | 12 +++++++++ tools/testing/selftests/arm64/tags_test.c | 19 ++++++++++++++ 25 files changed, 129 insertions(+), 16 deletions(-) create mode 100644 tools/testing/selftests/arm64/.gitignore create mode 100644 tools/testing/selftests/arm64/Makefile create mode 100755 tools/testing/selftests/arm64/run_tags_test.sh create mode 100644 tools/testing/selftests/arm64/tags_test.c
Quoted 6 lines · Andrey Konovalov
The following testing approaches has been taken to find potential issues with user pointer untagging:
1. Static testing (with sparse [3] and separately with a custom static analyzer based on Clang) to track casts of
__userpointers to integer types to find places where untagging needs to be done.
First of all, it's really cool that you took this approach. Sounds like there was a lot of systematic work to fix up the sites in the existing codebase.
But, isn't this a _bit_ fragile going forward? Folks can't just "make sparse" to find issues with missing untags. This seems like something where we would ideally add an __tagged annotation (or something) to the source tree and then have sparse rules that can look for missed untags.
Quoted 9 lines · Dave Hansen
Quoted 6 lines · Andrey Konovalov
The following testing approaches has been taken to find potential issues with user pointer untagging:
1. Static testing (with sparse [3] and separately with a custom static analyzer based on Clang) to track casts of
__userpointers to integer types to find places where untagging needs to be done.
Quoted 6 lines
First of all, it's really cool that you took this approach. Sounds like there was a lot of systematic work to fix up the sites in the existing codebase.
But, isn't this a _bit_ fragile going forward? Folks can't just "make sparse" to find issues with missing untags.
Yes, this static approach can only be used as a hint to find some places where untagging is needed, but certainly not all.
Quoted 3 lines
This seems like something
where we would ideally add an__taggedannotation (or something) to the source tree and then have sparse rules that can look for missed untags.
This has been suggested before, search for __untagged here [1]. However there are many places in the kernel where a __user pointer is casted into unsigned long and passed further. I'm not sure if it's possible apply a __tagged/__untagged kind of attribute to non-pointer types, is it?
Quoted 10 lines · Andrey Konovalov
Quoted 3 lines
This seems like something
where we would ideally add an__taggedannotation (or something) to the source tree and then have sparse rules that can look for missed untags.This has been suggested before, search for
__untaggedhere [1]. However there are many places in the kernel where a__userpointer is casted into unsigned long and passed further. I'm not sure if it's possible apply a __tagged/__untagged kind of attribute to non-pointer types, is it?
I believe we have sparse checking __GFP_* flags. We also have a gfp_t for them and I'm unsure whether the sparse support is tied to _that_ or whether it's just by tagging the type itself as being part of a discrete address space.
Quoted 24 lines · Andrey Konovalov
Quoted 9 lines · Dave Hansen
Quoted 6 lines · Andrey Konovalov
The following testing approaches has been taken to find potential issues with user pointer untagging:
1. Static testing (with sparse [3] and separately with a custom static analyzer based on Clang) to track casts of
__userpointers to integer types to find places where untagging needs to be done.Quoted 6 lines
First of all, it's really cool that you took this approach. Sounds like there was a lot of systematic work to fix up the sites in the existing codebase.
But, isn't this a _bit_ fragile going forward? Folks can't just "make sparse" to find issues with missing untags.
Yes, this static approach can only be used as a hint to find some places where untagging is needed, but certainly not all.
Quoted 3 lines
This seems like something
where we would ideally add an__taggedannotation (or something) to the source tree and then have sparse rules that can look for missed untags.
Quoted 7 lines
This has been suggested before, search for
__untaggedhere [1]. However there are many places in the kernel where a__userpointer is casted into unsigned long and passed further. I'm not sure if it's possible apply a __tagged/__untagged kind of attribute to non-pointer types, is it?
It's something that should need to be added to sparse since it's different from what sparse already have (the existing __bitwise and concept of address-space doesn't seem to do the job here).
-- Luc Van Oostenryck