Thread (7 messages) 7 messages, 4 authors, 2020-07-15

Re: [Linux-kernel-mentees] [PATCH v3] bpf: Fix NULL pointer dereference in __btf_resolve_helper_id()

From: Daniel Borkmann <daniel@iogearbox.net>
Date: 2020-07-15 21:07:27
Also in: bpf, lkml, netdev

On 7/14/20 8:09 PM, Peilin Ye wrote:
Prevent __btf_resolve_helper_id() from dereferencing `btf_vmlinux`
as NULL. This patch fixes the following syzbot bug:

     https://syzkaller.appspot.com/bug?id=f823224ada908fa5c207902a5a62065e53ca0fcc

Reported-by: syzbot+ee09bda7017345f1fbe6@syzkaller.appspotmail.com
Signed-off-by: Peilin Ye <redacted>
Looks good, applied, thanks! As far as I can tell all the other occurrences are
gated behind btf_parse_vmlinux() where we also init struct_opts, etc.

So for bpf-next this would then end up looking like ...

int btf_resolve_helper_id(struct bpf_verifier_log *log,
                           const struct bpf_func_proto *fn, int arg)
{
         int id;

         if (fn->arg_type[arg] != ARG_PTR_TO_BTF_ID)
                 return -EINVAL;
         id = fn->btf_id[arg];
         if (!id || !btf_vmlinux || id > btf_vmlinux->nr_types)
                 return -EINVAL;
         return id;
}
quoted hunk ↗ jump to hunk
---
Sorry, I got the link wrong. Thank you for pointing that out.

Change in v3:
     - Fix incorrect syzbot dashboard link.

Change in v2:
     - Split NULL and IS_ERR cases.

  kernel/bpf/btf.c | 5 +++++
  1 file changed, 5 insertions(+)
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 30721f2c2d10..092116a311f4 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -4088,6 +4088,11 @@ static int __btf_resolve_helper_id(struct bpf_verifier_log *log, void *fn,
  	const char *tname, *sym;
  	u32 btf_id, i;
  
+	if (!btf_vmlinux) {
+		bpf_log(log, "btf_vmlinux doesn't exist\n");
+		return -EINVAL;
+	}
+
  	if (IS_ERR(btf_vmlinux)) {
  		bpf_log(log, "btf_vmlinux is malformed\n");
  		return -EINVAL;
_______________________________________________
Linux-kernel-mentees mailing list
Linux-kernel-mentees@lists.linuxfoundation.org
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help