af_netlink: Add needed scm_destroy after scm_send.
authorEric W. Biederman <ebiederm@xmission.com>
Sun, 13 Jun 2010 03:31:06 +0000 (03:31 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 16 Jun 2010 21:55:56 +0000 (14:55 -0700)
scm_send occasionally allocates state in the scm_cookie, so I have
modified netlink_sendmsg to guarantee that when scm_send succeeds
scm_destory will be called to free that state.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
Reviewed-by: Daniel Lezcano <daniel.lezcano@free.fr>
Acked-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/netlink/af_netlink.c

index a2eb965207d339682728b5dd5a52104a8d4f848b..7aeaa83193db96ecb0fb64f5d06db97168a1f9e6 100644 (file)
@@ -1323,19 +1323,23 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
        if (msg->msg_flags&MSG_OOB)
                return -EOPNOTSUPP;
 
-       if (NULL == siocb->scm)
+       if (NULL == siocb->scm) {
                siocb->scm = &scm;
+               memset(&scm, 0, sizeof(scm));
+       }
        err = scm_send(sock, msg, siocb->scm);
        if (err < 0)
                return err;
 
        if (msg->msg_namelen) {
+               err = -EINVAL;
                if (addr->nl_family != AF_NETLINK)
-                       return -EINVAL;
+                       goto out;
                dst_pid = addr->nl_pid;
                dst_group = ffs(addr->nl_groups);
+               err =  -EPERM;
                if (dst_group && !netlink_capable(sock, NL_NONROOT_SEND))
-                       return -EPERM;
+                       goto out;
        } else {
                dst_pid = nlk->dst_pid;
                dst_group = nlk->dst_group;
@@ -1387,6 +1391,7 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
        err = netlink_unicast(sk, skb, dst_pid, msg->msg_flags&MSG_DONTWAIT);
 
 out:
+       scm_destroy(siocb->scm);
        return err;
 }