Skip to content

Commit 1630970

Browse files
ameryhungKernel Patches Daemon
authored andcommitted
bpf: Disable file_alloc_security hook
A use-after-free bug may be triggered by calling bpf_inode_storage_get() in a BPF LSM program hooked to file_alloc_security. Disable the hook to prevent this from happening. The cause of the bug is shown in the trace below. In alloc_file(), a file struct is first allocated through kmem_cache_alloc(). Then, file_alloc_security hook is invoked. Since the zero initialization or assignment of f->f_inode happen after this LSM hook, a BPF program may get a dangeld inode pointer by walking the file struct. alloc_file() -> alloc_empty_file() -> f = kmem_cache_alloc() -> init_file() -> security_file_alloc() // f->f_inode not init-ed yet! -> f->f_inode = NULL; -> file_init_path() -> f->f_inode = path->dentry->d_inode Reported-by: Kaiyan Mei <[email protected]> Reported-by: Yinhao Hu <[email protected]> Reported-by: Dongliang Mu <[email protected]> Closes: https://lore.kernel.org/bpf/[email protected]/ Signed-off-by: Amery Hung <[email protected]>
1 parent 8c83cb5 commit 1630970

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

kernel/bpf/bpf_lsm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ BTF_ID(func, bpf_lsm_key_getsecurity)
5151
BTF_ID(func, bpf_lsm_audit_rule_match)
5252
#endif
5353
BTF_ID(func, bpf_lsm_ismaclabel)
54+
BTF_ID(func, bpf_lsm_file_alloc_security)
5455
BTF_SET_END(bpf_lsm_disabled_hooks)
5556

5657
/* List of LSM hooks that should operate on 'current' cgroup regardless

0 commit comments

Comments
 (0)