Skip to content

Commit b47030c

Browse files
ebiedermdavem330
authored andcommitted
af_netlink: Add needed scm_destroy after scm_send.
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>
1 parent 109f6e3 commit b47030c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

net/netlink/af_netlink.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,19 +1323,23 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
13231323
if (msg->msg_flags&MSG_OOB)
13241324
return -EOPNOTSUPP;
13251325

1326-
if (NULL == siocb->scm)
1326+
if (NULL == siocb->scm) {
13271327
siocb->scm = &scm;
1328+
memset(&scm, 0, sizeof(scm));
1329+
}
13281330
err = scm_send(sock, msg, siocb->scm);
13291331
if (err < 0)
13301332
return err;
13311333

13321334
if (msg->msg_namelen) {
1335+
err = -EINVAL;
13331336
if (addr->nl_family != AF_NETLINK)
1334-
return -EINVAL;
1337+
goto out;
13351338
dst_pid = addr->nl_pid;
13361339
dst_group = ffs(addr->nl_groups);
1340+
err = -EPERM;
13371341
if (dst_group && !netlink_capable(sock, NL_NONROOT_SEND))
1338-
return -EPERM;
1342+
goto out;
13391343
} else {
13401344
dst_pid = nlk->dst_pid;
13411345
dst_group = nlk->dst_group;
@@ -1387,6 +1391,7 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
13871391
err = netlink_unicast(sk, skb, dst_pid, msg->msg_flags&MSG_DONTWAIT);
13881392

13891393
out:
1394+
scm_destroy(siocb->scm);
13901395
return err;
13911396
}
13921397

0 commit comments

Comments
 (0)