* [PATCH] bpf: add missing NULL check for __dev_get_by_index
@ 2025-03-08 21:56 Qasim Ijaz
2025-03-09 9:38 ` Markus Elfring
2025-03-09 10:00 ` Alexei Starovoitov
0 siblings, 2 replies; 3+ messages in thread
From: Qasim Ijaz @ 2025-03-08 21:56 UTC (permalink / raw)
To: ast, daniel, andrii
Cc: martin.lau, eddyz87, song, yonghong.song, john.fastabend, kpsingh,
sdf, haoluo, jolsa, bpf, linux-kernel
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@gmail.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);
+ }
+
netdev_lock_ops(offmap->netdev);
down_write(&bpf_devs_lock);
err = bpf_dev_offload_check(offmap->netdev);
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] bpf: add missing NULL check for __dev_get_by_index
2025-03-08 21:56 [PATCH] bpf: add missing NULL check for __dev_get_by_index Qasim Ijaz
@ 2025-03-09 9:38 ` Markus Elfring
2025-03-09 10:00 ` Alexei Starovoitov
1 sibling, 0 replies; 3+ messages in thread
From: Markus Elfring @ 2025-03-09 9:38 UTC (permalink / raw)
To: Qasim Ijaz, bpf
Cc: LKML, Andrii Nakryiko, Alexei Starovoitov, Daniel Borkmann,
Eduard Zingerman, Hao Luo, Jiri Olsa, John Fastabend, KP Singh,
Martin KaFai Lau, Song Liu, Stanislav Fomichev, Yonghong Song
…
> We should handle this case by adding a NULL check
> and cleaning up if it does happened.
Please improve such a change description another bit.
See also:
https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.14-rc5#n94
Regards,
Markus
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] bpf: add missing NULL check for __dev_get_by_index
2025-03-08 21:56 [PATCH] bpf: add missing NULL check for __dev_get_by_index Qasim Ijaz
2025-03-09 9:38 ` Markus Elfring
@ 2025-03-09 10:00 ` Alexei Starovoitov
1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2025-03-09 10:00 UTC (permalink / raw)
To: Qasim Ijaz
Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eddy Z, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf, LKML
On Sat, Mar 8, 2025 at 10:56 PM Qasim Ijaz <qasdev00@gmail.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@gmail.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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-09 10:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-08 21:56 [PATCH] bpf: add missing NULL check for __dev_get_by_index Qasim Ijaz
2025-03-09 9:38 ` Markus Elfring
2025-03-09 10:00 ` Alexei Starovoitov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.