Skip to content

Commit

Permalink
[NETLABEL]: Fix NULL deref in netlbl_unlabel_staticlist_gen() if ifin…
Browse files Browse the repository at this point in the history
…dex 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>
  • Loading branch information
Jesper Juhl authored and David S. Miller committed Apr 18, 2008
1 parent f5ba2d3 commit 794eb6b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions net/netlabel/netlabel_unlabeled.c
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,10 @@ static int netlbl_unlabel_staticlist_gen(u32 cmd,

if (iface->ifindex > 0) {
dev = dev_get_by_index(&init_net, iface->ifindex);
if (!dev) {
ret_val = -ENODEV;
goto list_cb_failure;
}
ret_val = nla_put_string(cb_arg->skb,
NLBL_UNLABEL_A_IFACE, dev->name);
dev_put(dev);
Expand Down

0 comments on commit 794eb6b

Please sign in to comment.