All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qasim Ijaz <qasdev00@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org
Cc: martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org,
	yonghong.song@linux.dev, john.fastabend@gmail.com,
	kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com,
	jolsa@kernel.org, bpf@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] bpf: add missing NULL check for __dev_get_by_index
Date: Sat,  8 Mar 2025 21:56:05 +0000	[thread overview]
Message-ID: <20250308215605.4774-1-qasdev00@gmail.com> (raw)

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


             reply	other threads:[~2025-03-08 21:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-08 21:56 Qasim Ijaz [this message]
2025-03-09  9:38 ` [PATCH] bpf: add missing NULL check for __dev_get_by_index Markus Elfring
2025-03-09 10:00 ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250308215605.4774-1-qasdev00@gmail.com \
    --to=qasdev00@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=sdf@fomichev.me \
    --cc=song@kernel.org \
    --cc=yonghong.song@linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.