Skip to content

Commit 0de4f50

Browse files
kchuyizhouMartin KaFai Lau
authored andcommitted
bpf: Let verifier consider {task,cgroup} is trusted in bpf_iter_reg
BTF_TYPE_SAFE_TRUSTED(struct bpf_iter__task) in verifier.c wanted to teach BPF verifier that bpf_iter__task -> task is a trusted ptr. But it doesn't work well. The reason is, bpf_iter__task -> task would go through btf_ctx_access() which enforces the reg_type of 'task' is ctx_arg_info->reg_type, and in task_iter.c, we actually explicitly declare that the ctx_arg_info->reg_type is PTR_TO_BTF_ID_OR_NULL. Actually we have a previous case like this[1] where PTR_TRUSTED is added to the arg flag for map_iter. This patch sets ctx_arg_info->reg_type is PTR_TO_BTF_ID_OR_NULL | PTR_TRUSTED in task_reg_info. Similarly, bpf_cgroup_reg_info -> cgroup is also PTR_TRUSTED since we are under the protection of cgroup_mutex and we would check cgroup_is_dead() in __cgroup_iter_seq_show(). This patch is to improve the user experience of the newly introduced bpf_iter_css_task kfunc before hitting the mainline. The Fixes tag is pointing to the commit introduced the bpf_iter_css_task kfunc. Link[1]:https://lore.kernel.org/all/20230706133932.45883-3-aspsk@isovalent.com/ Fixes: 9c66dc9 ("bpf: Introduce css_task open-coded iterator kfuncs") Signed-off-by: Chuyi Zhou <zhouchuyi@bytedance.com> Acked-by: Yonghong Song <yonghong.song@linux.dev> Link: https://lore.kernel.org/r/20231107132204.912120-2-zhouchuyi@bytedance.com Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
1 parent d84b139 commit 0de4f50

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
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,

0 commit comments

Comments
 (0)