Blob Blame History Raw
From: Peilin Ye <yepeilin.cs@gmail.com>
Date: Tue, 14 Jul 2020 14:09:04 -0400
Subject: bpf: Fix NULL pointer dereference in __btf_resolve_helper_id()
Patch-mainline: v5.8
Git-commit: 5b801dfb7feb2738975d80223efc2fc193e55573
References: bsc#1177028

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 <yepeilin.cs@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/20200714180904.277512-1-yepeilin.cs@gmail.com
Acked-by: Gary Lin <glin@suse.com>
---
 kernel/bpf/btf.c |    5 +++++
 1 file changed, 5 insertions(+)

--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -4065,6 +4065,11 @@ static int __btf_resolve_helper_id(struc
 	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;