Skip to content

Commit ec8e3e2

Browse files
laoarAlexei Starovoitov
authored andcommitted
bpf: mark mm->owner as __safe_rcu_or_null
When CONFIG_MEMCG is enabled, we can access mm->owner under RCU. The owner can be NULL. With this change, BPF helpers can safely access mm->owner to retrieve the associated task from the mm. We can then make policy decision based on the task attribute. The typical use case is as follows, bpf_rcu_read_lock(); // rcu lock must be held for rcu trusted field @owner = @mm->owner; // mm_struct::owner is rcu trusted or null if (!@owner) goto out; /* Do something based on the task attribute */ out: bpf_rcu_read_unlock(); Suggested-by: Andrii Nakryiko <[email protected]> Signed-off-by: Yafang Shao <[email protected]> Acked-by: Lorenzo Stoakes <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent c67f4ae commit ec8e3e2

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

kernel/bpf/verifier.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7054,6 +7054,9 @@ BTF_TYPE_SAFE_RCU(struct cgroup_subsys_state) {
70547054
/* RCU trusted: these fields are trusted in RCU CS and can be NULL */
70557055
BTF_TYPE_SAFE_RCU_OR_NULL(struct mm_struct) {
70567056
struct file __rcu *exe_file;
7057+
#ifdef CONFIG_MEMCG
7058+
struct task_struct __rcu *owner;
7059+
#endif
70577060
};
70587061

70597062
/* skb->sk, req->sk are not RCU protected, but we mark them as such

0 commit comments

Comments
 (0)