Skip to contentSkip to conversation

net: tipc: fix information leak to userland

PATCH Applied Vasiliy Kulikov 3 participants 5 messages Oct 31, 2010 – Nov 10, 2010

Subsystems (4)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 net: tipc: fix information leak to userland

Structure sockaddr_tipc is copied to userland with padding bytes after "id" field in union field "name" unitialized. It leads to leaking of contents of kernel stack memory. We have to initialize them to zero.

---
 net/tipc/socket.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
net/tipc/socket.c +1 -0
index 33217fc..e9f0d50 100644
@@ -396,6 +396,7 @@ static int get_name(struct socket *sock, struct sockaddr *uaddr,
 	struct sockaddr_tipc *addr = (struct sockaddr_tipc *)uaddr;
 	struct tipc_sock *tsock = tipc_sk(sock->sk);
 
+	memset(addr, 0, sizeof(*addr));
 	if (peer) {
 		if ((sock->state != SS_CONNECTED) &&
 			((peer != 2) || (sock->state != SS_DISCONNECTING)))
Signature · 1 line
1.7.0.4
maintainer Applied
#1 lore raw

From: Vasiliy Kulikov <[email protected]>
Date: Sun, 31 Oct 2010 20:10:32 +0300

Quoted 5 lines

Structure sockaddr_tipc is copied to userland with padding bytes after "id" field in union field "name" unitialized. It leads to leaking of contents of kernel stack memory. We have to initialize them to zero.

Applied.

Patches #1 and #2 were given feedback which I need you to integrate and submit new patches based upon, thanks.

#2 lore raw
Quoted 7 lines · David Miller

From: Vasiliy Kulikov <[email protected]>
Date: Sun, 31 Oct 2010 20:10:32 +0300

Quoted 4 lines

Structure sockaddr_tipc is copied to userland with padding bytes after "id" field in union field "name" unitialized. It leads to leaking of contents of kernel stack memory. We have to initialize them to zero.

Quoted 6 lines
Quoted 1 line

Applied.

Patches #1 and #2 were given feedback which I need you to integrate and submit new patches based upon, thanks.

About #2:

I still think that this:

    if (dev)
        strncpy(uaddr->sa_data, dev->name, 14);
    else
        memset(uaddr->sa_data, 0, 14);

is better than this:

    memset(uaddr->sa_data, 0, 14);
    dev = dev_get_by_index_rcu(sock_net(sk), pkt_sk(sk)->ifindex);
    if (dev)
        strlcpy(uaddr->sa_data, dev->name, 15);

Doesn't it? Explicitly filling with zero on the same "if" level is slightly easier to read and understand.

Signature · 1 line
Vasiliy
#3 lore raw

Am 09.11.2010 21:33, schrieb Vasiliy Kulikov:

Quoted 26 lines · David Miller
Quoted 7 lines

From: Vasiliy Kulikov <[email protected]>
Date: Sun, 31 Oct 2010 20:10:32 +0300

Quoted 4 lines

Structure sockaddr_tipc is copied to userland with padding bytes after "id" field in union field "name" unitialized. It leads to leaking of contents of kernel stack memory. We have to initialize them to zero.

Quoted 6 lines
Quoted 1 line

Applied.

Patches #1 and #2 were given feedback which I need you to integrate and submit new patches based upon, thanks.

About #2:

I still think that this:

    if (dev)
        strncpy(uaddr->sa_data, dev->name, 14);
    else
        memset(uaddr->sa_data, 0, 14);

is better than this:

Quoted 8 lines
    memset(uaddr->sa_data, 0, 14);
    dev = dev_get_by_index_rcu(sock_net(sk), pkt_sk(sk)->ifindex);
    if (dev)
        strlcpy(uaddr->sa_data, dev->name, 15);

Doesn't it? Explicitly filling with zero on the same "if" level is slightly easier to read and understand.

no problem with me, since i came up with the idea a simple explanation:
IMHO the pattern clear/if/copy is more robust

NTL the core problem was that sizeof sa_data is 14 while dev->name is IFNAMESZ.

re,
wh

#4 lore raw
Quoted 1 line · walter harms

NTL the core problem was that sizeof sa_data is 14 while dev->name is IFNAMESZ.

With this code it is NOT a bug because the output buffer is much bigger than 14 (128 bytes). I think it was just designed to overflow 14 bytes, assign sa_data[14] = 0 and ignore it (lack of snprintf() those days?).

Anywhere else sa_data[14] = ... is a bug.

Signature · 1 line
Vasiliy