login
Header Space

 
 

Re: [PATCH][netlabel] Don't risk NULL ptr deref in netlbl_unlabel_staticlist_gen() if ifindex not found

Previous thread: pull request: wireless-2.6.26 2008-04-16 by John W. Linville on Wednesday, April 16, 2008 - 4:44 pm. (2 messages)

Next thread: Re: Reporting bugs and bisection by Jakub Narebski on Wednesday, April 16, 2008 - 4:55 pm. (1 message)
To: Paul Moore <paul.moore@...>
Cc: <netdev@...>, <linux-kernel@...>, David Miller <davem@...>, Jesper Juhl <jesper.juhl@...>
Date: Wednesday, April 16, 2008 - 5:08 pm

Hi,

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.

Please consider the patch below for inclusion.


Signed-off-by: Jesper Juhl &lt;jesper.juhl@gmail.com&gt;
---

 netlabel_unlabeled.c |    4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/netlabel/netlabel_unlabeled.c b/net/netlabel/netlabel_unlabeled.c
index 4478f2f..6af9457 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,
 
 	if (iface-&gt;ifindex &gt; 0) {
 		dev = dev_get_by_index(&amp;init_net, iface-&gt;ifindex);
+		if (!dev) {
+			ret_val = -ENODEV;
+			goto list_cb_failure;
+		}
 		ret_val = nla_put_string(cb_arg-&gt;skb,
 					 NLBL_UNLABEL_A_IFACE, dev-&gt;name);
 		dev_put(dev);


--
To: Jesper Juhl <jesper.juhl@...>
Cc: <netdev@...>, <linux-kernel@...>, David Miller <davem@...>
Date: Wednesday, April 16, 2008 - 5:21 pm

I agree we should check for NULL here.  I checked the return of 
dev_get_by_index() in the rest of the file I must have just forgotten 
to check it here.

Thanks for finding this and fixing it.


-- 
paul moore
linux @ hp
--
To: Paul Moore <paul.moore@...>
Cc: <netdev@...>, <linux-kernel@...>, David Miller <davem@...>
Date: Wednesday, April 16, 2008 - 5:30 pm

-- 
Jesper Juhl &lt;jesper.juhl@gmail.com&gt;
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
--
To: <jesper.juhl@...>
Cc: <paul.moore@...>, <netdev@...>, <linux-kernel@...>
Date: Friday, April 18, 2008 - 2:23 am

From: "Jesper Juhl" &lt;jesper.juhl@gmail.com&gt;

I've done that, thanks everyone.
--
Previous thread: pull request: wireless-2.6.26 2008-04-16 by John W. Linville on Wednesday, April 16, 2008 - 4:44 pm. (2 messages)

Next thread: Re: Reporting bugs and bisection by Jakub Narebski on Wednesday, April 16, 2008 - 4:55 pm. (1 message)
speck-geostationary