Re: [PATCH bpf-next v3] bpf: Silence Coverity warning for find_kfunc_desc_btf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Oct 8, 2021 at 9:09 PM Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx> wrote:
>
> The helper function returns a pointer that in the failure case encodes
> an error in the struct btf pointer. The current code lead to Coverity
> warning about the use of the invalid pointer:
>
>  *** CID 1507963:  Memory - illegal accesses  (USE_AFTER_FREE)
>  /kernel/bpf/verifier.c: 1788 in find_kfunc_desc_btf()
>  1782                          return ERR_PTR(-EINVAL);
>  1783                  }
>  1784
>  1785                  kfunc_btf = __find_kfunc_desc_btf(env, offset, btf_modp);
>  1786                  if (IS_ERR_OR_NULL(kfunc_btf)) {
>  1787                          verbose(env, "cannot find module BTF for func_id %u\n", func_id);
>  >>>      CID 1507963:  Memory - illegal accesses  (USE_AFTER_FREE)
>  >>>      Using freed pointer "kfunc_btf".
>  1788                          return kfunc_btf ?: ERR_PTR(-ENOENT);
>  1789                  }
>  1790                  return kfunc_btf;
>  1791          }
>  1792          return btf_vmlinux ?: ERR_PTR(-ENOENT);
>  1793     }
>
> Daniel suggested the use of ERR_CAST so that the intended use is clear
> to Coverity, but on closer look it seems that we never return NULL from
> the helper. Andrii noted that since __find_kfunc_desc_btf already logs
> errors for all cases except btf_get_by_fd, it is much easier to add
> logging for that and remove the IS_ERR check altogether, returning
> directly from it.
>
> Suggested-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
> Signed-off-by: Kumar Kartikeya Dwivedi <memxor@xxxxxxxxx>
> ---
> v2->v3
>  * Remove unused variable (Kernel Test Robot)
> v1->v2
>  * Remove error check, log btf_get_by_fd failure (Andrii)
> ---

Patch bot missed this one. Applied yesterday to bpf-next. Thanks.

[...]



[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux