Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758914Ab2HQUdW (ORCPT ); Fri, 17 Aug 2012 16:33:22 -0400 Received: from 1010ds2-suoe.0.fullrate.dk ([90.184.90.115]:11882 "EHLO swampdragon.chaosbits.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754411Ab2HQUdP (ORCPT ); Fri, 17 Aug 2012 16:33:15 -0400 Date: Fri, 17 Aug 2012 22:33:12 +0200 (CEST) From: Jesper Juhl To: linux-kernel@vger.kernel.org cc: netdev@vger.kernel.org, "David S. Miller" , Sjur Braendeland , Daniel Martensson Subject: [PATCH] caif: Do not dereference NULL in chnl_recv_cb() Message-ID: User-Agent: Alpine 2.00 (LNX 1167 2008-08-23) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1275 Lines: 42 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 --- 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 http://www.chaosbits.net/ Don't top-post http://www.catb.org/jargon/html/T/top-post.html Plain text mails only, please. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/