]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
selftests/bpf: Tweak cgroup kfunc test.
authorAlexei Starovoitov <ast@kernel.org>
Fri, 3 Mar 2023 04:14:45 +0000 (20:14 -0800)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 3 Mar 2023 16:42:20 +0000 (17:42 +0100)
Adjust cgroup kfunc test to dereference RCU protected cgroup pointer
as PTR_TRUSTED and pass into KF_TRUSTED_ARGS kfunc.

Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: David Vernet <void@manifault.com>
Link: https://lore.kernel.org/bpf/20230303041446.3630-6-alexei.starovoitov@gmail.com
tools/testing/selftests/bpf/progs/cgrp_kfunc_success.c

index 42e13aebdd62756999bc591658879ff87a8724ac..030aff70008441d8192e2bc42f4ad5397a343361 100644 (file)
@@ -61,7 +61,7 @@ int BPF_PROG(test_cgrp_acquire_leave_in_map, struct cgroup *cgrp, const char *pa
 SEC("tp_btf/cgroup_mkdir")
 int BPF_PROG(test_cgrp_xchg_release, struct cgroup *cgrp, const char *path)
 {
-       struct cgroup *kptr;
+       struct cgroup *kptr, *cg;
        struct __cgrps_kfunc_map_value *v;
        long status;
 
@@ -80,6 +80,16 @@ int BPF_PROG(test_cgrp_xchg_release, struct cgroup *cgrp, const char *path)
                return 0;
        }
 
+       kptr = v->cgrp;
+       if (!kptr) {
+               err = 4;
+               return 0;
+       }
+
+       cg = bpf_cgroup_ancestor(kptr, 1);
+       if (cg) /* verifier only check */
+               bpf_cgroup_release(cg);
+
        kptr = bpf_kptr_xchg(&v->cgrp, NULL);
        if (!kptr) {
                err = 3;