staging: gdm72xx: fix an skb memory leak
authorJavier Martinez Canillas <javier@dowhile0.org>
Tue, 26 Jun 2012 22:22:20 +0000 (00:22 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 26 Jun 2012 22:39:37 +0000 (15:39 -0700)
The NLMSG_PUT() macro contains a hidden goto that jumps to the
nlmsg_failure label. Since the sk_buff was allocated before the macro,
jumping to the nlmsg_failure label leaks the memory allocated for it.

Calling kfree() before returning would fix it, but is better to avoid
using this error prone macro and use nlmsg_put() instead.

Also, use nlmsg_data() instead of NLMSG_DATA() to check type.

Signed-off-by: Javier Martinez Canillas <javier@dowhile0.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/gdm72xx/netlink_k.c

index 9fa432d7436401afb8eeb5fecf39b5f00b4bf080..064815bd3f8603b489422353de3b34c599b9137f 100644 (file)
@@ -126,8 +126,13 @@ int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len)
        }
 
        seq++;
-       nlh = NLMSG_PUT(skb, 0, seq, type, len);
-       memcpy(NLMSG_DATA(nlh), msg, len);
+       nlh = nlmsg_put(skb, 0, seq, type, len, 0);
+       if (!nlh) {
+               kfree_skb(skb);
+               return -EMSGSIZE;
+       }
+
+       memcpy(nlmsg_data(nlh), msg, len);
 
        NETLINK_CB(skb).pid = 0;
        NETLINK_CB(skb).dst_group = 0;
@@ -144,6 +149,5 @@ int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len)
                ret = 0;
        }
 
-nlmsg_failure:
        return ret;
 }
This page took 0.024572 seconds and 5 git commands to generate.