bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf] bpf: fix an unitialized value in bpf_iter
@ 2021-02-12  0:59 Yonghong Song
  2021-02-12 21:38 ` Alexei Starovoitov
  0 siblings, 1 reply; 2+ messages in thread
From: Yonghong Song @ 2021-02-12  0:59 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, kernel-team,
	syzbot+580f4f2a272e452d55cb

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.

Reported-by: syzbot+580f4f2a272e452d55cb@syzkaller.appspotmail.com
Fixes: 15d83c4d7cef ("bpf: Allow loading of a bpf_iter program")
Signed-off-by: Yonghong Song <yhs@fb.com>
---
 kernel/bpf/bpf_iter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c
index 5454161407f1..a0d9eade9c80 100644
--- a/kernel/bpf/bpf_iter.c
+++ b/kernel/bpf/bpf_iter.c
@@ -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;
 
-- 
2.24.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH bpf] bpf: fix an unitialized value in bpf_iter
  2021-02-12  0:59 [PATCH bpf] bpf: fix an unitialized value in bpf_iter Yonghong Song
@ 2021-02-12 21:38 ` Alexei Starovoitov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexei Starovoitov @ 2021-02-12 21:38 UTC (permalink / raw)
  To: Yonghong Song
  Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Kernel Team,
	syzbot+580f4f2a272e452d55cb

On Thu, Feb 11, 2021 at 4:59 PM Yonghong Song <yhs@fb.com> wrote:
>
> 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.
>
> Reported-by: syzbot+580f4f2a272e452d55cb@syzkaller.appspotmail.com
> Fixes: 15d83c4d7cef ("bpf: Allow loading of a bpf_iter program")
> Signed-off-by: Yonghong Song <yhs@fb.com>

Though it's a fix it's too late in the cycle.
I've applied to bpf-next.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-02-12 21:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-12  0:59 [PATCH bpf] bpf: fix an unitialized value in bpf_iter Yonghong Song
2021-02-12 21:38 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).