-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable writing xattr from BPF programs #8335
base: bpf-next_base
Are you sure you want to change the base?
Conversation
Upstream branch: bfaac2a |
21a4297
to
36a754d
Compare
Upstream branch: e8ec1c9 |
a10bc84
to
f59d967
Compare
Upstream branch: e8ec1c9 |
f59d967
to
52a22c8
Compare
Upstream branch: e8ec1c9 |
52a22c8
to
576f9bc
Compare
36a754d
to
b27feb5
Compare
Upstream branch: e8ec1c9 |
576f9bc
to
cf8b1e0
Compare
b27feb5
to
ffc879e
Compare
Upstream branch: a43796b |
cf8b1e0
to
a90db9c
Compare
ffc879e
to
77d4ead
Compare
Upstream branch: defac89 |
a90db9c
to
4cbcc20
Compare
77d4ead
to
483693f
Compare
Upstream branch: 95ad526 |
4cbcc20
to
8ead5ae
Compare
2327693
to
e4fef02
Compare
Upstream branch: 87c5441 |
d7e1d0e
to
68153e7
Compare
e4fef02
to
70e4b2e
Compare
Upstream branch: a8d1c48 |
68153e7
to
f0528cf
Compare
70e4b2e
to
a20eb62
Compare
Upstream branch: 556a399 |
f0528cf
to
b57faac
Compare
a20eb62
to
1332909
Compare
Upstream branch: 556a399 |
b57faac
to
9d8fb9c
Compare
1332909
to
075d2f1
Compare
Upstream branch: b53b63d |
9d8fb9c
to
63160c3
Compare
075d2f1
to
cfe4aae
Compare
Upstream branch: f8a0569 |
63160c3
to
498c1a4
Compare
cfe4aae
to
c120dfb
Compare
Introduct new xattr name prefix security.bpf., and enable reading these xattrs from bpf kfuncs bpf_get_[file|dentry]_xattr(). As we are on it, correct the comments for return value of bpf_get_[file|dentry]_xattr(), i.e. return length the xattr value on success. Signed-off-by: Song Liu <song@kernel.org> Acked-by: Christian Brauner <brauner@kernel.org> Reviewed-by: Jan Kara <jack@suse.cz>
Extend test_progs fs_kfuncs to cover different xattr names. Specifically: xattr name "user.kfuncs" and "security.bpf.xxx" can be read from BPF program with kfuncs bpf_get_[file|dentry]_xattr(); while "security.bpf" and "security.selinux" cannot be read. Signed-off-by: Song Liu <song@kernel.org>
Add bpf_lsm_inode_removexattr and bpf_lsm_inode_post_removexattr to list sleepable_lsm_hooks. These two hooks are always called from sleepable context. Signed-off-by: Song Liu <song@kernel.org>
Polymorphism exists in kernel functions, BPF helpers, as well as kfuncs. When called from different contexts, it is necessary to pick the right version of a kfunc. One of such example is bpf_dynptr_from_skb vs. bpf_dynptr_from_skb_rdonly. To avoid the burden on the users, the verifier can inspect the calling context and select the right version of kfunc. However, with more kfuncs being added to the kernel, it is not scalable to push all these logic to the verifiler. Extend btf_kfunc_id_set to handle kfunc polymorphism. Specifically, a list of kfuncs, "hidden_set", and a new method "remap" is added to btf_kfunc_id_set. kfuncs in hidden_set do not have BTF_SET8_KFUNCS flag, and are not exposed in vmlinux.h. The remap method is used to inspect the calling context, and when necessary, remap the user visible kfuncs (for example, bpf_dynptr_from_skb), to its hidden version (for example, bpf_dynptr_from_skb_rdonly). The verifier calls in these remap logic via the new btf_kfunc_id_remap() API, and picks the right kfuncs for the context. Signed-off-by: Song Liu <song@kernel.org>
btf_kfunc_id_set.remap can pick proper version of a kfunc for the calling context. Use this logic to select bpf_dynptr_from_skb or bpf_dynptr_from_skb_rdonly. This will make the verifier simpler. Unfortunately, btf_kfunc_id_set.remap cannot cover the DYNPTR_TYPE_SKB logic in check_kfunc_args(). This can be addressed later. Signed-off-by: Song Liu <song@kernel.org>
Add the following kfuncs to set and remove xattrs from BPF programs: bpf_set_dentry_xattr bpf_remove_dentry_xattr bpf_set_dentry_xattr_locked bpf_remove_dentry_xattr_locked The _locked version of these kfuncs are called from hooks where dentry->d_inode is already locked. Instead of requiring the user to know which version of the kfuncs to use, the verifier will pick the proper kfunc based on the calling hook. Signed-off-by: Song Liu <song@kernel.org>
Two sets of tests are added to exercise the not _locked and _locked version of the kfuncs. For both tests, user space accesses xattr security.bpf.foo on a testfile. The BPF program is triggered by user space access (on LSM hook inode_[set|get]_xattr) and sets or removes xattr security.bpf.bar. Then user space then validates that xattr security.bpf.bar is set or removed as expected. Note that, in both tests, the BPF programs use the not _locked kfuncs. The verifier picks the proper kfuncs based on the calling context. Signed-off-by: Song Liu <song@kernel.org>
Upstream branch: e055a46 |
498c1a4
to
0417639
Compare
Pull request for series with
subject: Enable writing xattr from BPF programs
version: 8
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=923532