Skip to content

Commit 8e1b802

Browse files
author
Martin KaFai Lau
committed
Merge branch 'Let BPF verifier consider {task,cgroup} is trusted in bpf_iter_reg'
Chuyi Zhou says: ==================== The patchset aims to let the BPF verivier consider bpf_iter__cgroup->cgroup and bpf_iter__task->task is trusted suggested by Alexei[1]. Please see individual patches for more details. And comments are always welcome. Link[1]:https://lore.kernel.org/bpf/20231022154527.229117-1-zhouchuyi@bytedance.com/T/#mb57725edc8ccdd50a1b165765c7619b4d65ed1b0 v2->v1: * Patch #1: Add Yonghong's ack and add description of similar case in log. * Patch #2: Add Yonghong's ack ==================== Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
2 parents d84b139 + 3c5864b commit 8e1b802

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

kernel/bpf/cgroup_iter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static struct bpf_iter_reg bpf_cgroup_reg_info = {
282282
.ctx_arg_info_size = 1,
283283
.ctx_arg_info = {
284284
{ offsetof(struct bpf_iter__cgroup, cgroup),
285-
PTR_TO_BTF_ID_OR_NULL },
285+
PTR_TO_BTF_ID_OR_NULL | PTR_TRUSTED },
286286
},
287287
.seq_info = &cgroup_iter_seq_info,
288288
};

kernel/bpf/task_iter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ static struct bpf_iter_reg task_reg_info = {
704704
.ctx_arg_info_size = 1,
705705
.ctx_arg_info = {
706706
{ offsetof(struct bpf_iter__task, task),
707-
PTR_TO_BTF_ID_OR_NULL },
707+
PTR_TO_BTF_ID_OR_NULL | PTR_TRUSTED },
708708
},
709709
.seq_info = &task_seq_info,
710710
.fill_link_info = bpf_iter_fill_link_info,

tools/testing/selftests/bpf/progs/iters_css_task.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,9 @@ SEC("?iter/cgroup")
5656
int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
5757
{
5858
struct seq_file *seq = ctx->meta->seq;
59-
struct cgroup *cgrp, *acquired;
59+
struct cgroup *cgrp = ctx->cgroup;
6060
struct cgroup_subsys_state *css;
6161
struct task_struct *task;
62-
u64 cgrp_id;
63-
64-
cgrp = ctx->cgroup;
6562

6663
/* epilogue */
6764
if (cgrp == NULL) {
@@ -73,20 +70,15 @@ int cgroup_id_printer(struct bpf_iter__cgroup *ctx)
7370
if (ctx->meta->seq_num == 0)
7471
BPF_SEQ_PRINTF(seq, "prologue\n");
7572

76-
cgrp_id = cgroup_id(cgrp);
77-
78-
BPF_SEQ_PRINTF(seq, "%8llu\n", cgrp_id);
73+
BPF_SEQ_PRINTF(seq, "%8llu\n", cgroup_id(cgrp));
7974

80-
acquired = bpf_cgroup_from_id(cgrp_id);
81-
if (!acquired)
82-
return 0;
83-
css = &acquired->self;
75+
css = &cgrp->self;
8476
css_task_cnt = 0;
8577
bpf_for_each(css_task, task, css, CSS_TASK_ITER_PROCS) {
8678
if (task->pid == target_pid)
8779
css_task_cnt++;
8880
}
89-
bpf_cgroup_release(acquired);
81+
9082
return 0;
9183
}
9284

0 commit comments

Comments
 (0)