[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAADnVQJXH7M0uhsswbWq1RjNv-h5e2M_6AtWd-1TazBo+QTgUg@mail.gmail.com>
Date: Sun, 9 Mar 2025 11:00:15 +0100
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Qasim Ijaz <qasdev00@...il.com>
Cc: Alexei Starovoitov <ast@...nel.org>, Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>, Martin KaFai Lau <martin.lau@...ux.dev>, Eddy Z <eddyz87@...il.com>,
Song Liu <song@...nel.org>, Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>, KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>, Hao Luo <haoluo@...gle.com>, Jiri Olsa <jolsa@...nel.org>,
bpf <bpf@...r.kernel.org>, LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] bpf: add missing NULL check for __dev_get_by_index
On Sat, Mar 8, 2025 at 10:56 PM Qasim Ijaz <qasdev00@...il.com> wrote:
>
> The __dev_get_by_index function can return NULL if it fails to
> find a device with the provided ifindex.
>
> We should handle this case by adding a NULL check
> and cleaning up if it does happened.
>
> Signed-off-by: Qasim Ijaz <qasdev00@...il.com>
> Fixes: a38845729ea3 ("bpf: offload: add map offload infrastructure")
> ---
> kernel/bpf/offload.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c
> index a10153c3be2d..28a30fa4457a 100644
> --- a/kernel/bpf/offload.c
> +++ b/kernel/bpf/offload.c
> @@ -530,6 +530,12 @@ struct bpf_map *bpf_map_offload_map_alloc(union bpf_attr *attr)
> bpf_map_init_from_attr(&offmap->map, attr);
> rtnl_lock();
> offmap->netdev = __dev_get_by_index(net, attr->map_ifindex);
> + if (!offmap->netdev) {
> + rtnl_unlock();
> + bpf_map_area_free(offmap);
> + return ERR_PTR(-ENODEV);
> + }
1. you're using some old git tree.
there is no such code in bpf_map_offload_map_alloc().
2. The actual code has bpf_dev_offload_check(offmap->netdev)
that does the NULL check already.
pw-bot: cr
> +
> netdev_lock_ops(offmap->netdev);
> down_write(&bpf_devs_lock);
> err = bpf_dev_offload_check(offmap->netdev);
> --
> 2.39.5
>
Powered by blists - more mailing lists