netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] bpf: Check the return value of dev_get_by_index_rcu()
@ 2020-11-19  7:04 xiakaixu1987
  2020-11-20 15:13 ` Daniel Borkmann
  0 siblings, 1 reply; 4+ messages in thread
From: xiakaixu1987 @ 2020-11-19  7:04 UTC (permalink / raw)
  To: ast, daniel, kafai, songliubraving, yhs, andrii, john.fastabend, kpsingh
  Cc: netdev, bpf, linux-kernel, Kaixu Xia

From: Kaixu Xia <kaixuxia@tencent.com>

The return value of dev_get_by_index_rcu() can be NULL, so here it
is need to check the return value and return error code if it is NULL.

Signed-off-by: Kaixu Xia <kaixuxia@tencent.com>
---
 net/core/filter.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/core/filter.c b/net/core/filter.c
index 2ca5eecebacf..1263fe07170a 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5573,6 +5573,8 @@ BPF_CALL_4(bpf_skb_fib_lookup, struct sk_buff *, skb,
 		struct net_device *dev;
 
 		dev = dev_get_by_index_rcu(net, params->ifindex);
+		if (unlikely(!dev))
+			return -EINVAL;
 		if (!is_skb_forwardable(dev, skb))
 			rc = BPF_FIB_LKUP_RET_FRAG_NEEDED;
 	}
-- 
2.20.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-20 16:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-19  7:04 [PATCH] bpf: Check the return value of dev_get_by_index_rcu() xiakaixu1987
2020-11-20 15:13 ` Daniel Borkmann
2020-11-20 15:19   ` David Ahern
2020-11-20 16:01     ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).