Patchwork [-next] genetlink: fix possible memory leak in genl_family_rcv_msg()

login
register
mail settings
Submitter Wei Yongjun
Date April 27, 2013, 1:34 a.m.
Message ID <CAPgLHd_tU4suwLY9M1Xoq9osTMcFWMARAaQV=9eodCJ+hZLz-Q@mail.gmail.com>
Download mbox | patch
Permalink /patch/240069/
State Accepted
Delegated to: David Miller
Headers show

Comments

Wei Yongjun - April 27, 2013, 1:34 a.m.
From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

'attrbuf' is malloced in genl_family_rcv_msg() when family->maxattr &&
family->parallel_ops, thus should be freed before leaving from the error
handling cases, otherwise it will cause memory leak.

Introduced by commit def3117493eafd9dfa1f809d861e0031b2cc8a07
(genl: Allow concurrent genl callbacks.)

Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
---
 net/netlink/genetlink.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)


--
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
David Miller - April 27, 2013, 3:26 a.m.
From: Wei Yongjun <weiyj.lk@gmail.com>
Date: Sat, 27 Apr 2013 09:34:16 +0800

> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> 
> 'attrbuf' is malloced in genl_family_rcv_msg() when family->maxattr &&
> family->parallel_ops, thus should be freed before leaving from the error
> handling cases, otherwise it will cause memory leak.
> 
> Introduced by commit def3117493eafd9dfa1f809d861e0031b2cc8a07
> (genl: Allow concurrent genl callbacks.)
> 
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>

Applied, 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

Patch

diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 2f72598..2fd6dbe 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -598,7 +598,7 @@  static int genl_family_rcv_msg(struct genl_family *family,
 		err = nlmsg_parse(nlh, hdrlen, attrbuf, family->maxattr,
 				  ops->policy);
 		if (err < 0)
-			return err;
+			goto out;
 	}
 
 	info.snd_seq = nlh->nlmsg_seq;
@@ -613,7 +613,7 @@  static int genl_family_rcv_msg(struct genl_family *family,
 	if (family->pre_doit) {
 		err = family->pre_doit(ops, skb, &info);
 		if (err)
-			return err;
+			goto out;
 	}
 
 	err = ops->doit(skb, &info);
@@ -621,6 +621,7 @@  static int genl_family_rcv_msg(struct genl_family *family,
 	if (family->post_doit)
 		family->post_doit(ops, skb, &info);
 
+out:
 	if (family->parallel_ops)
 		kfree(attrbuf);