bpf: Fix NULL pointer dereference in __btf_resolve_helper_id()
Subsystems (3)
PATCH 1/1 bpf: Fix NULL pointer dereference in __btf_resolve_helper_id()
Prevent __btf_resolve_helper_id() from dereferencing btf_vmlinux as NULL. This patch fixes the following syzbot bug:
https://syzkaller.appspot.com/bug?id=5edd146856fd513747c1992442732e5a0e9ba355
--- kernel/bpf/btf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/bpf/btf.c +1 -1
@@ -4088,7 +4088,7 @@ static int __btf_resolve_helper_id(struct bpf_verifier_log *log, void *fn,const char *tname, *sym;u32 btf_id, i; -if (IS_ERR (btf_vmlinux)) { +if (IS_ERR_OR_NULL (btf_vmlinux)) {bpf_log (log,"btf_vmlinux is malformed\n" );return -EINVAL ; }
Signature · 1 line
2.25.1
Quoted 17 lines · Peilin Ye
Prevent
__btf_resolve_helper_id()from dereferencingbtf_vmlinuxas NULL. This patch fixes the following syzbot bug:https://syzkaller.appspot.com/bug?id=5edd146856fd513747c1992442732e5a0e9ba355Reported-by [email protected]Signed-off-by Peilin Ye <[email protected]>--- kernel/bpf/btf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)kernel/bpf/btf.c +0
-0
kernel/bpf/btf.c static int __btf_resolve_helper_id(struct bpf_verifier_log *log, void *fn, · line 4092
Quoted 6 lines
kernel/bpf/btf.c +1
-1@@ -4088,7 +4088,7 @@ static int __btf_resolve_helper_id(struct bpf_verifier_log *log, void *fn,const char *tname, *sym;u32 btf_id, i; -if (IS_ERR (btf_vmlinux)) { +if (IS_ERR_OR_NULL (btf_vmlinux)) {bpf_log (log,"btf_vmlinux is malformed\n" );
Can you please split IS_ERR and NULL cases and emit different messages to log? If the kernel is not built with btf_vmlinux, saying that it's "malformed" will confuse people. Thanks.
Quoted 5 lines
kernel/bpf/btf.c +0
-1return -EINVAL ; } --2.25.1
PATCH v2 1/1 bpf: Fix NULL pointer dereference in __btf_resolve_helper_id()
Prevent __btf_resolve_helper_id() from dereferencing btf_vmlinux as NULL. This patch fixes the following syzbot bug:
https://syzkaller.appspot.com/bug?id=5edd146856fd513747c1992442732e5a0e9ba355
---
Thank you for reviewing my patch! I am new to Linux kernel development; would the log message and errno be appropriate for this case?
Change in v2:
- Split NULL and IS_ERR cases.
kernel/bpf/btf.c | 5 +++++ 1 file changed, 5 insertions(+)
kernel/bpf/btf.c +5 -0
@@ -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 ;
Signature · 1 line
2.25.1
Quoted 11 lines · Peilin Ye
Prevent
__btf_resolve_helper_id()from dereferencingbtf_vmlinuxas NULL. This patch fixes the following syzbot bug:https://syzkaller.appspot.com/bug?id=5edd146856fd513747c1992442732e5a0e9ba355Reported-by [email protected]Signed-off-by Peilin Ye <[email protected]>---
Thank you for reviewing my patch! I am new to Linux kernel development; would the log message and errno be appropriate for this case?
I think it's good enough, thanks for the fix.
Quoted 7 lines
Change in v2:
- Split NULL andIS_ERRcases.kernel/bpf/btf.c | 5 +++++ 1 file changed, 5 insertions(+)
[...]
Quoted 7 lines · Andrii Nakryiko
Quoted 5 lines · Peilin Ye
Prevent
__btf_resolve_helper_id()from dereferencingbtf_vmlinuxas NULL. This patch fixes the following syzbot bug:https://syzkaller.appspot.com/bug?id=5edd146856fd513747c1992442732e5a0e9ba355
The link looks wrong?
Nothing in the stack trace indicates this issue.
Quoted 19 lines
Quoted 5 lines
Reported-by [email protected]Signed-off-by Peilin Ye <[email protected]>---
Thank you for reviewing my patch! I am new to Linux kernel development; would the log message and errno be appropriate for this case?I think it's good enough, thanks for the fix.
Acked-by Andrii Nakryiko <[email protected]>Quoted 7 lines
Change in v2:
- Split NULL andIS_ERRcases.kernel/bpf/btf.c | 5 +++++ 1 file changed, 5 insertions(+)[...]
PATCH v3 1/1 bpf: Fix NULL pointer dereference in __btf_resolve_helper_id()
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
---
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(+)
kernel/bpf/btf.c +5 -0
@@ -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 ;
Signature · 6 lines
2.25.1 _______________________________________________ Linux-kernel-mentees mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
Daniel Borkmann
maintainerQuoted 7 lines · Peilin Ye
Prevent
__btf_resolve_helper_id()from dereferencingbtf_vmlinuxas NULL. This patch fixes the following syzbot bug:https://syzkaller.appspot.com/bug?id=f823224ada908fa5c207902a5a62065e53ca0fccReported-by [email protected]Signed-off-by Peilin Ye <[email protected]>
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 29 lines
---
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 andIS_ERRcases.kernel/bpf/btf.c | 5 +++++ 1 file changed, 5 insertions(+)kernel/bpf/btf.c +5
-0@@ -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 ;