[PATCH] caif: Do not dereference NULL in chnl_recv_cb()

Subsystems: networking [general], the rest

STALE5094d

3 messages, 3 authors, 2012-08-20 · open the first message on its own page

[PATCH] caif: Do not dereference NULL in chnl_recv_cb()

From: Jesper Juhl <hidden>
Date: 2012-08-17 20:33:22

In net/caif/chnl_net.c::chnl_recv_cb() we call skb_header_pointer()
which may return NULL, but we do not check for a NULL pointer before
dereferencing it.
This patch adds such a NULL check and properly free's allocated memory
and return an error (-EINVAL) on failure - much better than crashing..

Signed-off-by: Jesper Juhl <redacted>
---
 net/caif/chnl_net.c | 4 ++++
 1 file changed, 4 insertions(+)

 Note: compile tested only.
diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
index 69771c0..e597733 100644
--- a/net/caif/chnl_net.c
+++ b/net/caif/chnl_net.c
@@ -94,6 +94,10 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
 
 	/* check the version of IP */
 	ip_version = skb_header_pointer(skb, 0, 1, &buf);
+	if (!ip_version) {
+		kfree_skb(skb);
+		return -EINVAL;
+	}
 
 	switch (*ip_version >> 4) {
 	case 4:
-- 
1.7.11.4


-- 
Jesper Juhl <jj@chaosbits.net>       http://www.chaosbits.net/
Don't top-post http://www.catb.org/jargon/html/T/top-post.html
Plain text mails only, please.

RE: [PATCH] caif: Do not dereference NULL in chnl_recv_cb()

From: Sjur BRENDELAND <hidden>
Date: 2012-08-20 06:33:25

In net/caif/chnl_net.c::chnl_recv_cb() we call skb_header_pointer()
which may return NULL, but we do not check for a NULL pointer before
dereferencing it.
This patch adds such a NULL check and properly free's allocated memory
and return an error (-EINVAL) on failure - much better than crashing..

Signed-off-by: Jesper Juhl <redacted>
Thank you for fixing this, the patch looks good to me.
Acked-by: Sjur Brændeland <redacted>

Re: [PATCH] caif: Do not dereference NULL in chnl_recv_cb()

From: David Miller <davem@davemloft.net>
Date: 2012-08-20 09:48:10

From: Sjur BRENDELAND <redacted>
Date: Mon, 20 Aug 2012 08:33:35 +0200
quoted
In net/caif/chnl_net.c::chnl_recv_cb() we call skb_header_pointer()
which may return NULL, but we do not check for a NULL pointer before
dereferencing it.
This patch adds such a NULL check and properly free's allocated memory
and return an error (-EINVAL) on failure - much better than crashing..

Signed-off-by: Jesper Juhl <redacted>
Thank you for fixing this, the patch looks good to me.
Acked-by: Sjur Brændeland <redacted>
Applied, thanks.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help