Re: [PATCH v4 9/20] lsm: Refactor return value of LSM hook key_getsecurity

2024-07-23 Thread Xu Kuohai
On 7/23/2024 5:35 AM, Paul Moore wrote: On Sat, Jul 20, 2024 at 5:31 AM Xu Kuohai wrote: On 7/19/2024 10:08 AM, Paul Moore wrote: On Jul 11, 2024 Xu Kuohai wrote: To be consistent with most LSM hooks, convert the return value of hook key_getsecurity to 0 or a negative error code. Before

Re: [PATCH v4 7/20] lsm: Refactor return value of LSM hook setprocattr

2024-07-20 Thread Xu Kuohai
On 7/19/2024 10:08 AM, Paul Moore wrote: On Jul 11, 2024 Xu Kuohai wrote: To be consistent with most LSM hooks, convert the return value of hook setprocattr to 0 or a negative error code. Before: - Hook setprocattr returns the number of bytes written on success or a negative error code on

Re: [PATCH v4 10/20] lsm: Refactor return value of LSM hook audit_rule_match

2024-07-20 Thread Xu Kuohai
On 7/19/2024 10:08 AM, Paul Moore wrote: On Jul 11, 2024 Xu Kuohai wrote: To be consistent with most LSM hooks, convert the return value of hook audit_rule_match to 0 or a negative error code. Before: - Hook audit_rule_match returns 1 if the rule matches, 0 if it not, and negative error

Re: [PATCH v4 9/20] lsm: Refactor return value of LSM hook key_getsecurity

2024-07-20 Thread Xu Kuohai
On 7/19/2024 10:08 AM, Paul Moore wrote: On Jul 11, 2024 Xu Kuohai wrote: To be consistent with most LSM hooks, convert the return value of hook key_getsecurity to 0 or a negative error code. Before: - Hook key_getsecurity returns length of value on success or a negative error code on

Re: [PATCH v4 8/20] lsm: Refactor return value of LSM hook getprocattr

2024-07-20 Thread Xu Kuohai
On 7/19/2024 10:08 AM, Paul Moore wrote: On Jul 11, 2024 Xu Kuohai wrote: To be consistent with most LSM hooks, convert the return value of hook getprocattr to 0 or a negative error code. Before: - Hook getprocattr returns length of value on success or a negative error code on failure

Re: [PATCH v4 6/20] lsm: Refactor return value of LSM hook getselfattr

2024-07-20 Thread Xu Kuohai
On 7/19/2024 10:08 AM, Paul Moore wrote: On Jul 11, 2024 Xu Kuohai wrote: To be consistent with most LSM hooks, convert the return value of hook getselfattr to 0 or a negative error code. Before: - Hook getselfattr returns number of attributes found on success or a negative error code on

Re: [PATCH v4 5/20] lsm: Refactor return value of LSM hook inode_copy_up_xattr

2024-07-20 Thread Xu Kuohai
On 7/19/2024 10:08 AM, Paul Moore wrote: On Jul 11, 2024 Xu Kuohai wrote: To be consistent with most LSM hooks, convert the return value of hook inode_copy_up_xattr to 0 or a negative error code. Before: - Hook inode_copy_up_xattr returns 0 when accepting xattr, 1 when discarding xattr

Re: [PATCH v4 4/20] lsm: Refactor return value of LSM hook inode_listsecurity

2024-07-20 Thread Xu Kuohai
On 7/19/2024 10:08 AM, Paul Moore wrote: On Jul 11, 2024 Xu Kuohai wrote: To be consistent with most LSM hooks, convert the return value of hook inode_listsecurity to 0 or a negative error code. Before: - Hook inode_listsecurity returns number of bytes used/required on success or a

Re: [PATCH v4 3/20] lsm: Refactor return value of LSM hook inode_getsecurity

2024-07-20 Thread Xu Kuohai
On 7/19/2024 10:08 AM, Paul Moore wrote: On Jul 11, 2024 Xu Kuohai wrote: To be consistent with most LSM hooks, convert the return value of hook inode_getsecurity to 0 or a negative error code. Before: - Hook inode_getsecurity returns size of buffer on success or a negative error code on

Re: [PATCH v4 2/20] lsm: Refactor return value of LSM hook inode_need_killpriv

2024-07-20 Thread Xu Kuohai
On 7/19/2024 10:08 AM, Paul Moore wrote: On Jul 11, 2024 Xu Kuohai wrote: To be consistent with most LSM hooks, convert the return value of hook inode_need_killpriv to 0 or a negative error code. Before: - Both hook inode_need_killpriv and func security_inode_need_killpriv return > 0

Re: [PATCH bpf-next v4 00/20] Add return value range check for BPF LSM

2024-07-18 Thread Xu Kuohai
On 7/19/2024 10:13 AM, Paul Moore wrote: On Fri, Jul 12, 2024 at 5:44 PM Paul Moore wrote: On Thu, Jul 11, 2024 at 7:13 AM Xu Kuohai wrote: From: Xu Kuohai LSM BPF prog returning a positive number attached to the hook file_alloc_security makes kernel panic. Here is a panic log

Re: [PATCH bpf-next v4 11/20] bpf, lsm: Add disabled BPF LSM hook list

2024-07-13 Thread Xu Kuohai
On 7/13/2024 1:56 AM, Alexei Starovoitov wrote: On Thu, Jul 11, 2024 at 07:18:59PM +0800, Xu Kuohai wrote: From: Xu Kuohai Add a disabled hooks list for BPF LSM. progs being attached to the listed hooks will be rejected by the verifier. Suggested-by: KP Singh Signed-off-by: Xu Kuohai Xu

Re: [PATCH bpf-next v4 03/20] lsm: Refactor return value of LSM hook inode_getsecurity

2024-07-13 Thread Xu Kuohai
On 7/12/2024 9:31 PM, Simon Horman wrote: On Thu, Jul 11, 2024 at 07:18:51PM +0800, Xu Kuohai wrote: From: Xu Kuohai To be consistent with most LSM hooks, convert the return value of hook inode_getsecurity to 0 or a negative error code. Before: - Hook inode_getsecurity returns size of buffer

Re: [PATCH bpf-next v4 02/20] lsm: Refactor return value of LSM hook inode_need_killpriv

2024-07-13 Thread Xu Kuohai
On 7/11/2024 10:15 PM, Serge Hallyn wrote: Jul 11, 2024 06:14:09 Xu Kuohai : From: Xu Kuohai To be consistent with most LSM hooks, convert the return value of hook inode_need_killpriv to 0 or a negative error code. Before: - Both hook inode_need_killpriv and func

[PATCH bpf-next v4 20/20] selftests/bpf: Add verifier tests for bpf lsm

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai Add verifier tests to check bpf lsm return values, output parameter access and disabled hooks. Signed-off-by: Xu Kuohai --- .../selftests/bpf/prog_tests/verifier.c | 2 + .../selftests/bpf/progs/verifier_lsm.c| 274 ++ 2 files changed, 276

[PATCH bpf-next v4 19/20] selftests/bpf: Add test for lsm tail call

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai Add test for lsm tail call to ensure tail call can only be used between bpf lsm progs attached to the same hook. Signed-off-by: Xu Kuohai --- .../selftests/bpf/prog_tests/test_lsm.c | 46 ++- .../selftests/bpf/progs/lsm_tailcall.c| 34

[PATCH bpf-next v4 18/20] selftests/bpf: Add return value checks for failed tests

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai The return ranges of some bpf lsm test progs can not be deduced by the verifier accurately. To avoid erroneous rejections, add explicit return value checks for these progs. Signed-off-by: Xu Kuohai --- tools/testing/selftests/bpf/progs/err.h| 10

[PATCH bpf-next v4 17/20] selftests/bpf: Avoid load failure for token_lsm.c

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai The compiler optimized the two bpf progs in token_lsm.c to make return value from the bool variable in the "return -1" path, causing an unexpected rejection: 0: R1=ctx() R10=fp0 ; int BPF_PROG(bpf_token_capable, struct bpf_token *token, int cap) @ bpf_lsm.c:17 0: (

[PATCH bpf-next v4 16/20] bpf: Add a special case for bitwise AND on range [-1, 0]

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai With lsm return value check, the no-alu32 version test_libbpf_get_fd_by_id_opts is rejected by the verifier, and the log says: 0: R1=ctx() R10=fp0 ; int BPF_PROG(check_access, struct bpf_map *map, fmode_t fmode) @ test_libbpf_get_fd_by_id_opts.c:27 0: (b7) r0 = 0

[PATCH bpf-next v4 13/20] bpf, lsm: Add check for BPF LSM return value

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai A bpf prog returning a positive number attached to file_alloc_security hook makes kernel panic. This happens because file system can not filter out the positive number returned by the LSM prog using IS_ERR, and misinterprets this positive number as a file pointer. Given that

[PATCH bpf-next v4 14/20] bpf: Prevent tail call between progs attached to different hooks

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai bpf progs can be attached to kernel functions, and the attached functions can take different parameters or return different return values. If prog attached to one kernel function tail calls prog attached to another kernel function, the ctx access or return value verification

[PATCH bpf-next v4 15/20] bpf: Fix compare error in function retval_range_within

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai After checking lsm hook return range in verifier, the test case "test_progs -t test_lsm" failed, and the failure log says: libbpf: prog 'test_int_hook': BPF program load failed: Invalid argument libbpf: prog 'test_int_hook': -- BEGIN PROG LOAD LO

[PATCH bpf-next v4 12/20] bpf, lsm: Enable BPF LSM prog to read/write return value parameters

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai Output parameters are used to refactor the LSM hook return values. To make these hooks usable by bpf prog, it is necessary for bpf prog to read and write these output return value parameters. All return value parameters are added as the last parameter and are always pointers to

[PATCH bpf-next v4 09/20] lsm: Refactor return value of LSM hook key_getsecurity

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai To be consistent with most LSM hooks, convert the return value of hook key_getsecurity to 0 or a negative error code. Before: - Hook key_getsecurity returns length of value on success or a negative error code on failure. After: - Hook key_getsecurity returns 0 on success or a

[PATCH bpf-next v4 10/20] lsm: Refactor return value of LSM hook audit_rule_match

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai To be consistent with most LSM hooks, convert the return value of hook audit_rule_match to 0 or a negative error code. Before: - Hook audit_rule_match returns 1 if the rule matches, 0 if it not, and negative error code otherwise. After: - Hook audit_rule_match returns 0 on

[PATCH bpf-next v4 06/20] lsm: Refactor return value of LSM hook getselfattr

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai To be consistent with most LSM hooks, convert the return value of hook getselfattr to 0 or a negative error code. Before: - Hook getselfattr returns number of attributes found on success or a negative error code on failure. After: - Hook getselfattr returns 0 on success or a

[PATCH bpf-next v4 07/20] lsm: Refactor return value of LSM hook setprocattr

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai To be consistent with most LSM hooks, convert the return value of hook setprocattr to 0 or a negative error code. Before: - Hook setprocattr returns the number of bytes written on success or a negative error code on failure. After: - Hook setprocattr returns 0 on success or a

[PATCH bpf-next v4 01/20] lsm: Refactor return value of LSM hook vm_enough_memory

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai To be consistent with most LSM hooks, convert the return value of hook vm_enough_memory to 0 or a negative error code. Before: - Hook vm_enough_memory returns 1 if permission is granted, 0 if not. - LSM_RET_DEFAULT(vm_enough_memory_mm) is 1. After: - Hook vm_enough_memory

[PATCH bpf-next v4 03/20] lsm: Refactor return value of LSM hook inode_getsecurity

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai To be consistent with most LSM hooks, convert the return value of hook inode_getsecurity to 0 or a negative error code. Before: - Hook inode_getsecurity returns size of buffer on success or a negative error code on failure. After: - Hook inode_getsecurity returns 0 on success

[PATCH bpf-next v4 04/20] lsm: Refactor return value of LSM hook inode_listsecurity

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai To be consistent with most LSM hooks, convert the return value of hook inode_listsecurity to 0 or a negative error code. Before: - Hook inode_listsecurity returns number of bytes used/required on success or a negative error code on failure. After: - Hook inode_listsecurity

[PATCH bpf-next v4 11/20] bpf, lsm: Add disabled BPF LSM hook list

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai Add a disabled hooks list for BPF LSM. progs being attached to the listed hooks will be rejected by the verifier. Suggested-by: KP Singh Signed-off-by: Xu Kuohai --- kernel/bpf/bpf_lsm.c | 19 +-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a

[PATCH bpf-next v4 00/20] Add return value range check for BPF LSM

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai LSM BPF prog returning a positive number attached to the hook file_alloc_security makes kernel panic. Here is a panic log: [ 441.235774] BUG: kernel NULL pointer dereference, address: 09 [ 441.236748] #PF: supervisor write access in kernel mode [ 441.237429] #PF

[PATCH bpf-next v4 08/20] lsm: Refactor return value of LSM hook getprocattr

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai To be consistent with most LSM hooks, convert the return value of hook getprocattr to 0 or a negative error code. Before: - Hook getprocattr returns length of value on success or a negative error code on failure. After: - Hook getprocattr returns 0 on success or a negative

[PATCH bpf-next v4 05/20] lsm: Refactor return value of LSM hook inode_copy_up_xattr

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai To be consistent with most LSM hooks, convert the return value of hook inode_copy_up_xattr to 0 or a negative error code. Before: - Hook inode_copy_up_xattr returns 0 when accepting xattr, 1 when discarding xattr, -EOPNOTSUPP if it does not know xattr, or any other negative

[PATCH bpf-next v4 02/20] lsm: Refactor return value of LSM hook inode_need_killpriv

2024-07-11 Thread Xu Kuohai
From: Xu Kuohai To be consistent with most LSM hooks, convert the return value of hook inode_need_killpriv to 0 or a negative error code. Before: - Both hook inode_need_killpriv and func security_inode_need_killpriv return > 0 if security_inode_killpriv is required, 0 if not, and <

Re: [PATCH bpf-next v2] arm64, bpf: Add 12-argument support for bpf trampoline

2024-07-08 Thread Xu Kuohai
On 7/8/2024 5:00 PM, Puranjay Mohan wrote: Xu Kuohai writes: On 7/5/2024 8:53 PM, Puranjay Mohan wrote: The arm64 bpf JIT currently supports attaching the trampoline to functions with <= 8 arguments. This is because up to 8 arguments can be passed in registers r0-r7. If there are more tha

Re: [PATCH bpf-next v2] arm64, bpf: Add 12-argument support for bpf trampoline

2024-07-06 Thread Xu Kuohai
On 7/5/2024 8:53 PM, Puranjay Mohan wrote: The arm64 bpf JIT currently supports attaching the trampoline to functions with <= 8 arguments. This is because up to 8 arguments can be passed in registers r0-r7. If there are more than 8 arguments then the 9th and later arguments are passed on the stac

Re: [PATCH bpf-next v3 01/11] bpf, lsm: Annotate lsm hook return value range

2024-06-10 Thread Xu Kuohai
On 6/10/2024 2:17 AM, Paul Moore wrote: On Sun, Jun 9, 2024 at 1:39 PM Casey Schaufler wrote: On 6/8/2024 6:54 AM, Alexei Starovoitov wrote: On Sat, Jun 8, 2024 at 1:04 AM Xu Kuohai wrote: On 6/7/2024 5:53 AM, Paul Moore wrote: On Thu, Apr 11, 2024 at 8:24 AM Xu Kuohai wrote: From: Xu

Re: [PATCH bpf-next v3 01/11] bpf, lsm: Annotate lsm hook return value range

2024-06-08 Thread Xu Kuohai
On 6/7/2024 5:53 AM, Paul Moore wrote: On Thu, Apr 11, 2024 at 8:24 AM Xu Kuohai wrote: From: Xu Kuohai Add macro LSM_RET_INT to annotate lsm hook return integer type and the default return value, and the expected return range. The LSM_RET_INT is declared as: LSM_RET_INT(defval, min, max

Re: [PATCH bpf-next v3 07/11] bpf: Fix a false rejection caused by AND operation

2024-04-29 Thread Xu Kuohai
On 4/30/2024 6:18 AM, Eduard Zingerman wrote: On Mon, 2024-04-29 at 13:58 -0700, Andrii Nakryiko wrote: [...] diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 8f0f2e21699e..b69c89bc5cfc 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -13478,6 +13478,28 @@ stat

Re: [PATCH bpf-next v3 07/11] bpf: Fix a false rejection caused by AND operation

2024-04-29 Thread Xu Kuohai
On 4/30/2024 4:58 AM, Andrii Nakryiko wrote: On Sun, Apr 28, 2024 at 8:15 AM Xu Kuohai wrote: On 4/27/2024 4:36 AM, Andrii Nakryiko wrote: On Tue, Apr 23, 2024 at 7:26 PM Xu Kuohai wrote: On 4/24/2024 5:55 AM, Yonghong Song wrote: On 4/20/24 1:33 AM, Xu Kuohai wrote: On 4/20/2024 7:00

Re: [PATCH bpf-next v3 07/11] bpf: Fix a false rejection caused by AND operation

2024-04-28 Thread Xu Kuohai
On 4/27/2024 4:36 AM, Andrii Nakryiko wrote: On Tue, Apr 23, 2024 at 7:26 PM Xu Kuohai wrote: On 4/24/2024 5:55 AM, Yonghong Song wrote: On 4/20/24 1:33 AM, Xu Kuohai wrote: On 4/20/2024 7:00 AM, Eduard Zingerman wrote: On Thu, 2024-04-11 at 20:27 +0800, Xu Kuohai wrote: From: Xu Kuohai

Re: [PATCH bpf-next v3 06/11] bpf: Fix compare error in function retval_range_within

2024-04-26 Thread Xu Kuohai
On 4/26/2024 7:41 AM, Andrii Nakryiko wrote: On Thu, Apr 11, 2024 at 5:24 AM Xu Kuohai wrote: From: Xu Kuohai After checking lsm hook return range in verifier, the test case "test_progs -t test_lsm" failed, and the failure log says: libbpf: prog 'test_int_hook': BPF

Re: [PATCH bpf-next v3 07/11] bpf: Fix a false rejection caused by AND operation

2024-04-26 Thread Xu Kuohai
On 4/26/2024 12:28 AM, Yonghong Song wrote: On 4/24/24 7:42 PM, Xu Kuohai wrote: On 4/25/2024 6:06 AM, Yonghong Song wrote: On 4/23/24 7:25 PM, Xu Kuohai wrote: On 4/24/2024 5:55 AM, Yonghong Song wrote: On 4/20/24 1:33 AM, Xu Kuohai wrote: On 4/20/2024 7:00 AM, Eduard Zingerman wrote

Re: [PATCH bpf-next v3 07/11] bpf: Fix a false rejection caused by AND operation

2024-04-24 Thread Xu Kuohai
On 4/25/2024 6:06 AM, Yonghong Song wrote: On 4/23/24 7:25 PM, Xu Kuohai wrote: On 4/24/2024 5:55 AM, Yonghong Song wrote: On 4/20/24 1:33 AM, Xu Kuohai wrote: On 4/20/2024 7:00 AM, Eduard Zingerman wrote: On Thu, 2024-04-11 at 20:27 +0800, Xu Kuohai wrote: From: Xu Kuohai With lsm

Re: [PATCH bpf-next v3 07/11] bpf: Fix a false rejection caused by AND operation

2024-04-23 Thread Xu Kuohai
On 4/24/2024 5:55 AM, Yonghong Song wrote: On 4/20/24 1:33 AM, Xu Kuohai wrote: On 4/20/2024 7:00 AM, Eduard Zingerman wrote: On Thu, 2024-04-11 at 20:27 +0800, Xu Kuohai wrote: From: Xu Kuohai With lsm return value check, the no-alu32 version test_libbpf_get_fd_by_id_opts is rejected by

Re: [PATCH bpf-next v3 07/11] bpf: Fix a false rejection caused by AND operation

2024-04-20 Thread Xu Kuohai
On 4/20/2024 7:00 AM, Eduard Zingerman wrote: On Thu, 2024-04-11 at 20:27 +0800, Xu Kuohai wrote: From: Xu Kuohai With lsm return value check, the no-alu32 version test_libbpf_get_fd_by_id_opts is rejected by the verifier, and the log says: 0: R1=ctx() R10=fp0 ; int BPF_PROG

[PATCH bpf-next v3 11/11] selftests/bpf: Add verifier tests for bpf lsm

2024-04-11 Thread Xu Kuohai
From: Xu Kuohai Add verifier tests to check bpf lsm return values and disabled hooks. Signed-off-by: Xu Kuohai --- .../selftests/bpf/prog_tests/verifier.c | 3 +- .../selftests/bpf/progs/verifier_lsm.c| 155 ++ 2 files changed, 157 insertions(+), 1 deletion

[PATCH bpf-next v3 08/11] selftests/bpf: Avoid load failure for token_lsm.c

2024-04-11 Thread Xu Kuohai
From: Xu Kuohai The compiler optimized the two bpf progs in token_lsm.c to make return value from the bool variable in the "return -1" path, causing an unexpected rejection: 0: R1=ctx() R10=fp0 ; int BPF_PROG(bpf_token_capable, struct bpf_token *token, int cap) @ bpf_lsm.c:17 0: (

[PATCH bpf-next v3 01/11] bpf, lsm: Annotate lsm hook return value range

2024-04-11 Thread Xu Kuohai
From: Xu Kuohai Add macro LSM_RET_INT to annotate lsm hook return integer type and the default return value, and the expected return range. The LSM_RET_INT is declared as: LSM_RET_INT(defval, min, max) where - defval is the default return value - min and max indicate the expected return

[PATCH bpf-next v3 02/11] bpf, lsm: Add helper to read lsm hook return value range

2024-04-11 Thread Xu Kuohai
From: Xu Kuohai Add helper to read lsm hook return value range. The following patch will use this information to verify lsm hook return values in bpf verifier. Signed-off-by: Xu Kuohai --- include/linux/bpf_lsm.h | 8 ++ kernel/bpf/bpf_lsm.c| 54

[PATCH bpf-next v3 09/11] selftests/bpf: Add return value checks for failed tests

2024-04-11 Thread Xu Kuohai
From: Xu Kuohai The return ranges of some bpf lsm test progs can not be deduced by the verifier accurately. To avoid erroneous rejections, add explicit return value checks for these progs. Signed-off-by: Xu Kuohai --- tools/testing/selftests/bpf/progs/err.h| 10

[PATCH bpf-next v3 10/11] selftests/bpf: Add test for lsm tail call

2024-04-11 Thread Xu Kuohai
From: Xu Kuohai Add test for lsm tail call to ensure tail call can only be used between bpf lsm progs attached to the same hook. Signed-off-by: Xu Kuohai --- .../selftests/bpf/prog_tests/test_lsm.c | 46 ++- .../selftests/bpf/progs/lsm_tailcall.c| 34

[PATCH bpf-next v3 03/11] bpf, lsm: Check bpf lsm hook return values in verifier

2024-04-11 Thread Xu Kuohai
From: Xu Kuohai A bpf prog returning positive number attached to file_alloc_security hook will make kernel panic. The reason is that the positive number returned by bpf prog is not a valid errno, and could not be filtered out with IS_ERR which is used by the file system to check errors. As a

[PATCH bpf-next v3 07/11] bpf: Fix a false rejection caused by AND operation

2024-04-11 Thread Xu Kuohai
From: Xu Kuohai With lsm return value check, the no-alu32 version test_libbpf_get_fd_by_id_opts is rejected by the verifier, and the log says: 0: R1=ctx() R10=fp0 ; int BPF_PROG(check_access, struct bpf_map *map, fmode_t fmode) @ test_libbpf_get_fd_by_id_opts.c:27 0: (b7) r0 = 0

[PATCH bpf-next v3 06/11] bpf: Fix compare error in function retval_range_within

2024-04-11 Thread Xu Kuohai
From: Xu Kuohai After checking lsm hook return range in verifier, the test case "test_progs -t test_lsm" failed, and the failure log says: libbpf: prog 'test_int_hook': BPF program load failed: Invalid argument libbpf: prog 'test_int_hook': -- BEGIN PROG LOAD LO

[PATCH bpf-next v3 00/11] Add check for bpf lsm return value

2024-04-11 Thread Xu Kuohai
From: Xu Kuohai A bpf prog returning positive number attached to file_alloc_security hook will make kernel panic. Here is a panic log: [ 441.235774] BUG: kernel NULL pointer dereference, address: 09 [ 441.236748] #PF: supervisor write access in kernel mode [ 441.237429] #PF

[PATCH bpf-next v3 05/11] bpf: Avoid progs for different hooks calling each other with tail call

2024-04-11 Thread Xu Kuohai
From: Xu Kuohai LSM and tracing bpf programs are hooked to kernel functions which may have different types. That is, the hook functions may have different parameters, different return types, or different return ranges. progs attached to different hook types may receive different context

[PATCH bpf-next v3 04/11] bpf, lsm: Add bpf lsm disabled hook list

2024-04-11 Thread Xu Kuohai
From: Xu Kuohai Add a disabled hooks list for bpf lsm. progs being attached to the listed hooks will be rejected by the verifier. Suggested-by: KP Singh Signed-off-by: Xu Kuohai --- kernel/bpf/bpf_lsm.c | 20 ++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a