Skip to content

Commit e0e3cea

Browse files
edumazetdavem330
authored andcommitted
af_netlink: force credentials passing [CVE-2012-3520]
Pablo Neira Ayuso discovered that avahi and potentially NetworkManager accept spoofed Netlink messages because of a kernel bug. The kernel passes all-zero SCM_CREDENTIALS ancillary data to the receiver if the sender did not provide such data, instead of not including any such data at all or including the correct data from the peer (as it is the case with AF_UNIX). This bug was introduced in commit 16e5726 (af_unix: dont send SCM_CREDENTIALS by default) This patch forces passing credentials for netlink, as before the regression. Another fix would be to not add SCM_CREDENTIALS in netlink messages if not provided by the sender, but it might break some programs. With help from Florian Weimer & Petr Matousek This issue is designated as CVE-2012-3520 Signed-off-by: Eric Dumazet <[email protected]> Cc: Petr Matousek <[email protected]> Cc: Florian Weimer <[email protected]> Cc: Pablo Neira Ayuso <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent a9915a1 commit e0e3cea

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

include/net/scm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,11 @@ static __inline__ void scm_destroy(struct scm_cookie *scm)
7070
}
7171

7272
static __inline__ int scm_send(struct socket *sock, struct msghdr *msg,
73-
struct scm_cookie *scm)
73+
struct scm_cookie *scm, bool forcecreds)
7474
{
7575
memset(scm, 0, sizeof(*scm));
76+
if (forcecreds)
77+
scm_set_cred(scm, task_tgid(current), current_cred());
7678
unix_get_peersec_dgram(sock, scm);
7779
if (msg->msg_controllen <= 0)
7880
return 0;

net/netlink/af_netlink.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,7 @@ static int netlink_sendmsg(struct kiocb *kiocb, struct socket *sock,
13621362
if (NULL == siocb->scm)
13631363
siocb->scm = &scm;
13641364

1365-
err = scm_send(sock, msg, siocb->scm);
1365+
err = scm_send(sock, msg, siocb->scm, true);
13661366
if (err < 0)
13671367
return err;
13681368

net/unix/af_unix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,7 +1450,7 @@ static int unix_dgram_sendmsg(struct kiocb *kiocb, struct socket *sock,
14501450
if (NULL == siocb->scm)
14511451
siocb->scm = &tmp_scm;
14521452
wait_for_unix_gc();
1453-
err = scm_send(sock, msg, siocb->scm);
1453+
err = scm_send(sock, msg, siocb->scm, false);
14541454
if (err < 0)
14551455
return err;
14561456

@@ -1619,7 +1619,7 @@ static int unix_stream_sendmsg(struct kiocb *kiocb, struct socket *sock,
16191619
if (NULL == siocb->scm)
16201620
siocb->scm = &tmp_scm;
16211621
wait_for_unix_gc();
1622-
err = scm_send(sock, msg, siocb->scm);
1622+
err = scm_send(sock, msg, siocb->scm, false);
16231623
if (err < 0)
16241624
return err;
16251625

0 commit comments

Comments
 (0)