genetlink: fix possible memory leak in genl_family_rcv_msg()
authorWei Yongjun <yongjun_wei@trendmicro.com.cn>
Fri, 26 Apr 2013 15:34:16 +0000 (15:34 +0000)
committerDavid S. Miller <davem@davemloft.net>
Sat, 27 Apr 2013 03:25:39 +0000 (23:25 -0400)
'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>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/netlink/genetlink.c

index 2f72598dd8feb6166c42f40a05d30a2c15f60695..2fd6dbea327a8b39d2ec0ed10b927d74bcdab408 100644 (file)
@@ -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);