diff mbox

connector: bump skb->users before callback invocation

Message ID 20151231132633.GA30790@breakpoint.cc
State Accepted, archived
Delegated to: David Miller
Headers show

Commit Message

Florian Westphal Dec. 31, 2015, 1:26 p.m. UTC
Dmitry reports memleak with syskaller program.
Problem is that connector bumps skb usecount but might not invoke callback.

So move skb_get to where we invoke the callback.

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
---
 I wonder wth userspace can cram skb->len < NLMSG_HDRLEN
 down the kernel, it seems to beg for trouble...

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

David Miller Jan. 5, 2016, 2:47 a.m. UTC | #1
From: Florian Westphal <fw@strlen.de>
Date: Thu, 31 Dec 2015 14:26:33 +0100

> Dmitry reports memleak with syskaller program.
> Problem is that connector bumps skb usecount but might not invoke callback.
> 
> So move skb_get to where we invoke the callback.
> 
> Reported-by: Dmitry Vyukov <dvyukov@google.com>
> Signed-off-by: Florian Westphal <fw@strlen.de>

Applied and queued up for -stable, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Evgeniy Polyakov Jan. 11, 2016, 8:03 p.m. UTC | #2
Hi everyone

Thanks for fixing and quick pushing of this bug.

05.01.2016, 05:47, "David Miller" <davem@davemloft.net>:
> From: Florian Westphal <fw@strlen.de>
> Date: Thu, 31 Dec 2015 14:26:33 +0100
>
>>  Dmitry reports memleak with syskaller program.
>>  Problem is that connector bumps skb usecount but might not invoke callback.
>>
>>  So move skb_get to where we invoke the callback.
>>
>>  Reported-by: Dmitry Vyukov <dvyukov@google.com>
>>  Signed-off-by: Florian Westphal <fw@strlen.de>
>
> Applied and queued up for -stable, thanks.
diff mbox

Patch

diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c
index d7373ca..25693b0 100644
--- a/drivers/connector/connector.c
+++ b/drivers/connector/connector.c
@@ -179,26 +179,21 @@  static int cn_call_callback(struct sk_buff *skb)
  *
  * It checks skb, netlink header and msg sizes, and calls callback helper.
  */
-static void cn_rx_skb(struct sk_buff *__skb)
+static void cn_rx_skb(struct sk_buff *skb)
 {
 	struct nlmsghdr *nlh;
-	struct sk_buff *skb;
 	int len, err;
 
-	skb = skb_get(__skb);
-
 	if (skb->len >= NLMSG_HDRLEN) {
 		nlh = nlmsg_hdr(skb);
 		len = nlmsg_len(nlh);
 
 		if (len < (int)sizeof(struct cn_msg) ||
 		    skb->len < nlh->nlmsg_len ||
-		    len > CONNECTOR_MAX_MSG_SIZE) {
-			kfree_skb(skb);
+		    len > CONNECTOR_MAX_MSG_SIZE)
 			return;
-		}
 
-		err = cn_call_callback(skb);
+		err = cn_call_callback(skb_get(skb));
 		if (err < 0)
 			kfree_skb(skb);
 	}