* [PATCHv2 bpf] bpf: Check the helper function is valid in get_helper_proto
@ 2025-08-13 13:38 Jiri Olsa
2025-08-13 22:44 ` Andrii Nakryiko
2025-08-14 13:53 ` Paul Chaignon
0 siblings, 2 replies; 5+ messages in thread
From: Jiri Olsa @ 2025-08-13 13:38 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko
Cc: syzbot+a9ed3d9132939852d0df, bpf, linux-perf-users,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, Hao Luo
From: Jiri Olsa <olsajiri@gmail.com>
syzbot reported an verifier bug [1] where the helper func pointer
could be NULL due to disabled config option.
As Alexei suggested we could check on that in get_helper_proto
directly. Excluding tail_call helper from the check, because it
is NULL by design and valid in all configs.
[1] https://lore.kernel.org/bpf/68904050.050a0220.7f033.0001.GAE@google.com/
Reported-by: syzbot+a9ed3d9132939852d0df@syzkaller.appspotmail.com
Suggested-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
v2 changes:
- set bpf_tail_call_proto.func to -1 so we can skip the extra check [Andrii]
kernel/bpf/core.c | 5 ++++-
kernel/bpf/verifier.c | 2 +-
2 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 5d1650af899d..0f6e9a3d9960 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -3024,7 +3024,10 @@ EXPORT_SYMBOL_GPL(bpf_event_output);
/* Always built-in helper functions. */
const struct bpf_func_proto bpf_tail_call_proto = {
- .func = NULL,
+ /* func is unused for tail_call, we set it to pass the
+ * get_helper_proto check
+ */
+ .func = (void *) 1,
.gpl_only = false,
.ret_type = RET_VOID,
.arg1_type = ARG_PTR_TO_CTX,
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index c4f69a9e9af6..c89e2b1bc644 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -11354,7 +11354,7 @@ static int get_helper_proto(struct bpf_verifier_env *env, int func_id,
return -EINVAL;
*ptr = env->ops->get_func_proto(func_id, env->prog);
- return *ptr ? 0 : -EINVAL;
+ return *ptr && (*ptr)->func ? 0 : -EINVAL;
}
static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
--
2.50.1
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCHv2 bpf] bpf: Check the helper function is valid in get_helper_proto
2025-08-13 13:38 [PATCHv2 bpf] bpf: Check the helper function is valid in get_helper_proto Jiri Olsa
@ 2025-08-13 22:44 ` Andrii Nakryiko
2025-08-14 7:29 ` Jiri Olsa
2025-08-14 13:53 ` Paul Chaignon
1 sibling, 1 reply; 5+ messages in thread
From: Andrii Nakryiko @ 2025-08-13 22:44 UTC (permalink / raw)
To: Jiri Olsa
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
syzbot+a9ed3d9132939852d0df, bpf, linux-perf-users,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, Hao Luo
On Wed, Aug 13, 2025 at 6:38 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> From: Jiri Olsa <olsajiri@gmail.com>
>
> syzbot reported an verifier bug [1] where the helper func pointer
> could be NULL due to disabled config option.
>
> As Alexei suggested we could check on that in get_helper_proto
> directly. Excluding tail_call helper from the check, because it
> is NULL by design and valid in all configs.
>
> [1] https://lore.kernel.org/bpf/68904050.050a0220.7f033.0001.GAE@google.com/
> Reported-by: syzbot+a9ed3d9132939852d0df@syzkaller.appspotmail.com
> Suggested-by: Alexei Starovoitov <ast@kernel.org>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> v2 changes:
> - set bpf_tail_call_proto.func to -1 so we can skip the extra check [Andrii]
>
> kernel/bpf/core.c | 5 ++++-
> kernel/bpf/verifier.c | 2 +-
> 2 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> index 5d1650af899d..0f6e9a3d9960 100644
> --- a/kernel/bpf/core.c
> +++ b/kernel/bpf/core.c
> @@ -3024,7 +3024,10 @@ EXPORT_SYMBOL_GPL(bpf_event_output);
>
> /* Always built-in helper functions. */
> const struct bpf_func_proto bpf_tail_call_proto = {
> - .func = NULL,
> + /* func is unused for tail_call, we set it to pass the
> + * get_helper_proto check
> + */
> + .func = (void *) 1,
we seem to have BPF_PTR_POISON in include/linux/poison.h, let's use
that instead of 1?
pw-bot: cr
> .gpl_only = false,
> .ret_type = RET_VOID,
> .arg1_type = ARG_PTR_TO_CTX,
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index c4f69a9e9af6..c89e2b1bc644 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -11354,7 +11354,7 @@ static int get_helper_proto(struct bpf_verifier_env *env, int func_id,
> return -EINVAL;
>
> *ptr = env->ops->get_func_proto(func_id, env->prog);
> - return *ptr ? 0 : -EINVAL;
> + return *ptr && (*ptr)->func ? 0 : -EINVAL;
> }
>
> static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
> --
> 2.50.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCHv2 bpf] bpf: Check the helper function is valid in get_helper_proto
2025-08-13 22:44 ` Andrii Nakryiko
@ 2025-08-14 7:29 ` Jiri Olsa
0 siblings, 0 replies; 5+ messages in thread
From: Jiri Olsa @ 2025-08-14 7:29 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
syzbot+a9ed3d9132939852d0df, bpf, linux-perf-users,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, Hao Luo
On Wed, Aug 13, 2025 at 03:44:43PM -0700, Andrii Nakryiko wrote:
> On Wed, Aug 13, 2025 at 6:38 AM Jiri Olsa <jolsa@kernel.org> wrote:
> >
> > From: Jiri Olsa <olsajiri@gmail.com>
> >
> > syzbot reported an verifier bug [1] where the helper func pointer
> > could be NULL due to disabled config option.
> >
> > As Alexei suggested we could check on that in get_helper_proto
> > directly. Excluding tail_call helper from the check, because it
> > is NULL by design and valid in all configs.
> >
> > [1] https://lore.kernel.org/bpf/68904050.050a0220.7f033.0001.GAE@google.com/
> > Reported-by: syzbot+a9ed3d9132939852d0df@syzkaller.appspotmail.com
> > Suggested-by: Alexei Starovoitov <ast@kernel.org>
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> > v2 changes:
> > - set bpf_tail_call_proto.func to -1 so we can skip the extra check [Andrii]
> >
> > kernel/bpf/core.c | 5 ++++-
> > kernel/bpf/verifier.c | 2 +-
> > 2 files changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
> > index 5d1650af899d..0f6e9a3d9960 100644
> > --- a/kernel/bpf/core.c
> > +++ b/kernel/bpf/core.c
> > @@ -3024,7 +3024,10 @@ EXPORT_SYMBOL_GPL(bpf_event_output);
> >
> > /* Always built-in helper functions. */
> > const struct bpf_func_proto bpf_tail_call_proto = {
> > - .func = NULL,
> > + /* func is unused for tail_call, we set it to pass the
> > + * get_helper_proto check
> > + */
> > + .func = (void *) 1,
>
> we seem to have BPF_PTR_POISON in include/linux/poison.h, let's use
> that instead of 1?
ah I did not know about this macro, thanks
jirka
>
> pw-bot: cr
>
>
> > .gpl_only = false,
> > .ret_type = RET_VOID,
> > .arg1_type = ARG_PTR_TO_CTX,
> > diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> > index c4f69a9e9af6..c89e2b1bc644 100644
> > --- a/kernel/bpf/verifier.c
> > +++ b/kernel/bpf/verifier.c
> > @@ -11354,7 +11354,7 @@ static int get_helper_proto(struct bpf_verifier_env *env, int func_id,
> > return -EINVAL;
> >
> > *ptr = env->ops->get_func_proto(func_id, env->prog);
> > - return *ptr ? 0 : -EINVAL;
> > + return *ptr && (*ptr)->func ? 0 : -EINVAL;
> > }
> >
> > static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
> > --
> > 2.50.1
> >
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCHv2 bpf] bpf: Check the helper function is valid in get_helper_proto
2025-08-13 13:38 [PATCHv2 bpf] bpf: Check the helper function is valid in get_helper_proto Jiri Olsa
2025-08-13 22:44 ` Andrii Nakryiko
@ 2025-08-14 13:53 ` Paul Chaignon
2025-08-14 14:18 ` Jiri Olsa
1 sibling, 1 reply; 5+ messages in thread
From: Paul Chaignon @ 2025-08-14 13:53 UTC (permalink / raw)
To: Jiri Olsa
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
syzbot+a9ed3d9132939852d0df, bpf, linux-perf-users,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, Hao Luo
On Wed, Aug 13, 2025 at 03:38:32PM +0200, Jiri Olsa wrote:
> From: Jiri Olsa <olsajiri@gmail.com>
>
> syzbot reported an verifier bug [1] where the helper func pointer
> could be NULL due to disabled config option.
>
> As Alexei suggested we could check on that in get_helper_proto
> directly. Excluding tail_call helper from the check, because it
> is NULL by design and valid in all configs.
>
> [1] https://lore.kernel.org/bpf/68904050.050a0220.7f033.0001.GAE@google.com/
> Reported-by: syzbot+a9ed3d9132939852d0df@syzkaller.appspotmail.com
The same bug was reported before by the kernel test robot at
https://lore.kernel.org/oe-lkp/202507160818.68358831-lkp@intel.com, so
I guess we'll need:
Reported-by: kernel test robot <oliver.sang@intel.com>
Closes: https://lore.kernel.org/oe-lkp/202507160818.68358831-lkp@intel.com
With that,
Acked-by: Paul Chaignon <paul.chaignon@gmail.com>
[...]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCHv2 bpf] bpf: Check the helper function is valid in get_helper_proto
2025-08-14 13:53 ` Paul Chaignon
@ 2025-08-14 14:18 ` Jiri Olsa
0 siblings, 0 replies; 5+ messages in thread
From: Jiri Olsa @ 2025-08-14 14:18 UTC (permalink / raw)
To: Paul Chaignon
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
syzbot+a9ed3d9132939852d0df, bpf, linux-perf-users,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, Hao Luo
On Thu, Aug 14, 2025 at 03:53:14PM +0200, Paul Chaignon wrote:
> On Wed, Aug 13, 2025 at 03:38:32PM +0200, Jiri Olsa wrote:
> > From: Jiri Olsa <olsajiri@gmail.com>
> >
> > syzbot reported an verifier bug [1] where the helper func pointer
> > could be NULL due to disabled config option.
> >
> > As Alexei suggested we could check on that in get_helper_proto
> > directly. Excluding tail_call helper from the check, because it
> > is NULL by design and valid in all configs.
> >
> > [1] https://lore.kernel.org/bpf/68904050.050a0220.7f033.0001.GAE@google.com/
> > Reported-by: syzbot+a9ed3d9132939852d0df@syzkaller.appspotmail.com
>
> The same bug was reported before by the kernel test robot at
> https://lore.kernel.org/oe-lkp/202507160818.68358831-lkp@intel.com, so
> I guess we'll need:
>
> Reported-by: kernel test robot <oliver.sang@intel.com>
> Closes: https://lore.kernel.org/oe-lkp/202507160818.68358831-lkp@intel.com
>
> With that,
>
> Acked-by: Paul Chaignon <paul.chaignon@gmail.com>
thanks, will fix
jirka
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-14 14:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-13 13:38 [PATCHv2 bpf] bpf: Check the helper function is valid in get_helper_proto Jiri Olsa
2025-08-13 22:44 ` Andrii Nakryiko
2025-08-14 7:29 ` Jiri Olsa
2025-08-14 13:53 ` Paul Chaignon
2025-08-14 14:18 ` Jiri Olsa
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox