-
Notifications
You must be signed in to change notification settings - Fork 6
Introduce bpf_cgroup_read_xattr #5503
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
base: bpf-next_base
Are you sure you want to change the base?
Introduce bpf_cgroup_read_xattr #5503
Conversation
Upstream branch: 99fe8af |
983d136
to
097b64d
Compare
Upstream branch: c11f34e |
d208ff1
to
39d6a11
Compare
097b64d
to
1daac42
Compare
Upstream branch: 3ce7cdd |
39d6a11
to
95fb834
Compare
1daac42
to
86c8a5d
Compare
Upstream branch: 3ce7cdd |
95fb834
to
b5a368a
Compare
86c8a5d
to
2fccc2d
Compare
All allocations of struct kernfs_iattrs are serialized through a global mutex. Simply do a racy allocation and let the first one win. I bet most callers are under inode->i_rwsem anyway and it wouldn't be needed but let's not require that. Signed-off-by: Christian Brauner <[email protected]> Acked-by: Greg Kroah-Hartman <[email protected]> Acked-by: Tejun Heo <[email protected]> Signed-off-by: Song Liu <[email protected]>
BPF programs, such as LSM and sched_ext, would benefit from tags on cgroups. One common practice to apply such tags is to set xattrs on cgroupfs folders. Introduce kfunc bpf_cgroup_read_xattr, which allows reading cgroup's xattr. Note that, we already have bpf_get_[file|dentry]_xattr. However, these two APIs are not ideal for reading cgroupfs xattrs, because: 1) These two APIs only works in sleepable contexts; 2) There is no kfunc that matches current cgroup to cgroupfs dentry. bpf_cgroup_read_xattr is generic and can be useful for many program types. It is also safe, because it requires trusted or rcu protected argument (KF_RCU). Therefore, we make it available to all program types. Signed-off-by: Song Liu <[email protected]> Acked-by: Tejun Heo <[email protected]>
Mark struct cgroup_subsys_state->cgroup as safe under RCU read lock. This will enable accessing css->cgroup from a bpf css iterator. Signed-off-by: Song Liu <[email protected]>
Add tests for different scenarios with bpf_cgroup_read_xattr: 1. Read cgroup xattr from bpf_cgroup_from_id; 2. Read cgroup xattr from bpf_cgroup_ancestor; 3. Read cgroup xattr from css_iter; 4. Use bpf_cgroup_read_xattr in LSM hook security_socket_connect. 5. Use bpf_cgroup_read_xattr in cgroup program. Signed-off-by: Song Liu <[email protected]>
Upstream branch: 3713b58 |
b5a368a
to
c38d54a
Compare
Pull request for series with
subject: Introduce bpf_cgroup_read_xattr
version: 3
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=974689