mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-30 06:10:56 +00:00
20c09d92fa
The life time of certain kernel structures like 'struct cgroup' is protected by RCU. Hence it's safe to dereference them directly from __kptr tagged pointers in bpf maps. The resulting pointer is MEM_RCU and can be passed to kfuncs that expect KF_RCU. Derefrence of other kptr-s returns PTR_UNTRUSTED. For example: struct map_value { struct cgroup __kptr *cgrp; }; SEC("tp_btf/cgroup_mkdir") int BPF_PROG(test_cgrp_get_ancestors, struct cgroup *cgrp_arg, const char *path) { struct cgroup *cg, *cg2; cg = bpf_cgroup_acquire(cgrp_arg); // cg is PTR_TRUSTED and ref_obj_id > 0 bpf_kptr_xchg(&v->cgrp, cg); cg2 = v->cgrp; // This is new feature introduced by this patch. // cg2 is PTR_MAYBE_NULL | MEM_RCU. // When cg2 != NULL, it's a valid cgroup, but its percpu_ref could be zero if (cg2) bpf_cgroup_ancestor(cg2, level); // safe to do. } Signed-off-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Acked-by: Tejun Heo <tj@kernel.org> Acked-by: David Vernet <void@manifault.com> Link: https://lore.kernel.org/bpf/20230303041446.3630-4-alexei.starovoitov@gmail.com |
||
---|---|---|
.. | ||
libbpf | ||
bpf_design_QA.rst | ||
bpf_devel_QA.rst | ||
bpf_iterators.rst | ||
bpf_licensing.rst | ||
bpf_prog_run.rst | ||
btf.rst | ||
clang-notes.rst | ||
classic_vs_extended.rst | ||
cpumasks.rst | ||
drgn.rst | ||
faq.rst | ||
graph_ds_impl.rst | ||
helpers.rst | ||
index.rst | ||
instruction-set.rst | ||
kfuncs.rst | ||
linux-notes.rst | ||
llvm_reloc.rst | ||
map_array.rst | ||
map_bloom_filter.rst | ||
map_cgroup_storage.rst | ||
map_cgrp_storage.rst | ||
map_cpumap.rst | ||
map_devmap.rst | ||
map_hash.rst | ||
map_lpm_trie.rst | ||
map_of_maps.rst | ||
map_queue_stack.rst | ||
map_sk_storage.rst | ||
map_sockmap.rst | ||
map_xskmap.rst | ||
maps.rst | ||
other.rst | ||
prog_cgroup_sockopt.rst | ||
prog_cgroup_sysctl.rst | ||
prog_flow_dissector.rst | ||
prog_lsm.rst | ||
prog_sk_lookup.rst | ||
programs.rst | ||
redirect.rst | ||
ringbuf.rst | ||
s390.rst | ||
syscall_api.rst | ||
test_debug.rst | ||
verifier.rst |