[PATCH] bpf: Check the return value of dev_get_by_index_rcu()

From: xiakaixu1987
Date: Thu Nov 19 2020 - 02:06:04 EST


From: Kaixu Xia <kaixuxia@xxxxxxxxxxx>

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@xxxxxxxxxxx>
---
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