diff mbox series

[bpf-next] bpf: Fix an error code in check_btf_func()

Message ID 20200603175509.GE18931@mwanda
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series [bpf-next] bpf: Fix an error code in check_btf_func() | expand

Commit Message

Dan Carpenter June 3, 2020, 5:55 p.m. UTC
This code returns success if kcalloc() but it should return -ENOMEM.

Fixes: 8c1b6e69dcc1 ("bpf: Compare BTF types of functions arguments with actual types")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 kernel/bpf/verifier.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Alexei Starovoitov June 3, 2020, 5:57 p.m. UTC | #1
On Wed, Jun 3, 2020 at 10:55 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> This code returns success if kcalloc() but it should return -ENOMEM.
>
> Fixes: 8c1b6e69dcc1 ("bpf: Compare BTF types of functions arguments with actual types")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  kernel/bpf/verifier.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
> index 5c7bbaac81ef9..25363f134bf0c 100644
> --- a/kernel/bpf/verifier.c
> +++ b/kernel/bpf/verifier.c
> @@ -7581,8 +7581,10 @@ static int check_btf_func(struct bpf_verifier_env *env,
>         if (!krecord)
>                 return -ENOMEM;
>         info_aux = kcalloc(nfuncs, sizeof(*info_aux), GFP_KERNEL | __GFP_NOWARN);
> -       if (!info_aux)
> +       if (!info_aux) {
> +               ret = -ENOMEM;
>                 goto err_free;
> +       }

Thanks for the fix.
I think it's better to do 'int ret = -ENOMEM;' instead.
diff mbox series

Patch

diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 5c7bbaac81ef9..25363f134bf0c 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -7581,8 +7581,10 @@  static int check_btf_func(struct bpf_verifier_env *env,
 	if (!krecord)
 		return -ENOMEM;
 	info_aux = kcalloc(nfuncs, sizeof(*info_aux), GFP_KERNEL | __GFP_NOWARN);
-	if (!info_aux)
+	if (!info_aux) {
+		ret = -ENOMEM;
 		goto err_free;
+	}
 
 	for (i = 0; i < nfuncs; i++) {
 		ret = bpf_check_uarg_tail_zero(urecord, krec_size, urec_size);