aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesper Juhl <jesper.juhl@gmail.com>2008-04-18 02:22:54 -0400
committerDavid S. Miller <davem@davemloft.net>2008-04-18 02:22:54 -0400
commit794eb6bf20ebf992c040ea831cd3a9c64b0c1f7a (patch)
tree41d710fe62265b95b2e3e0cd9fa49d5ffe65fb81
parentf5ba2d32170679eb9b7c251ac3d9687916a41c18 (diff)
[NETLABEL]: Fix NULL deref in netlbl_unlabel_staticlist_gen() if ifindex not found
dev_get_by_index() may return NULL if nothing is found. In net/netlabel/netlabel_unlabeled.c::netlbl_unlabel_staticlist_gen() the function is called, but the return value is never checked. If it returns NULL then we'll deref a NULL pointer on the very next line. I checked the callers, and I don't think this can actually happen today, but code changes over time and in the future it might happen and it does no harm to be defensive and check for the failure, so that if/when it happens we'll fail gracefully instead of crashing. Signed-off-by: Jesper Juhl <jesper.juhl@gmail.com> Acked-by: Paul Moore <paul.moore@hp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/netlabel/netlabel_unlabeled.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c
index a547c6320eb3..d282ad1570a7 100644
--- a/net/netlabel/netlabel_unlabeled.c
+++ b/net/netlabel/netlabel_unlabeled.c
@@ -1339,6 +1339,10 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd,
1339 1339
1340 if (iface->ifindex > 0) { 1340 if (iface->ifindex > 0) {
1341 dev = dev_get_by_index(&init_net, iface->ifindex); 1341 dev = dev_get_by_index(&init_net, iface->ifindex);
1342 if (!dev) {
1343 ret_val = -ENODEV;
1344 goto list_cb_failure;
1345 }
1342 ret_val = nla_put_string(cb_arg->skb, 1346 ret_val = nla_put_string(cb_arg->skb,
1343 NLBL_UNLABEL_A_IFACE, dev->name); 1347 NLBL_UNLABEL_A_IFACE, dev->name);
1344 dev_put(dev); 1348 dev_put(dev);