[PATCH bpf-next v2 23/26] bpf: Handle allocation failure in acquire_lock_state

Kumar Kartikeya Dwivedi posted 26 patches 10 months, 1 week ago
There is a newer version of this series
[PATCH bpf-next v2 23/26] bpf: Handle allocation failure in acquire_lock_state
Posted by Kumar Kartikeya Dwivedi 10 months, 1 week ago
The acquire_lock_state function needs to handle possible NULL values
returned by acquire_reference_state, and return -ENOMEM.

Fixes: 769b0f1c8214 ("bpf: Refactor {acquire,release}_reference_state")
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
 kernel/bpf/verifier.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 9971c03adfd5..d6999d085c7d 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -1501,6 +1501,8 @@ static int acquire_lock_state(struct bpf_verifier_env *env, int insn_idx, enum r
 	struct bpf_reference_state *s;
 
 	s = acquire_reference_state(env, insn_idx);
+	if (!s)
+		return -ENOMEM;
 	s->type = type;
 	s->id = id;
 	s->ptr = ptr;
-- 
2.43.5
Re: [PATCH bpf-next v2 23/26] bpf: Handle allocation failure in acquire_lock_state
Posted by Alexei Starovoitov 10 months, 1 week ago
On Thu, Feb 6, 2025 at 2:55 AM Kumar Kartikeya Dwivedi <memxor@gmail.com> wrote:
>
> The acquire_lock_state function needs to handle possible NULL values
> returned by acquire_reference_state, and return -ENOMEM.
>
> Fixes: 769b0f1c8214 ("bpf: Refactor {acquire,release}_reference_state")
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
> ---
>  kernel/bpf/verifier.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 9971c03adfd5..d6999d085c7d 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -1501,6 +1501,8 @@ static int acquire_lock_state(struct bpf_verifier_env *env, int insn_idx, enum r
>         struct bpf_reference_state *s;
>
>         s = acquire_reference_state(env, insn_idx);
> +       if (!s)
> +               return -ENOMEM;

I'll grab this fix into bpf tree.
Next time just send it separately, so the fix is not lost
in the patch bomb.