linux/lib
Yonghong Song 7472d5a642 compiler_types: define __user as __attribute__((btf_type_tag("user")))
The __user attribute is currently mainly used by sparse for type checking.
The attribute indicates whether a memory access is in user memory address
space or not. Such information is important during tracing kernel
internal functions or data structures as accessing user memory often
has different mechanisms compared to accessing kernel memory. For example,
the perf-probe needs explicit command line specification to indicate a
particular argument or string in user-space memory ([1], [2], [3]).
Currently, vmlinux BTF is available in kernel with many distributions.
If __user attribute information is available in vmlinux BTF, the explicit
user memory access information from users will not be necessary as
the kernel can figure it out by itself with vmlinux BTF.

Besides the above possible use for perf/probe, another use case is
for bpf verifier. Currently, for bpf BPF_PROG_TYPE_TRACING type of bpf
programs, users can write direct code like
  p->m1->m2
and "p" could be a function parameter. Without __user information in BTF,
the verifier will assume p->m1 accessing kernel memory and will generate
normal loads. Let us say "p" actually tagged with __user in the source
code.  In such cases, p->m1 is actually accessing user memory and direct
load is not right and may produce incorrect result. For such cases,
bpf_probe_read_user() will be the correct way to read p->m1.

To support encoding __user information in BTF, a new attribute
  __attribute__((btf_type_tag("<arbitrary_string>")))
is implemented in clang ([4]). For example, if we have
  #define __user __attribute__((btf_type_tag("user")))
during kernel compilation, the attribute "user" information will
be preserved in dwarf. After pahole converting dwarf to BTF, __user
information will be available in vmlinux BTF.

The following is an example with latest upstream clang (clang14) and
pahole 1.23:

  [$ ~] cat test.c
  #define __user __attribute__((btf_type_tag("user")))
  int foo(int __user *arg) {
          return *arg;
  }
  [$ ~] clang -O2 -g -c test.c
  [$ ~] pahole -JV test.o
  ...
  [1] INT int size=4 nr_bits=32 encoding=SIGNED
  [2] TYPE_TAG user type_id=1
  [3] PTR (anon) type_id=2
  [4] FUNC_PROTO (anon) return=1 args=(3 arg)
  [5] FUNC foo type_id=4
  [$ ~]

You can see for the function argument "int __user *arg", its type is
described as
  PTR -> TYPE_TAG(user) -> INT
The kernel can use this information for bpf verification or other
use cases.

Current btf_type_tag is only supported in clang (>= clang14) and
pahole (>= 1.23). gcc support is also proposed and under development ([5]).

  [1] http://lkml.kernel.org/r/155789874562.26965.10836126971405890891.stgit@devnote2
  [2] http://lkml.kernel.org/r/155789872187.26965.4468456816590888687.stgit@devnote2
  [3] http://lkml.kernel.org/r/155789871009.26965.14167558859557329331.stgit@devnote2
  [4] https://reviews.llvm.org/D111199
  [5] https://lore.kernel.org/bpf/0cbeb2fb-1a18-f690-e360-24b1c90c2a91@fb.com/

Signed-off-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/r/20220127154600.652613-1-yhs@fb.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
2022-01-27 12:03:46 -08:00
..
842
crypto lib/crypto: blake2s: move hmac construction into wireguard 2022-01-18 13:03:55 +01:00
dim Revert "lib: Revert use of fallthrough pseudo-keyword in lib/" 2020-11-18 14:15:17 -06:00
fonts lib: fix spelling mistakes 2021-07-08 11:48:20 -07:00
kunit Merge branch 'signal-for-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace 2022-01-17 05:49:30 +02:00
livepatch
lz4 include/linux/unaligned: replace kernel.h with the necessary inclusions 2022-01-20 08:52:53 +02:00
lzo lib/lzo/lzo1x_compress.c: make lzogeneric1x_1_compress() static 2020-12-15 22:46:19 -08:00
math math: make RATIONAL tristate 2021-09-08 11:50:26 -07:00
mpi lib/mpi: Add the return value check of kcalloc() 2022-01-07 14:30:01 +11:00
pldmfw lib: fix spelling mistakes 2021-07-08 11:48:20 -07:00
raid6 lib/raid6: Use strict priority ranking for pq gen() benchmarking 2022-01-06 08:37:03 -08:00
reed_solomon lib: fix spelling mistakes 2021-07-08 11:48:20 -07:00
test_fortify fortify: Add compile-time FORTIFY_SOURCE tests 2021-10-18 12:28:52 -07:00
vdso lib/vdso: Add vdso_data pointer as input to __arch_get_timens_vdso_data() 2021-04-14 23:04:44 +10:00
xz lib/xz, lib/decompress_unxz.c: Fix spelling in comments 2021-10-19 23:44:30 +08:00
zlib_deflate
zlib_dfltcc zlib: move EXPORT_SYMBOL() and MODULE_LICENSE() out of dfltcc_syms.c 2020-12-29 15:36:49 -08:00
zlib_inflate lib/zlib_inflate/inffast: check config in C to avoid unused function warning 2021-09-24 16:13:35 -07:00
zstd lib: zstd: Don't add -O3 to cflags 2021-11-18 13:16:22 -08:00
.gitignore fortify: Add compile-time FORTIFY_SOURCE tests 2021-10-18 12:28:52 -07:00
argv_split.c
ashldi3.c
ashrdi3.c
asn1_decoder.c Revert "lib: Revert use of fallthrough pseudo-keyword in lib/" 2020-11-18 14:15:17 -06:00
asn1_encoder.c lib: remove redundant assignment to variable ret 2022-01-20 08:52:55 +02:00
assoc_array.c assoc_array: Avoid open coded arithmetic in allocator arguments 2021-10-13 14:54:13 -05:00
atomic64_test.c
atomic64.c locking/atomic: atomic64: Remove unusable atomic ops 2021-12-13 10:56:09 +01:00
audit.c audit: add support for the openat2 syscall 2021-10-01 16:52:48 -04:00
bcd.c
bch.c lib/bch.c: fix a typo in the file bch.c 2021-05-06 19:24:12 -07:00
bitfield_kunit.c lib: kunit: Fix compilation test when using TEST_BIT_FIELD_COMPILE 2020-10-16 13:25:14 -06:00
bitmap.c lib: bitmap: Introduce node-aware alloc API 2021-10-26 19:30:38 -07:00
bitrev.c
bootconfig.c Merge branch 'akpm' (patches from Andrew) 2021-11-06 14:08:17 -07:00
bsearch.c
btree.c
bucket_locks.c
bug.c bug: Assign values once in bug_get_file_line() 2021-04-01 09:54:37 +01:00
build_OID_registry
buildid.c kdump: use vmlinux_build_id to simplify 2021-07-08 11:48:22 -07:00
bust_spinlocks.c
check_signature.c
checksum.c
clz_ctz.c
clz_tab.c
cmdline_kunit.c lib/cmdline_kunit: Remove a cast which are no-longer required 2021-06-23 16:41:41 -06:00
cmdline.c lib/cmdline: Export next_arg() for being used in modules 2021-05-05 16:07:40 +02:00
cmpdi2.c
compat_audit.c audit: add support for the openat2 syscall 2021-10-01 16:52:48 -04:00
cpu_rmap.c
cpumask.c memblock: use memblock_free for freeing virtual pointers 2021-11-06 13:30:41 -07:00
crc-ccitt.c
crc-itu-t.c
crc-t10dif.c
crc4.c
crc7.c lib/crc7: fix a kernel-doc markup 2021-01-21 14:06:00 -07:00
crc8.c lib: crc8: pointer to data block should be const 2021-05-06 19:24:12 -07:00
crc16.c
crc32.c lib/crc32.c: fix trivial typo in preprocessor condition 2020-10-16 11:11:20 -07:00
crc32defs.h
crc32test.c lib/crc32test: remove extra local_irq_disable/enable 2020-11-02 12:14:19 -08:00
crc64.c lib: crc64: fix kernel-doc warning 2021-06-05 08:58:12 -07:00
ctype.c
debug_info.c isystem: ship and use stdarg.h 2021-08-19 09:02:55 +09:00
debug_locks.c locking/lockdep: Improve noinstr vs errors 2021-06-22 13:56:43 +02:00
debugobjects.c debugobjects: Make them PREEMPT_RT aware 2021-08-13 10:07:44 +02:00
dec_and_lock.c
decompress_bunzip2.c lib/decompressors: fix spelling mistakes 2021-07-01 11:06:05 -07:00
decompress_inflate.c
decompress_unlz4.c lib/decompress_unlz4.c: correctly handle zero-padding around initrds. 2021-07-01 11:06:06 -07:00
decompress_unlzma.c lib: fix inconsistent indenting in process_bit1() 2021-05-06 19:24:12 -07:00
decompress_unlzo.c lib/decompressors: remove set but not used variabled 'level' 2021-07-01 11:06:06 -07:00
decompress_unxz.c lib/xz, lib/decompress_unxz.c: Fix spelling in comments 2021-10-19 23:44:30 +08:00
decompress_unzstd.c lib: zstd: Add decompress_sources.h for decompress_unzstd 2021-11-08 16:55:26 -08:00
decompress.c
devmem_is_allowed.c lib: use PFN_PHYS() in devmem_is_allowed() 2021-08-13 14:09:32 -10:00
devres.c lib: devres: Add managed arch_io_reserve_memtype_wc() 2021-09-23 09:25:59 +02:00
digsig.c crypto: sha - split sha.h into sha1.h and sha2.h 2020-11-20 14:45:33 +11:00
dump_stack.c lib/dump_stack: correct kernel-doc notation 2021-09-08 11:50:26 -07:00
dynamic_debug.c dyndbg: refine verbosity 1-4 summary-detail 2021-10-21 13:01:25 +02:00
dynamic_queue_limits.c lib: dynamic_queue_limits: delete duplicated words + fix typo 2020-10-16 11:11:20 -07:00
earlycpio.c lib: remove "expecting prototype" kernel-doc warnings 2021-04-16 16:10:37 -07:00
errname.c kernel.h: split out mathematical helpers 2020-12-15 22:46:15 -08:00
error-inject.c kprobes: treewide: Replace arch_deref_entry_point() with dereference_symbol_descriptor() 2021-09-30 21:24:06 -04:00
errseq.c kernel.h: split out mathematical helpers 2020-12-15 22:46:15 -08:00
extable.c sparc32: switch to generic extables 2021-01-03 20:05:18 -05:00
fault-inject-usercopy.c lib, include/linux: add usercopy failure capability 2020-10-16 11:11:22 -07:00
fault-inject.c
fdt_addresses.c
fdt_empty_tree.c
fdt_ro.c
fdt_rw.c
fdt_strerror.c
fdt_sw.c
fdt_wip.c
fdt.c
find_bit_benchmark.c
find_bit.c lib: add fast path for find_first_*_bit() and find_last_bit() 2021-05-06 19:24:12 -07:00
flex_proportions.c flex_proportions: Allow N events instead of 1 2021-10-18 07:49:39 -04:00
gen_crc32table.c
gen_crc64table.c
genalloc.c lib/genalloc: add parameter description to fix doc compile warning 2021-05-06 19:24:12 -07:00
generic-radix-tree.c
glob.c Revert "lib: Revert use of fallthrough pseudo-keyword in lib/" 2020-11-18 14:15:17 -06:00
globtest.c
hexdump.c kernel.h: split out min()/max() et al. helpers 2020-10-16 11:11:19 -07:00
hweight.c
idr.c XArray updates for 5.9 2020-10-20 14:39:37 -07:00
inflate.c
interval_tree_test.c
interval_tree.c
iomap_copy.c
iomap.c
iommu-helper.c
iov_iter.c iov_iter: Convert iter_xarray to use folios 2022-01-04 13:15:33 -05:00
irq_poll.c
irq_regs.c
is_single_threaded.c
kasprintf.c isystem: ship and use stdarg.h 2021-08-19 09:02:55 +09:00
Kconfig lib/crypto: add prompts back to crypto libraries 2022-01-18 13:03:55 +01:00
Kconfig.debug compiler_types: define __user as __attribute__((btf_type_tag("user"))) 2022-01-27 12:03:46 -08:00
Kconfig.kasan kasan: fix Kconfig check of CC_HAS_WORKING_NOSANITIZE_ADDRESS 2021-09-24 16:13:34 -07:00
Kconfig.kcsan kcsan: Support WEAK_MEMORY with Clang where no objtool support exists 2021-12-09 16:42:28 -08:00
Kconfig.kfence kfence: default to dynamic branch instead of static keys mode 2021-11-06 13:30:43 -07:00
Kconfig.kgdb kgdb: Honour the kprobe blocklist when setting breakpoints 2020-09-28 12:14:08 +01:00
Kconfig.ubsan ubsan: remove CONFIG_UBSAN_OBJECT_SIZE 2022-01-20 08:52:55 +02:00
kfifo.c lib: fix spelling mistakes 2021-07-08 11:48:20 -07:00
klist.c
kobject_uevent.c kobject: remove kset from struct kset_uevent_ops callbacks 2021-12-28 11:26:18 +01:00
kobject.c driver core: make kobj_type constant. 2021-12-27 10:40:00 +01:00
kstrtox.c kstrtox: uninline everything 2022-01-20 08:52:53 +02:00
kstrtox.h lib: vsprintf: Fix handling of number field widths in vsscanf 2021-05-19 15:05:11 +02:00
libcrc32c.c lib: libcrc32c: delete duplicated words 2020-10-16 11:11:19 -07:00
linear_ranges.c lib: add linear range get selector within 2021-08-13 18:37:38 +02:00
list_debug.c lib/list_debug.c: print more list debugging context in __list_del_entry_valid() 2022-01-20 08:52:53 +02:00
list_sort.c lib: fix spelling mistakes 2021-07-08 11:48:20 -07:00
list-test.c
llist.c
locking-selftest-hardirq.h
locking-selftest-mutex.h
locking-selftest-rlock-hardirq.h
locking-selftest-rlock-softirq.h
locking-selftest-rlock.h
locking-selftest-rsem.h
locking-selftest-rtmutex.h
locking-selftest-softirq.h
locking-selftest-spin-hardirq.h
locking-selftest-spin-softirq.h
locking-selftest-spin.h
locking-selftest-wlock-hardirq.h
locking-selftest-wlock-softirq.h
locking-selftest-wlock.h
locking-selftest-wsem.h
locking-selftest.c lockdep/selftests: Adapt ww-tests for PREEMPT_RT 2021-12-04 10:56:24 +01:00
lockref.c
logic_iomem.c logic_io instance of iounmap() needs volatile on argument 2021-12-21 21:31:08 +01:00
logic_pio.c PCI: Fix pci_register_io_range() memory leak 2021-02-17 17:31:06 -06:00
lru_cache.c lib: remove "expecting prototype" kernel-doc warnings 2021-04-16 16:10:37 -07:00
lshrdi3.c
Makefile Merge branch 'akpm' (patches from Andrew) 2022-01-20 10:41:01 +02:00
memcat_p.c
memcpy_kunit.c string.h: Introduce memset_startat() for wiping trailing members and padding 2021-10-18 12:28:52 -07:00
memory-notifier-error-inject.c
memregion.c lib/memregion.c: include memregion.h 2020-09-26 10:33:57 -07:00
memweight.c
muldi3.c
net_utils.c
netdev-notifier-error-inject.c
nlattr.c lib: fix spelling mistakes 2021-07-08 11:48:20 -07:00
nmi_backtrace.c printk: restore flushing of NMI buffers on remote CPUs after NMI backtraces 2021-11-10 16:12:00 +01:00
nodemask.c
notifier-error-inject.c
notifier-error-inject.h
objagg.c lib: objagg: Use the bitmap API when applicable 2021-12-24 14:54:29 -08:00
of-reconfig-notifier-error-inject.c
oid_registry.c lib: fix spelling mistakes 2021-07-08 11:48:20 -07:00
once.c once: Fix panic when module unload 2021-08-08 13:00:20 +01:00
packing.c net: update NXP copyright text 2021-09-17 13:52:17 +01:00
parman.c lib: remove "expecting prototype" kernel-doc warnings 2021-04-16 16:10:37 -07:00
parser.c kernel.h: split out kstrtox() and simple_strtox() to a separate header 2021-07-01 11:06:05 -07:00
pci_iomap.c pci_iounmap'2: Electric Boogaloo: try to make sense of it all 2021-09-19 17:13:35 -07:00
percpu_counter.c lib/percpu_counter: tame kernel-doc compile warning 2021-05-06 19:24:12 -07:00
percpu_test.c
percpu-refcount.c percpu_ref: Don't opencode percpu_ref_is_dying 2021-05-13 03:27:38 +00:00
plist.c
pm-notifier-error-inject.c
radix-tree.c lib: remove "expecting prototype" kernel-doc warnings 2021-04-16 16:10:37 -07:00
random32.c mm: don't include <linux/blk-cgroup.h> in <linux/writeback.h> 2021-10-18 06:17:01 -06:00
ratelimit.c
rbtree_test.c
rbtree.c
ref_tracker.c ref_tracker: use __GFP_NOFAIL more carefully 2022-01-12 14:29:50 +00:00
refcount.c lib: fix spelling mistakes 2021-07-08 11:48:20 -07:00
rhashtable.c lib: fix spelling mistakes 2021-07-08 11:48:20 -07:00
sbitmap.c sbitmap: silence data race warning 2021-10-25 10:45:01 -06:00
scatterlist.c mm/scatterlist: replace the !preemptible warning in sg_miter_stop() 2021-11-09 10:02:50 -08:00
seq_buf.c lib: fix spelling mistakes 2021-07-08 11:48:20 -07:00
sg_pool.c lib/scatterlist: Fix wrong update of orig_nents 2021-08-24 19:52:40 -03:00
sg_split.c
sha1.c lib/crypto: sha1: re-roll loops to reduce code size 2022-01-18 13:03:55 +01:00
show_mem.c
siphash.c siphash: use _unaligned version by default 2021-11-29 19:50:50 -08:00
slub_kunit.c mm/slub, kunit: add a KUnit test for SLUB debugging functionality 2021-06-29 10:53:46 -07:00
smp_processor_id.c lib/smp_processor_id: Use is_percpu_thread() instead of nr_cpus_allowed 2021-05-19 10:51:40 +02:00
sort.c lib: fix spelling mistakes 2021-07-08 11:48:20 -07:00
stackdepot.c lib, stackdepot: add helper to print stack entries into buffer 2021-11-09 10:02:50 -08:00
stmp_device.c
string_helpers.c lib/string_helpers: Introduce managed variant of kasprintf_strarray() 2021-11-18 18:40:08 +02:00
string.c lib/string: Move helper functions out of string.c 2021-09-25 08:20:49 -07:00
strncpy_from_user.c lib/strncpy_from_user.c: Mask out bytes after NUL terminator. 2020-11-19 11:56:16 -08:00
strnlen_user.c
syscall.c sched: Change task_struct::state 2021-06-18 11:43:09 +02:00
test_bitmap.c lib: test_bitmap: add bitmap_print_bitmask/list_to_buf test cases 2021-08-13 10:27:49 +02:00
test_bitops.c lib/test: fix spelling mistakes 2021-07-08 11:48:20 -07:00
test_bits.c
test_blackhole_dev.c
test_bpf.c bpf: Change value of MAX_TAIL_CALL_CNT from 32 to 33 2021-11-16 14:03:15 +01:00
test_debug_virtual.c
test_firmware.c firmware: replace HOTPLUG with UEVENT in FW_ACTION defines 2021-05-13 16:14:45 +02:00
test_fpu.c selftests/fpu: Fix debugfs_simple_attr.cocci warning 2021-01-18 11:03:26 +01:00
test_free_pages.c lib/test_free_pages.c: add basic progress indicators 2020-12-15 22:46:16 -08:00
test_hash.c test_hash.c: refactor into kunit 2022-01-20 08:52:54 +02:00
test_hexdump.c
test_hmm_uapi.h mm: selftests for exclusive device memory 2021-07-01 11:06:03 -07:00
test_hmm.c mm/hmm.c: allow VM_MIXEDMAP to work with hmm_range_fault 2022-01-15 16:30:31 +02:00
test_ida.c
test_kasan_module.c kasan: test: bypass __alloc_size checks 2021-11-06 13:30:33 -07:00
test_kasan.c kasan: test: add test case for double-kmem_cache_destroy() 2022-01-15 16:30:26 +02:00
test_kmod.c lib/test: fix spelling mistakes 2021-07-08 11:48:20 -07:00
test_kprobes.c test_kprobes: Move it from kernel/ to lib/ 2021-10-26 17:23:46 -04:00
test_linear_ranges.c
test_list_sort.c lib/test: convert lib/test_list_sort.c to use KUnit 2021-06-25 11:31:03 -06:00
test_lockup.c lib/test_lockup: Adapt to changed variables 2021-08-17 19:05:33 +02:00
test_memcat_p.c
test_meminit.c lib/test_meminit: destroy cache in kmem_cache_alloc_bulk() test 2022-01-20 08:52:54 +02:00
test_min_heap.c
test_module.c
test_objagg.c
test_overflow.c
test_parman.c
test_printf.c vsprintf: Make %pGp print the hex value 2021-10-27 13:40:14 +02:00
test_ref_tracker.c lib: add tests for reference tracker 2021-12-06 16:04:44 -08:00
test_rhashtable.c rhashtable: avoid -Wrestrict warning on overlapping sprintf output 2021-03-24 15:16:09 -07:00
test_scanf.c lib/test_scanf: split up number parsing test routines 2021-09-06 11:04:03 -07:00
test_siphash.c
test_sort.c lib/test: convert test_sort.c to use KUnit 2021-09-08 11:50:26 -07:00
test_stackinit.c lib/test_stackinit: Add assigned initializers 2021-08-22 00:21:36 -07:00
test_static_key_base.c
test_static_keys.c
test_string.c lib/test_string.c: allow module removal 2021-07-01 11:06:05 -07:00
test_strscpy.c
test_sysctl.c lib: test_sysctl: delete duplicated words 2020-10-16 11:11:20 -07:00
test_ubsan.c ubsan: remove CONFIG_UBSAN_OBJECT_SIZE 2022-01-20 08:52:55 +02:00
test_user_copy.c
test_uuid.c
test_vmalloc.c lib/test_vmalloc.c: use swap() to make code cleaner 2021-11-06 13:30:37 -07:00
test_xarray.c XArray: Fix splitting to non-zero orders 2021-03-30 13:42:33 -04:00
test-kstrtox.c
test-string_helpers.c string_helpers: Escape double quotes in escape_special 2021-07-19 11:39:28 +02:00
textsearch.c
timerqueue.c rbtree, timerqueue: Use rb_add_cached() 2021-02-17 14:08:01 +01:00
ts_bm.c
ts_fsm.c Revert "lib: Revert use of fallthrough pseudo-keyword in lib/" 2020-11-18 14:15:17 -06:00
ts_kmp.c
ubsan.c kunit: ubsan integration 2021-08-13 13:19:06 -06:00
ubsan.h ubsan: implement __ubsan_handle_alignment_assumption 2021-02-05 11:03:47 -08:00
ucmpdi2.c
ucs2_string.c
usercopy.c lib, uaccess: add failure injection to usercopy functions 2020-10-16 11:11:22 -07:00
uuid.c
vsprintf.c vsprintf: Use non-atomic bitmap API when applicable 2021-12-06 13:35:28 +01:00
win_minmax.c
xarray.c XArray: Add xas_advance() 2022-01-08 00:28:41 -05:00
xxhash.c