[arm64:devel/btrfs-live-lock-fix 1/4] kernel/trace/bpf_trace.c:164:12: error: static declaration of 'bpf_probe_read_user' follows non-static declaration
kernel test robot
lkp at intel.com
Fri Nov 26 20:45:33 PST 2021
tree: https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git devel/btrfs-live-lock-fix
head: eade0a26bad9d83117f472f6eebd84b90cef0dae
commit: 25237b79a183c4501485f6d3375e03e2d82c062c [1/4] uaccess: Return bytes not copied in copy_{to,from}_user_nofault()
config: mips-allmodconfig (https://download.01.org/0day-ci/archive/20211127/202111271227.vVg9OeUo-lkp@intel.com/config)
compiler: mips-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git/commit/?id=25237b79a183c4501485f6d3375e03e2d82c062c
git remote add arm64 https://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git
git fetch --no-tags arm64 devel/btrfs-live-lock-fix
git checkout 25237b79a183c4501485f6d3375e03e2d82c062c
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=mips SHELL=/bin/bash kernel/trace/
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp at intel.com>
All error/warnings (new ones prefixed by >>):
In file included from kernel/trace/bpf_trace.c:11:
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_user_common':
>> include/linux/filter.h:500:13: error: invalid storage class for function '____bpf_probe_read_user'
500 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__)); \
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:164:1: note: in expansion of macro 'BPF_CALL_3'
164 | BPF_CALL_3(bpf_probe_read_user, void *, dst, u32, size,
| ^~~~~~~~~~
>> include/linux/filter.h:499:9: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
499 | static __always_inline \
| ^~~~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:164:1: note: in expansion of macro 'BPF_CALL_3'
164 | BPF_CALL_3(bpf_probe_read_user, void *, dst, u32, size,
| ^~~~~~~~~~
>> kernel/trace/bpf_trace.c:164:12: error: static declaration of 'bpf_probe_read_user' follows non-static declaration
164 | BPF_CALL_3(bpf_probe_read_user, void *, dst, u32, size,
| ^~~~~~~~~~~~~~~~~~~
include/linux/filter.h:503:13: note: in definition of macro 'BPF_CALL_x'
503 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)) \
| ^~~~
kernel/trace/bpf_trace.c:164:1: note: in expansion of macro 'BPF_CALL_3'
164 | BPF_CALL_3(bpf_probe_read_user, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:164:12: note: previous declaration of 'bpf_probe_read_user' with type 'u64(u64, u64, u64, u64, u64)' {aka 'long long unsigned int(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'}
164 | BPF_CALL_3(bpf_probe_read_user, void *, dst, u32, size,
| ^~~~~~~~~~~~~~~~~~~
include/linux/filter.h:502:13: note: in definition of macro 'BPF_CALL_x'
502 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)); \
| ^~~~
kernel/trace/bpf_trace.c:164:1: note: in expansion of macro 'BPF_CALL_3'
164 | BPF_CALL_3(bpf_probe_read_user, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_user':
>> include/linux/filter.h:505:37: error: '____bpf_probe_read_user' undeclared (first use in this function); did you mean 'btf_bpf_probe_read_user'?
505 | return ((btf_##name)____##name)(__BPF_MAP(x,__BPF_CAST,__BPF_N,__VA_ARGS__));\
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:164:1: note: in expansion of macro 'BPF_CALL_3'
164 | BPF_CALL_3(bpf_probe_read_user, void *, dst, u32, size,
| ^~~~~~~~~~
include/linux/filter.h:505:37: note: each undeclared identifier is reported only once for each function it appears in
505 | return ((btf_##name)____##name)(__BPF_MAP(x,__BPF_CAST,__BPF_N,__VA_ARGS__));\
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:164:1: note: in expansion of macro 'BPF_CALL_3'
164 | BPF_CALL_3(bpf_probe_read_user, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_user_common':
include/linux/filter.h:508:13: error: invalid storage class for function '____bpf_probe_read_user'
508 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__))
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:164:1: note: in expansion of macro 'BPF_CALL_3'
164 | BPF_CALL_3(bpf_probe_read_user, void *, dst, u32, size,
| ^~~~~~~~~~
>> kernel/trace/bpf_trace.c:180:1: error: invalid storage class for function 'bpf_probe_read_user_str_common'
180 | bpf_probe_read_user_str_common(void *dst, u32 size,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from kernel/trace/bpf_trace.c:11:
>> include/linux/filter.h:500:13: error: invalid storage class for function '____bpf_probe_read_user_str'
500 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__)); \
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:201:1: note: in expansion of macro 'BPF_CALL_3'
201 | BPF_CALL_3(bpf_probe_read_user_str, void *, dst, u32, size,
| ^~~~~~~~~~
>> kernel/trace/bpf_trace.c:201:12: error: static declaration of 'bpf_probe_read_user_str' follows non-static declaration
201 | BPF_CALL_3(bpf_probe_read_user_str, void *, dst, u32, size,
| ^~~~~~~~~~~~~~~~~~~~~~~
include/linux/filter.h:503:13: note: in definition of macro 'BPF_CALL_x'
503 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)) \
| ^~~~
kernel/trace/bpf_trace.c:201:1: note: in expansion of macro 'BPF_CALL_3'
201 | BPF_CALL_3(bpf_probe_read_user_str, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:201:12: note: previous declaration of 'bpf_probe_read_user_str' with type 'u64(u64, u64, u64, u64, u64)' {aka 'long long unsigned int(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'}
201 | BPF_CALL_3(bpf_probe_read_user_str, void *, dst, u32, size,
| ^~~~~~~~~~~~~~~~~~~~~~~
include/linux/filter.h:502:13: note: in definition of macro 'BPF_CALL_x'
502 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)); \
| ^~~~
kernel/trace/bpf_trace.c:201:1: note: in expansion of macro 'BPF_CALL_3'
201 | BPF_CALL_3(bpf_probe_read_user_str, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_user_str':
>> include/linux/filter.h:505:37: error: '____bpf_probe_read_user_str' undeclared (first use in this function); did you mean 'btf_bpf_probe_read_user_str'?
505 | return ((btf_##name)____##name)(__BPF_MAP(x,__BPF_CAST,__BPF_N,__VA_ARGS__));\
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:201:1: note: in expansion of macro 'BPF_CALL_3'
201 | BPF_CALL_3(bpf_probe_read_user_str, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_user_common':
include/linux/filter.h:508:13: error: invalid storage class for function '____bpf_probe_read_user_str'
508 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__))
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:201:1: note: in expansion of macro 'BPF_CALL_3'
201 | BPF_CALL_3(bpf_probe_read_user_str, void *, dst, u32, size,
| ^~~~~~~~~~
>> kernel/trace/bpf_trace.c:217:1: error: invalid storage class for function 'bpf_probe_read_kernel_common'
217 | bpf_probe_read_kernel_common(void *dst, u32 size, const void *unsafe_ptr)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from kernel/trace/bpf_trace.c:11:
>> include/linux/filter.h:500:13: error: invalid storage class for function '____bpf_probe_read_kernel'
500 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__)); \
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:227:1: note: in expansion of macro 'BPF_CALL_3'
227 | BPF_CALL_3(bpf_probe_read_kernel, void *, dst, u32, size,
| ^~~~~~~~~~
>> kernel/trace/bpf_trace.c:227:12: error: static declaration of 'bpf_probe_read_kernel' follows non-static declaration
227 | BPF_CALL_3(bpf_probe_read_kernel, void *, dst, u32, size,
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/filter.h:503:13: note: in definition of macro 'BPF_CALL_x'
503 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)) \
| ^~~~
kernel/trace/bpf_trace.c:227:1: note: in expansion of macro 'BPF_CALL_3'
227 | BPF_CALL_3(bpf_probe_read_kernel, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:227:12: note: previous declaration of 'bpf_probe_read_kernel' with type 'u64(u64, u64, u64, u64, u64)' {aka 'long long unsigned int(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'}
227 | BPF_CALL_3(bpf_probe_read_kernel, void *, dst, u32, size,
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/filter.h:502:13: note: in definition of macro 'BPF_CALL_x'
502 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)); \
| ^~~~
kernel/trace/bpf_trace.c:227:1: note: in expansion of macro 'BPF_CALL_3'
227 | BPF_CALL_3(bpf_probe_read_kernel, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_kernel':
>> include/linux/filter.h:505:37: error: '____bpf_probe_read_kernel' undeclared (first use in this function); did you mean 'btf_bpf_probe_read_kernel'?
505 | return ((btf_##name)____##name)(__BPF_MAP(x,__BPF_CAST,__BPF_N,__VA_ARGS__));\
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:227:1: note: in expansion of macro 'BPF_CALL_3'
227 | BPF_CALL_3(bpf_probe_read_kernel, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_user_common':
include/linux/filter.h:508:13: error: invalid storage class for function '____bpf_probe_read_kernel'
508 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__))
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:227:1: note: in expansion of macro 'BPF_CALL_3'
227 | BPF_CALL_3(bpf_probe_read_kernel, void *, dst, u32, size,
| ^~~~~~~~~~
>> kernel/trace/bpf_trace.c:243:1: error: invalid storage class for function 'bpf_probe_read_kernel_str_common'
243 | bpf_probe_read_kernel_str_common(void *dst, u32 size, const void *unsafe_ptr)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from kernel/trace/bpf_trace.c:11:
>> include/linux/filter.h:500:13: error: invalid storage class for function '____bpf_probe_read_kernel_str'
500 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__)); \
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:262:1: note: in expansion of macro 'BPF_CALL_3'
262 | BPF_CALL_3(bpf_probe_read_kernel_str, void *, dst, u32, size,
| ^~~~~~~~~~
>> kernel/trace/bpf_trace.c:262:12: error: static declaration of 'bpf_probe_read_kernel_str' follows non-static declaration
262 | BPF_CALL_3(bpf_probe_read_kernel_str, void *, dst, u32, size,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/filter.h:503:13: note: in definition of macro 'BPF_CALL_x'
503 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)) \
| ^~~~
kernel/trace/bpf_trace.c:262:1: note: in expansion of macro 'BPF_CALL_3'
262 | BPF_CALL_3(bpf_probe_read_kernel_str, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:262:12: note: previous declaration of 'bpf_probe_read_kernel_str' with type 'u64(u64, u64, u64, u64, u64)' {aka 'long long unsigned int(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'}
262 | BPF_CALL_3(bpf_probe_read_kernel_str, void *, dst, u32, size,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/filter.h:502:13: note: in definition of macro 'BPF_CALL_x'
502 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)); \
| ^~~~
kernel/trace/bpf_trace.c:262:1: note: in expansion of macro 'BPF_CALL_3'
262 | BPF_CALL_3(bpf_probe_read_kernel_str, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_kernel_str':
>> include/linux/filter.h:505:37: error: '____bpf_probe_read_kernel_str' undeclared (first use in this function); did you mean 'btf_bpf_probe_read_kernel_str'?
505 | return ((btf_##name)____##name)(__BPF_MAP(x,__BPF_CAST,__BPF_N,__VA_ARGS__));\
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:262:1: note: in expansion of macro 'BPF_CALL_3'
262 | BPF_CALL_3(bpf_probe_read_kernel_str, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_user_common':
include/linux/filter.h:508:13: error: invalid storage class for function '____bpf_probe_read_kernel_str'
508 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__))
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:262:1: note: in expansion of macro 'BPF_CALL_3'
262 | BPF_CALL_3(bpf_probe_read_kernel_str, void *, dst, u32, size,
| ^~~~~~~~~~
>> include/linux/filter.h:500:13: error: invalid storage class for function '____bpf_probe_read_compat'
500 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__)); \
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:278:1: note: in expansion of macro 'BPF_CALL_3'
278 | BPF_CALL_3(bpf_probe_read_compat, void *, dst, u32, size,
| ^~~~~~~~~~
>> kernel/trace/bpf_trace.c:278:12: error: static declaration of 'bpf_probe_read_compat' follows non-static declaration
278 | BPF_CALL_3(bpf_probe_read_compat, void *, dst, u32, size,
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/filter.h:503:13: note: in definition of macro 'BPF_CALL_x'
503 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)) \
| ^~~~
kernel/trace/bpf_trace.c:278:1: note: in expansion of macro 'BPF_CALL_3'
278 | BPF_CALL_3(bpf_probe_read_compat, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:278:12: note: previous declaration of 'bpf_probe_read_compat' with type 'u64(u64, u64, u64, u64, u64)' {aka 'long long unsigned int(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'}
278 | BPF_CALL_3(bpf_probe_read_compat, void *, dst, u32, size,
| ^~~~~~~~~~~~~~~~~~~~~
include/linux/filter.h:502:13: note: in definition of macro 'BPF_CALL_x'
502 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)); \
| ^~~~
kernel/trace/bpf_trace.c:278:1: note: in expansion of macro 'BPF_CALL_3'
278 | BPF_CALL_3(bpf_probe_read_compat, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_compat':
>> include/linux/filter.h:505:37: error: '____bpf_probe_read_compat' undeclared (first use in this function); did you mean 'btf_bpf_probe_read_compat'?
505 | return ((btf_##name)____##name)(__BPF_MAP(x,__BPF_CAST,__BPF_N,__VA_ARGS__));\
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:278:1: note: in expansion of macro 'BPF_CALL_3'
278 | BPF_CALL_3(bpf_probe_read_compat, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_user_common':
include/linux/filter.h:508:13: error: invalid storage class for function '____bpf_probe_read_compat'
508 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__))
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:278:1: note: in expansion of macro 'BPF_CALL_3'
278 | BPF_CALL_3(bpf_probe_read_compat, void *, dst, u32, size,
| ^~~~~~~~~~
>> kernel/trace/bpf_trace.c:289:27: error: initializer element is not constant
289 | .func = bpf_probe_read_compat,
| ^~~~~~~~~~~~~~~~~~~~~
kernel/trace/bpf_trace.c:289:27: note: (near initialization for 'bpf_probe_read_compat_proto.func')
In file included from kernel/trace/bpf_trace.c:11:
include/linux/filter.h:500:13: error: invalid storage class for function '____bpf_probe_read_compat_str'
500 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__)); \
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:297:1: note: in expansion of macro 'BPF_CALL_3'
297 | BPF_CALL_3(bpf_probe_read_compat_str, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:297:12: error: static declaration of 'bpf_probe_read_compat_str' follows non-static declaration
297 | BPF_CALL_3(bpf_probe_read_compat_str, void *, dst, u32, size,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/filter.h:503:13: note: in definition of macro 'BPF_CALL_x'
503 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)) \
| ^~~~
kernel/trace/bpf_trace.c:297:1: note: in expansion of macro 'BPF_CALL_3'
297 | BPF_CALL_3(bpf_probe_read_compat_str, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:297:12: note: previous declaration of 'bpf_probe_read_compat_str' with type 'u64(u64, u64, u64, u64, u64)' {aka 'long long unsigned int(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'}
297 | BPF_CALL_3(bpf_probe_read_compat_str, void *, dst, u32, size,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
include/linux/filter.h:502:13: note: in definition of macro 'BPF_CALL_x'
502 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)); \
| ^~~~
kernel/trace/bpf_trace.c:297:1: note: in expansion of macro 'BPF_CALL_3'
297 | BPF_CALL_3(bpf_probe_read_compat_str, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_compat_str':
include/linux/filter.h:505:37: error: '____bpf_probe_read_compat_str' undeclared (first use in this function); did you mean 'btf_bpf_probe_read_compat_str'?
505 | return ((btf_##name)____##name)(__BPF_MAP(x,__BPF_CAST,__BPF_N,__VA_ARGS__));\
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:297:1: note: in expansion of macro 'BPF_CALL_3'
297 | BPF_CALL_3(bpf_probe_read_compat_str, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_user_common':
include/linux/filter.h:508:13: error: invalid storage class for function '____bpf_probe_read_compat_str'
508 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__))
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:297:1: note: in expansion of macro 'BPF_CALL_3'
297 | BPF_CALL_3(bpf_probe_read_compat_str, void *, dst, u32, size,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:308:27: error: initializer element is not constant
308 | .func = bpf_probe_read_compat_str,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
kernel/trace/bpf_trace.c:308:27: note: (near initialization for 'bpf_probe_read_compat_str_proto.func')
In file included from kernel/trace/bpf_trace.c:11:
include/linux/filter.h:500:13: error: invalid storage class for function '____bpf_probe_write_user'
500 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__)); \
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:317:1: note: in expansion of macro 'BPF_CALL_3'
317 | BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:317:12: error: static declaration of 'bpf_probe_write_user' follows non-static declaration
317 | BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src,
| ^~~~~~~~~~~~~~~~~~~~
include/linux/filter.h:503:13: note: in definition of macro 'BPF_CALL_x'
503 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)) \
| ^~~~
kernel/trace/bpf_trace.c:317:1: note: in expansion of macro 'BPF_CALL_3'
317 | BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:317:12: note: previous declaration of 'bpf_probe_write_user' with type 'u64(u64, u64, u64, u64, u64)' {aka 'long long unsigned int(long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int, long long unsigned int)'}
317 | BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src,
| ^~~~~~~~~~~~~~~~~~~~
include/linux/filter.h:502:13: note: in definition of macro 'BPF_CALL_x'
502 | u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)); \
| ^~~~
kernel/trace/bpf_trace.c:317:1: note: in expansion of macro 'BPF_CALL_3'
317 | BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_write_user':
include/linux/filter.h:505:37: error: '____bpf_probe_write_user' undeclared (first use in this function); did you mean 'btf_bpf_probe_write_user'?
505 | return ((btf_##name)____##name)(__BPF_MAP(x,__BPF_CAST,__BPF_N,__VA_ARGS__));\
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
kernel/trace/bpf_trace.c:317:1: note: in expansion of macro 'BPF_CALL_3'
317 | BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src,
| ^~~~~~~~~~
kernel/trace/bpf_trace.c: In function 'bpf_probe_read_user_common':
include/linux/filter.h:508:13: error: invalid storage class for function '____bpf_probe_write_user'
508 | u64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__))
| ^~~~
include/linux/filter.h:513:33: note: in expansion of macro 'BPF_CALL_x'
513 | #define BPF_CALL_3(name, ...) BPF_CALL_x(3, name, __VA_ARGS__)
| ^~~~~~~~~~
vim +/bpf_probe_read_user +164 kernel/trace/bpf_trace.c
035226b964c820 Gianluca Borello 2017-10-26 76
eb411377aed9e2 Alan Maguire 2020-09-28 @77 static int bpf_btf_printf_prepare(struct btf_ptr *ptr, u32 btf_ptr_size,
eb411377aed9e2 Alan Maguire 2020-09-28 78 u64 flags, const struct btf **btf,
eb411377aed9e2 Alan Maguire 2020-09-28 79 s32 *btf_id);
eb411377aed9e2 Alan Maguire 2020-09-28 80
2541517c32be25 Alexei Starovoitov 2015-03-25 81 /**
2541517c32be25 Alexei Starovoitov 2015-03-25 82 * trace_call_bpf - invoke BPF program
e87c6bc3852b98 Yonghong Song 2017-10-23 83 * @call: tracepoint event
2541517c32be25 Alexei Starovoitov 2015-03-25 84 * @ctx: opaque context pointer
2541517c32be25 Alexei Starovoitov 2015-03-25 85 *
2541517c32be25 Alexei Starovoitov 2015-03-25 86 * kprobe handlers execute BPF programs via this helper.
2541517c32be25 Alexei Starovoitov 2015-03-25 87 * Can be used from static tracepoints in the future.
2541517c32be25 Alexei Starovoitov 2015-03-25 88 *
2541517c32be25 Alexei Starovoitov 2015-03-25 89 * Return: BPF programs always return an integer which is interpreted by
2541517c32be25 Alexei Starovoitov 2015-03-25 90 * kprobe handler as:
2541517c32be25 Alexei Starovoitov 2015-03-25 91 * 0 - return from kprobe (event is filtered out)
2541517c32be25 Alexei Starovoitov 2015-03-25 92 * 1 - store kprobe event into ring buffer
2541517c32be25 Alexei Starovoitov 2015-03-25 93 * Other values are reserved and currently alias to 1
2541517c32be25 Alexei Starovoitov 2015-03-25 94 */
e87c6bc3852b98 Yonghong Song 2017-10-23 95 unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
2541517c32be25 Alexei Starovoitov 2015-03-25 96 {
2541517c32be25 Alexei Starovoitov 2015-03-25 97 unsigned int ret;
2541517c32be25 Alexei Starovoitov 2015-03-25 98
b0a81b94cc50a1 Thomas Gleixner 2020-02-24 99 cant_sleep();
2541517c32be25 Alexei Starovoitov 2015-03-25 100
2541517c32be25 Alexei Starovoitov 2015-03-25 101 if (unlikely(__this_cpu_inc_return(bpf_prog_active) != 1)) {
2541517c32be25 Alexei Starovoitov 2015-03-25 102 /*
2541517c32be25 Alexei Starovoitov 2015-03-25 103 * since some bpf program is already running on this cpu,
2541517c32be25 Alexei Starovoitov 2015-03-25 104 * don't call into another bpf program (same or different)
2541517c32be25 Alexei Starovoitov 2015-03-25 105 * and don't send kprobe event into ring-buffer,
2541517c32be25 Alexei Starovoitov 2015-03-25 106 * so return zero here
2541517c32be25 Alexei Starovoitov 2015-03-25 107 */
2541517c32be25 Alexei Starovoitov 2015-03-25 108 ret = 0;
2541517c32be25 Alexei Starovoitov 2015-03-25 109 goto out;
2541517c32be25 Alexei Starovoitov 2015-03-25 110 }
2541517c32be25 Alexei Starovoitov 2015-03-25 111
e87c6bc3852b98 Yonghong Song 2017-10-23 112 /*
e87c6bc3852b98 Yonghong Song 2017-10-23 113 * Instead of moving rcu_read_lock/rcu_dereference/rcu_read_unlock
e87c6bc3852b98 Yonghong Song 2017-10-23 114 * to all call sites, we did a bpf_prog_array_valid() there to check
e87c6bc3852b98 Yonghong Song 2017-10-23 115 * whether call->prog_array is empty or not, which is
2b5894cc33e9de Qiujun Huang 2020-10-29 116 * a heuristic to speed up execution.
e87c6bc3852b98 Yonghong Song 2017-10-23 117 *
e87c6bc3852b98 Yonghong Song 2017-10-23 118 * If bpf_prog_array_valid() fetched prog_array was
e87c6bc3852b98 Yonghong Song 2017-10-23 119 * non-NULL, we go into trace_call_bpf() and do the actual
e87c6bc3852b98 Yonghong Song 2017-10-23 120 * proper rcu_dereference() under RCU lock.
e87c6bc3852b98 Yonghong Song 2017-10-23 121 * If it turns out that prog_array is NULL then, we bail out.
e87c6bc3852b98 Yonghong Song 2017-10-23 122 * For the opposite, if the bpf_prog_array_valid() fetched pointer
e87c6bc3852b98 Yonghong Song 2017-10-23 123 * was NULL, you'll skip the prog_array with the risk of missing
e87c6bc3852b98 Yonghong Song 2017-10-23 124 * out of events when it was updated in between this and the
e87c6bc3852b98 Yonghong Song 2017-10-23 125 * rcu_dereference() which is accepted risk.
e87c6bc3852b98 Yonghong Song 2017-10-23 126 */
7d08c2c9117113 Andrii Nakryiko 2021-08-15 127 ret = BPF_PROG_RUN_ARRAY(call->prog_array, ctx, bpf_prog_run);
2541517c32be25 Alexei Starovoitov 2015-03-25 128
2541517c32be25 Alexei Starovoitov 2015-03-25 129 out:
2541517c32be25 Alexei Starovoitov 2015-03-25 130 __this_cpu_dec(bpf_prog_active);
2541517c32be25 Alexei Starovoitov 2015-03-25 131
2541517c32be25 Alexei Starovoitov 2015-03-25 132 return ret;
2541517c32be25 Alexei Starovoitov 2015-03-25 133 }
2541517c32be25 Alexei Starovoitov 2015-03-25 134
9802d86585db91 Josef Bacik 2017-12-11 135 #ifdef CONFIG_BPF_KPROBE_OVERRIDE
9802d86585db91 Josef Bacik 2017-12-11 136 BPF_CALL_2(bpf_override_return, struct pt_regs *, regs, unsigned long, rc)
9802d86585db91 Josef Bacik 2017-12-11 137 {
9802d86585db91 Josef Bacik 2017-12-11 138 regs_set_return_value(regs, rc);
540adea3809f61 Masami Hiramatsu 2018-01-13 139 override_function_with_return(regs);
9802d86585db91 Josef Bacik 2017-12-11 140 return 0;
9802d86585db91 Josef Bacik 2017-12-11 141 }
9802d86585db91 Josef Bacik 2017-12-11 142
9802d86585db91 Josef Bacik 2017-12-11 143 static const struct bpf_func_proto bpf_override_return_proto = {
9802d86585db91 Josef Bacik 2017-12-11 144 .func = bpf_override_return,
9802d86585db91 Josef Bacik 2017-12-11 145 .gpl_only = true,
9802d86585db91 Josef Bacik 2017-12-11 146 .ret_type = RET_INTEGER,
9802d86585db91 Josef Bacik 2017-12-11 147 .arg1_type = ARG_PTR_TO_CTX,
9802d86585db91 Josef Bacik 2017-12-11 148 .arg2_type = ARG_ANYTHING,
9802d86585db91 Josef Bacik 2017-12-11 149 };
9802d86585db91 Josef Bacik 2017-12-11 150 #endif
9802d86585db91 Josef Bacik 2017-12-11 151
8d92db5c04d103 Christoph Hellwig 2020-06-08 152 static __always_inline int
8d92db5c04d103 Christoph Hellwig 2020-06-08 153 bpf_probe_read_user_common(void *dst, u32 size, const void __user *unsafe_ptr)
2541517c32be25 Alexei Starovoitov 2015-03-25 154 {
8d92db5c04d103 Christoph Hellwig 2020-06-08 155 int ret;
2541517c32be25 Alexei Starovoitov 2015-03-25 156
c0ee37e85e0e47 Christoph Hellwig 2020-06-17 157 ret = copy_from_user_nofault(dst, unsafe_ptr, size);
25237b79a183c4 Catalin Marinas 2021-11-26 158 if (unlikely(ret)) {
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 159 memset(dst, 0, size);
25237b79a183c4 Catalin Marinas 2021-11-26 160 return -EFAULT;
25237b79a183c4 Catalin Marinas 2021-11-26 161 return 0;
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 162 }
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 163
8d92db5c04d103 Christoph Hellwig 2020-06-08 @164 BPF_CALL_3(bpf_probe_read_user, void *, dst, u32, size,
8d92db5c04d103 Christoph Hellwig 2020-06-08 165 const void __user *, unsafe_ptr)
8d92db5c04d103 Christoph Hellwig 2020-06-08 166 {
8d92db5c04d103 Christoph Hellwig 2020-06-08 167 return bpf_probe_read_user_common(dst, size, unsafe_ptr);
8d92db5c04d103 Christoph Hellwig 2020-06-08 168 }
8d92db5c04d103 Christoph Hellwig 2020-06-08 169
f470378c7562a2 John Fastabend 2020-05-24 170 const struct bpf_func_proto bpf_probe_read_user_proto = {
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 171 .func = bpf_probe_read_user,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 172 .gpl_only = true,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 173 .ret_type = RET_INTEGER,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 174 .arg1_type = ARG_PTR_TO_UNINIT_MEM,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 175 .arg2_type = ARG_CONST_SIZE_OR_ZERO,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 176 .arg3_type = ARG_ANYTHING,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 177 };
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 178
8d92db5c04d103 Christoph Hellwig 2020-06-08 179 static __always_inline int
8d92db5c04d103 Christoph Hellwig 2020-06-08 @180 bpf_probe_read_user_str_common(void *dst, u32 size,
8d92db5c04d103 Christoph Hellwig 2020-06-08 181 const void __user *unsafe_ptr)
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 182 {
8d92db5c04d103 Christoph Hellwig 2020-06-08 183 int ret;
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 184
6fa6d28051e9fc Daniel Xu 2020-11-17 185 /*
6fa6d28051e9fc Daniel Xu 2020-11-17 186 * NB: We rely on strncpy_from_user() not copying junk past the NUL
6fa6d28051e9fc Daniel Xu 2020-11-17 187 * terminator into `dst`.
6fa6d28051e9fc Daniel Xu 2020-11-17 188 *
6fa6d28051e9fc Daniel Xu 2020-11-17 189 * strncpy_from_user() does long-sized strides in the fast path. If the
6fa6d28051e9fc Daniel Xu 2020-11-17 190 * strncpy does not mask out the bytes after the NUL in `unsafe_ptr`,
6fa6d28051e9fc Daniel Xu 2020-11-17 191 * then there could be junk after the NUL in `dst`. If user takes `dst`
6fa6d28051e9fc Daniel Xu 2020-11-17 192 * and keys a hash map with it, then semantically identical strings can
6fa6d28051e9fc Daniel Xu 2020-11-17 193 * occupy multiple entries in the map.
6fa6d28051e9fc Daniel Xu 2020-11-17 194 */
8d92db5c04d103 Christoph Hellwig 2020-06-08 195 ret = strncpy_from_user_nofault(dst, unsafe_ptr, size);
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 196 if (unlikely(ret < 0))
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 197 memset(dst, 0, size);
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 198 return ret;
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 199 }
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 200
8d92db5c04d103 Christoph Hellwig 2020-06-08 @201 BPF_CALL_3(bpf_probe_read_user_str, void *, dst, u32, size,
8d92db5c04d103 Christoph Hellwig 2020-06-08 202 const void __user *, unsafe_ptr)
8d92db5c04d103 Christoph Hellwig 2020-06-08 203 {
8d92db5c04d103 Christoph Hellwig 2020-06-08 204 return bpf_probe_read_user_str_common(dst, size, unsafe_ptr);
8d92db5c04d103 Christoph Hellwig 2020-06-08 205 }
8d92db5c04d103 Christoph Hellwig 2020-06-08 206
f470378c7562a2 John Fastabend 2020-05-24 207 const struct bpf_func_proto bpf_probe_read_user_str_proto = {
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 208 .func = bpf_probe_read_user_str,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 209 .gpl_only = true,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 210 .ret_type = RET_INTEGER,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 211 .arg1_type = ARG_PTR_TO_UNINIT_MEM,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 212 .arg2_type = ARG_CONST_SIZE_OR_ZERO,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 213 .arg3_type = ARG_ANYTHING,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 214 };
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 215
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 216 static __always_inline int
8d92db5c04d103 Christoph Hellwig 2020-06-08 @217 bpf_probe_read_kernel_common(void *dst, u32 size, const void *unsafe_ptr)
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 218 {
ff40e51043af63 Daniel Borkmann 2021-05-28 219 int ret;
9d1f8be5cf42b4 David Howells 2019-08-19 220
fe557319aa06c2 Christoph Hellwig 2020-06-17 221 ret = copy_from_kernel_nofault(dst, unsafe_ptr, size);
074f528eed408b Daniel Borkmann 2016-04-13 222 if (unlikely(ret < 0))
074f528eed408b Daniel Borkmann 2016-04-13 223 memset(dst, 0, size);
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 224 return ret;
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 225 }
074f528eed408b Daniel Borkmann 2016-04-13 226
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 @227 BPF_CALL_3(bpf_probe_read_kernel, void *, dst, u32, size,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 228 const void *, unsafe_ptr)
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 229 {
8d92db5c04d103 Christoph Hellwig 2020-06-08 230 return bpf_probe_read_kernel_common(dst, size, unsafe_ptr);
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 231 }
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 232
f470378c7562a2 John Fastabend 2020-05-24 233 const struct bpf_func_proto bpf_probe_read_kernel_proto = {
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 234 .func = bpf_probe_read_kernel,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 235 .gpl_only = true,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 236 .ret_type = RET_INTEGER,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 237 .arg1_type = ARG_PTR_TO_UNINIT_MEM,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 238 .arg2_type = ARG_CONST_SIZE_OR_ZERO,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 239 .arg3_type = ARG_ANYTHING,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 240 };
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 241
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 242 static __always_inline int
8d92db5c04d103 Christoph Hellwig 2020-06-08 @243 bpf_probe_read_kernel_str_common(void *dst, u32 size, const void *unsafe_ptr)
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 244 {
ff40e51043af63 Daniel Borkmann 2021-05-28 245 int ret;
8d92db5c04d103 Christoph Hellwig 2020-06-08 246
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 247 /*
8d92db5c04d103 Christoph Hellwig 2020-06-08 248 * The strncpy_from_kernel_nofault() call will likely not fill the
8d92db5c04d103 Christoph Hellwig 2020-06-08 249 * entire buffer, but that's okay in this circumstance as we're probing
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 250 * arbitrary memory anyway similar to bpf_probe_read_*() and might
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 251 * as well probe the stack. Thus, memory is explicitly cleared
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 252 * only in error case, so that improper users ignoring return
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 253 * code altogether don't copy garbage; otherwise length of string
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 254 * is returned that can be used for bpf_perf_event_output() et al.
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 255 */
8d92db5c04d103 Christoph Hellwig 2020-06-08 256 ret = strncpy_from_kernel_nofault(dst, unsafe_ptr, size);
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 257 if (unlikely(ret < 0))
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 258 memset(dst, 0, size);
074f528eed408b Daniel Borkmann 2016-04-13 259 return ret;
2541517c32be25 Alexei Starovoitov 2015-03-25 260 }
2541517c32be25 Alexei Starovoitov 2015-03-25 261
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 @262 BPF_CALL_3(bpf_probe_read_kernel_str, void *, dst, u32, size,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 263 const void *, unsafe_ptr)
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 264 {
8d92db5c04d103 Christoph Hellwig 2020-06-08 265 return bpf_probe_read_kernel_str_common(dst, size, unsafe_ptr);
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 266 }
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 267
f470378c7562a2 John Fastabend 2020-05-24 268 const struct bpf_func_proto bpf_probe_read_kernel_str_proto = {
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 269 .func = bpf_probe_read_kernel_str,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 270 .gpl_only = true,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 271 .ret_type = RET_INTEGER,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 272 .arg1_type = ARG_PTR_TO_UNINIT_MEM,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 273 .arg2_type = ARG_CONST_SIZE_OR_ZERO,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 274 .arg3_type = ARG_ANYTHING,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 275 };
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 276
8d92db5c04d103 Christoph Hellwig 2020-06-08 277 #ifdef CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
8d92db5c04d103 Christoph Hellwig 2020-06-08 @278 BPF_CALL_3(bpf_probe_read_compat, void *, dst, u32, size,
8d92db5c04d103 Christoph Hellwig 2020-06-08 279 const void *, unsafe_ptr)
8d92db5c04d103 Christoph Hellwig 2020-06-08 280 {
8d92db5c04d103 Christoph Hellwig 2020-06-08 281 if ((unsigned long)unsafe_ptr < TASK_SIZE) {
8d92db5c04d103 Christoph Hellwig 2020-06-08 282 return bpf_probe_read_user_common(dst, size,
8d92db5c04d103 Christoph Hellwig 2020-06-08 283 (__force void __user *)unsafe_ptr);
8d92db5c04d103 Christoph Hellwig 2020-06-08 284 }
8d92db5c04d103 Christoph Hellwig 2020-06-08 285 return bpf_probe_read_kernel_common(dst, size, unsafe_ptr);
8d92db5c04d103 Christoph Hellwig 2020-06-08 286 }
8d92db5c04d103 Christoph Hellwig 2020-06-08 287
8d92db5c04d103 Christoph Hellwig 2020-06-08 288 static const struct bpf_func_proto bpf_probe_read_compat_proto = {
8d92db5c04d103 Christoph Hellwig 2020-06-08 @289 .func = bpf_probe_read_compat,
8d92db5c04d103 Christoph Hellwig 2020-06-08 290 .gpl_only = true,
8d92db5c04d103 Christoph Hellwig 2020-06-08 291 .ret_type = RET_INTEGER,
8d92db5c04d103 Christoph Hellwig 2020-06-08 292 .arg1_type = ARG_PTR_TO_UNINIT_MEM,
8d92db5c04d103 Christoph Hellwig 2020-06-08 293 .arg2_type = ARG_CONST_SIZE_OR_ZERO,
8d92db5c04d103 Christoph Hellwig 2020-06-08 294 .arg3_type = ARG_ANYTHING,
8d92db5c04d103 Christoph Hellwig 2020-06-08 295 };
8d92db5c04d103 Christoph Hellwig 2020-06-08 296
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 @297 BPF_CALL_3(bpf_probe_read_compat_str, void *, dst, u32, size,
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 298 const void *, unsafe_ptr)
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 299 {
8d92db5c04d103 Christoph Hellwig 2020-06-08 300 if ((unsigned long)unsafe_ptr < TASK_SIZE) {
8d92db5c04d103 Christoph Hellwig 2020-06-08 301 return bpf_probe_read_user_str_common(dst, size,
8d92db5c04d103 Christoph Hellwig 2020-06-08 302 (__force void __user *)unsafe_ptr);
8d92db5c04d103 Christoph Hellwig 2020-06-08 303 }
8d92db5c04d103 Christoph Hellwig 2020-06-08 304 return bpf_probe_read_kernel_str_common(dst, size, unsafe_ptr);
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 305 }
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 306
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 307 static const struct bpf_func_proto bpf_probe_read_compat_str_proto = {
6ae08ae3dea2cf Daniel Borkmann 2019-11-02 308 .func = bpf_probe_read_compat_str,
2541517c32be25 Alexei Starovoitov 2015-03-25 309 .gpl_only = true,
2541517c32be25 Alexei Starovoitov 2015-03-25 310 .ret_type = RET_INTEGER,
39f19ebbf57b40 Alexei Starovoitov 2017-01-09 311 .arg1_type = ARG_PTR_TO_UNINIT_MEM,
9c019e2bc4b2bd Yonghong Song 2017-11-12 312 .arg2_type = ARG_CONST_SIZE_OR_ZERO,
2541517c32be25 Alexei Starovoitov 2015-03-25 313 .arg3_type = ARG_ANYTHING,
2541517c32be25 Alexei Starovoitov 2015-03-25 314 };
8d92db5c04d103 Christoph Hellwig 2020-06-08 315 #endif /* CONFIG_ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE */
2541517c32be25 Alexei Starovoitov 2015-03-25 316
eb1b66887472ea Daniel Borkmann 2019-11-02 @317 BPF_CALL_3(bpf_probe_write_user, void __user *, unsafe_ptr, const void *, src,
f3694e00123802 Daniel Borkmann 2016-09-09 318 u32, size)
96ae5227959447 Sargun Dhillon 2016-07-25 319 {
96ae5227959447 Sargun Dhillon 2016-07-25 320 /*
96ae5227959447 Sargun Dhillon 2016-07-25 321 * Ensure we're in user context which is safe for the helper to
96ae5227959447 Sargun Dhillon 2016-07-25 322 * run. This helper has no business in a kthread.
96ae5227959447 Sargun Dhillon 2016-07-25 323 *
96ae5227959447 Sargun Dhillon 2016-07-25 324 * access_ok() should prevent writing to non-user memory, but in
96ae5227959447 Sargun Dhillon 2016-07-25 325 * some situations (nommu, temporary switch, etc) access_ok() does
96ae5227959447 Sargun Dhillon 2016-07-25 326 * not provide enough validation, hence the check on KERNEL_DS.
c7b6f29b625753 Nadav Amit 2019-04-25 327 *
c7b6f29b625753 Nadav Amit 2019-04-25 328 * nmi_uaccess_okay() ensures the probe is not run in an interim
c7b6f29b625753 Nadav Amit 2019-04-25 329 * state, when the task or mm are switched. This is specifically
c7b6f29b625753 Nadav Amit 2019-04-25 330 * required to prevent the use of temporary mm.
96ae5227959447 Sargun Dhillon 2016-07-25 331 */
96ae5227959447 Sargun Dhillon 2016-07-25 332
96ae5227959447 Sargun Dhillon 2016-07-25 333 if (unlikely(in_interrupt() ||
96ae5227959447 Sargun Dhillon 2016-07-25 334 current->flags & (PF_KTHREAD | PF_EXITING)))
96ae5227959447 Sargun Dhillon 2016-07-25 335 return -EPERM;
db68ce10c4f0a2 Al Viro 2017-03-20 336 if (unlikely(uaccess_kernel()))
96ae5227959447 Sargun Dhillon 2016-07-25 337 return -EPERM;
c7b6f29b625753 Nadav Amit 2019-04-25 338 if (unlikely(!nmi_uaccess_okay()))
c7b6f29b625753 Nadav Amit 2019-04-25 339 return -EPERM;
96ae5227959447 Sargun Dhillon 2016-07-25 340
25237b79a183c4 Catalin Marinas 2021-11-26 341 return copy_to_user_nofault(unsafe_ptr, src, size) ? -EFAULT : 0;
96ae5227959447 Sargun Dhillon 2016-07-25 342 }
96ae5227959447 Sargun Dhillon 2016-07-25 343
96ae5227959447 Sargun Dhillon 2016-07-25 344 static const struct bpf_func_proto bpf_probe_write_user_proto = {
96ae5227959447 Sargun Dhillon 2016-07-25 345 .func = bpf_probe_write_user,
96ae5227959447 Sargun Dhillon 2016-07-25 346 .gpl_only = true,
96ae5227959447 Sargun Dhillon 2016-07-25 347 .ret_type = RET_INTEGER,
96ae5227959447 Sargun Dhillon 2016-07-25 348 .arg1_type = ARG_ANYTHING,
39f19ebbf57b40 Alexei Starovoitov 2017-01-09 349 .arg2_type = ARG_PTR_TO_MEM,
39f19ebbf57b40 Alexei Starovoitov 2017-01-09 350 .arg3_type = ARG_CONST_SIZE,
96ae5227959447 Sargun Dhillon 2016-07-25 351 };
96ae5227959447 Sargun Dhillon 2016-07-25 352
96ae5227959447 Sargun Dhillon 2016-07-25 @353 static const struct bpf_func_proto *bpf_get_probe_write_proto(void)
96ae5227959447 Sargun Dhillon 2016-07-25 354 {
2c78ee898d8f10 Alexei Starovoitov 2020-05-13 355 if (!capable(CAP_SYS_ADMIN))
2c78ee898d8f10 Alexei Starovoitov 2020-05-13 356 return NULL;
2c78ee898d8f10 Alexei Starovoitov 2020-05-13 357
96ae5227959447 Sargun Dhillon 2016-07-25 358 pr_warn_ratelimited("%s[%d] is installing a program with bpf_probe_write_user helper that may corrupt user memory!",
96ae5227959447 Sargun Dhillon 2016-07-25 359 current->comm, task_pid_nr(current));
96ae5227959447 Sargun Dhillon 2016-07-25 360
96ae5227959447 Sargun Dhillon 2016-07-25 361 return &bpf_probe_write_user_proto;
96ae5227959447 Sargun Dhillon 2016-07-25 362 }
96ae5227959447 Sargun Dhillon 2016-07-25 363
:::::: The code at line 164 was first introduced by commit
:::::: 8d92db5c04d10381f4db70ed99b1b576f5db18a7 bpf: rework the compat kernel probe handling
:::::: TO: Christoph Hellwig <hch at lst.de>
:::::: CC: Linus Torvalds <torvalds at linux-foundation.org>
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
More information about the linux-arm-kernel
mailing list