Files
lkl_linux/include/linux
Alexei Starovoitov 20c09d92fa bpf: Introduce kptr_rcu.
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
2023-03-03 17:42:20 +01:00
..
2023-01-16 09:26:05 +01:00
2022-11-04 12:59:25 +02:00
2022-12-11 21:25:58 +01:00
2023-01-11 06:52:43 -05:00
2023-02-01 17:29:30 +01:00
2023-02-13 18:51:35 +02:00
2023-02-16 21:23:52 +00:00
2023-01-09 17:00:54 +01:00
2023-02-15 19:38:50 +01:00
2023-01-19 14:46:25 +01:00
2022-12-07 09:43:12 -07:00
2023-03-01 09:55:24 -08:00
2023-03-03 17:42:20 +01:00
2023-02-03 08:20:55 -07:00
2023-01-13 11:48:15 +01:00
2022-11-18 09:14:10 +01:00
2022-12-11 18:12:17 -08:00
2023-01-29 15:18:33 -07:00
2023-01-29 15:18:33 -07:00
2023-01-19 09:24:28 +01:00
2023-01-11 06:52:43 -05:00
2022-10-24 12:30:26 +03:00
2023-01-17 09:29:59 +01:00
2022-11-11 18:18:05 -08:00
2023-01-19 09:24:28 +01:00
2023-02-15 19:38:53 +01:00
2022-11-15 00:42:02 -08:00
2022-12-11 19:30:20 -08:00
2023-02-13 10:11:20 +02:00
2023-01-19 09:24:28 +01:00
2023-01-19 09:24:28 +01:00
2023-01-19 09:24:30 +01:00
2023-01-19 09:24:30 +01:00
2023-01-16 09:26:06 +01:00
2023-01-04 14:44:13 -07:00
2023-01-19 09:24:28 +01:00
2022-12-20 03:13:45 +01:00
2022-10-23 18:06:54 -04:00
2023-01-19 09:24:28 +01:00
2023-01-03 17:49:22 -08:00
2022-12-10 13:36:05 -05:00
2023-01-13 11:48:16 +01:00
2023-01-08 20:59:17 -07:00
2023-01-19 09:24:28 +01:00
2022-10-24 12:12:32 -07:00