Skip to content

Commit 60085c3

Browse files
miniplidavem330
authored andcommitted
tipc: fix info leaks via msg_name in recv_msg/recv_stream
The code in set_orig_addr() does not initialize all of the members of struct sockaddr_tipc when filling the sockaddr info -- namely the union is only partly filled. This will make recv_msg() and recv_stream() -- the only users of this function -- leak kernel stack memory as the msg_name member is a local variable in net/socket.c. Additionally to that both recv_msg() and recv_stream() fail to update the msg_namelen member to 0 while otherwise returning with 0, i.e. "success". This is the case for, e.g., non-blocking sockets. This will lead to a 128 byte kernel stack leak in net/socket.c. Fix the first issue by initializing the memory of the union with memset(0). Fix the second one by setting msg_namelen to 0 early as it will be updated later if we're going to fill the msg_name member. Cc: Jon Maloy <jon.maloy@ericsson.com> Cc: Allan Stephens <allan.stephens@windriver.com> Signed-off-by: Mathias Krause <minipli@googlemail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 4a18423 commit 60085c3

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Diff for: net/tipc/socket.c

+7
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,7 @@ static void set_orig_addr(struct msghdr *m, struct tipc_msg *msg)
790790
if (addr) {
791791
addr->family = AF_TIPC;
792792
addr->addrtype = TIPC_ADDR_ID;
793+
memset(&addr->addr, 0, sizeof(addr->addr));
793794
addr->addr.id.ref = msg_origport(msg);
794795
addr->addr.id.node = msg_orignode(msg);
795796
addr->addr.name.domain = 0; /* could leave uninitialized */
@@ -904,6 +905,9 @@ static int recv_msg(struct kiocb *iocb, struct socket *sock,
904905
goto exit;
905906
}
906907

908+
/* will be updated in set_orig_addr() if needed */
909+
m->msg_namelen = 0;
910+
907911
timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
908912
restart:
909913

@@ -1013,6 +1017,9 @@ static int recv_stream(struct kiocb *iocb, struct socket *sock,
10131017
goto exit;
10141018
}
10151019

1020+
/* will be updated in set_orig_addr() if needed */
1021+
m->msg_namelen = 0;
1022+
10161023
target = sock_rcvlowat(sk, flags & MSG_WAITALL, buf_len);
10171024
timeout = sock_rcvtimeo(sk, flags & MSG_DONTWAIT);
10181025

0 commit comments

Comments
 (0)