bpf: fix an unitialized value in bpf_iter
Subsystems (2)
PATCH 1/1 bpf: fix an unitialized value in bpf_iter
Commit 15d83c4d7cef ("bpf: Allow loading of a bpf_iter program") cached btf_id in struct bpf_iter_target_info so later on if it can be checked cheaply compared to checking registered names.
syzbot found a bug that uninitialized value may occur to bpf_iter_target_info->btf_id. This is because we allocated bpf_iter_target_info structure with kmalloc and never initialized field btf_id afterwards. This uninitialized btf_id is typically compared to a u32 bpf program func proto btf_id, and the chance of being equal is extremely slim.
This patch fixed the issue by using kzalloc which will also prevent future likely instances due to adding new fields.
--- kernel/bpf/bpf_iter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/bpf_iter.c +1 -1
@@ -287,7 +287,7 @@ int bpf_iter_reg_target(const struct bpf_iter_reg *reg_info) {struct bpf_iter_target_info *tinfo; - tinfo =kmalloc (sizeof (*tinfo),GFP_KERNEL ); + tinfo =kzalloc (sizeof (*tinfo),GFP_KERNEL );if (!tinfo)return -ENOMEM ;
Signature · 1 line
2.24.1
Quoted 12 lines · Yonghong Song
Commit
15d83c4d7cef("bpf: Allow loading of abpf_iterprogram") cachedbtf_idin structbpf_iter_target_infoso later on if it can be checked cheaply compared to checking registered names.syzbot found a bug that uninitialized value may occur to
bpf_iter_target_info->btf_id. This is because we allocatedbpf_iter_target_infostructure with kmalloc and never initialized fieldbtf_idafterwards. This uninitializedbtf_idis typically compared to a u32 bpf program func protobtf_id, and the chance of being equal is extremely slim.
Quoted 6 lines
This patch fixed the issue by using kzalloc which will also prevent future likely instances due to adding new fields.
Reported-by [email protected]Fixes 15d83c4d7cef ("bpf: Allow loading of a bpf_iter program")Signed-off-by Yonghong Song <[email protected]>
Though it's a fix it's too late in the cycle.
I've applied to bpf-next.