diff options
author | Javier Martinez Canillas <javier@dowhile0.org> | 2012-06-26 18:22:20 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-06-26 18:39:37 -0400 |
commit | 2da049bd5f9b0dbd688519fdb6688a4895fe8395 (patch) | |
tree | 038ad1358269b1883733c0b6e2017ac171b00731 | |
parent | e8abca1f30239f6c979f60df49305a602672cb94 (diff) |
staging: gdm72xx: fix an skb memory leak
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>
-rw-r--r-- | drivers/staging/gdm72xx/netlink_k.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/drivers/staging/gdm72xx/netlink_k.c b/drivers/staging/gdm72xx/netlink_k.c index 9fa432d74364..064815bd3f86 100644 --- a/drivers/staging/gdm72xx/netlink_k.c +++ b/drivers/staging/gdm72xx/netlink_k.c | |||
@@ -126,8 +126,13 @@ int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len) | |||
126 | } | 126 | } |
127 | 127 | ||
128 | seq++; | 128 | seq++; |
129 | nlh = NLMSG_PUT(skb, 0, seq, type, len); | 129 | nlh = nlmsg_put(skb, 0, seq, type, len, 0); |
130 | memcpy(NLMSG_DATA(nlh), msg, len); | 130 | if (!nlh) { |
131 | kfree_skb(skb); | ||
132 | return -EMSGSIZE; | ||
133 | } | ||
134 | |||
135 | memcpy(nlmsg_data(nlh), msg, len); | ||
131 | 136 | ||
132 | NETLINK_CB(skb).pid = 0; | 137 | NETLINK_CB(skb).pid = 0; |
133 | NETLINK_CB(skb).dst_group = 0; | 138 | NETLINK_CB(skb).dst_group = 0; |
@@ -144,6 +149,5 @@ int netlink_send(struct sock *sock, int group, u16 type, void *msg, int len) | |||
144 | ret = 0; | 149 | ret = 0; |
145 | } | 150 | } |
146 | 151 | ||
147 | nlmsg_failure: | ||
148 | return ret; | 152 | return ret; |
149 | } | 153 | } |