Re: [PATCH] bpf, libbpf: Smatch: Fix potential NULL pointer dereference

From: Yonghong Song
Date: Tue Jul 02 2019 - 11:35:01 EST




On 7/2/19 3:25 AM, Leo Yan wrote:
> Based on the following report from Smatch, fix the potential
> NULL pointer dereference check.
>
> tools/lib/bpf/libbpf.c:3493
> bpf_prog_load_xattr() warn: variable dereferenced before check 'attr'
> (see line 3483)
>
> 3479 int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr,
> 3480 struct bpf_object **pobj, int *prog_fd)
> 3481 {
> 3482 struct bpf_object_open_attr open_attr = {
> 3483 .file = attr->file,
> 3484 .prog_type = attr->prog_type,
> ^^^^^^
> 3485 };
>
> At the head of function, it directly access 'attr' without checking if
> it's NULL pointer. This patch moves the values assignment after
> validating 'attr' and 'attr->file'.
>
> Signed-off-by: Leo Yan <leo.yan@xxxxxxxxxx>

Acked-by: Yonghong Song <yhs@xxxxxx>