]>
Commit | Line | Data |
---|---|---|
a9fba688 SL |
1 | From 945e7404a83d79f1afac000f7f504054bab01f0c Mon Sep 17 00:00:00 2001 |
2 | From: Xin Long <lucien.xin@gmail.com> | |
3 | Date: Sun, 31 Mar 2019 16:58:15 +0800 | |
4 | Subject: sctp: initialize _pad of sockaddr_in before copying to user memory | |
5 | ||
6 | [ Upstream commit 09279e615c81ce55e04835970601ae286e3facbe ] | |
7 | ||
8 | Syzbot report a kernel-infoleak: | |
9 | ||
10 | BUG: KMSAN: kernel-infoleak in _copy_to_user+0x16b/0x1f0 lib/usercopy.c:32 | |
11 | Call Trace: | |
12 | _copy_to_user+0x16b/0x1f0 lib/usercopy.c:32 | |
13 | copy_to_user include/linux/uaccess.h:174 [inline] | |
14 | sctp_getsockopt_peer_addrs net/sctp/socket.c:5911 [inline] | |
15 | sctp_getsockopt+0x1668e/0x17f70 net/sctp/socket.c:7562 | |
16 | ... | |
17 | Uninit was stored to memory at: | |
18 | sctp_transport_init net/sctp/transport.c:61 [inline] | |
19 | sctp_transport_new+0x16d/0x9a0 net/sctp/transport.c:115 | |
20 | sctp_assoc_add_peer+0x532/0x1f70 net/sctp/associola.c:637 | |
21 | sctp_process_param net/sctp/sm_make_chunk.c:2548 [inline] | |
22 | sctp_process_init+0x1a1b/0x3ed0 net/sctp/sm_make_chunk.c:2361 | |
23 | ... | |
24 | Bytes 8-15 of 16 are uninitialized | |
25 | ||
26 | It was caused by that th _pad field (the 8-15 bytes) of a v4 addr (saved in | |
27 | struct sockaddr_in) wasn't initialized, but directly copied to user memory | |
28 | in sctp_getsockopt_peer_addrs(). | |
29 | ||
30 | So fix it by calling memset(addr->v4.sin_zero, 0, 8) to initialize _pad of | |
31 | sockaddr_in before copying it to user memory in sctp_v4_addr_to_user(), as | |
32 | sctp_v6_addr_to_user() does. | |
33 | ||
34 | Reported-by: syzbot+86b5c7c236a22616a72f@syzkaller.appspotmail.com | |
35 | Signed-off-by: Xin Long <lucien.xin@gmail.com> | |
36 | Tested-by: Alexander Potapenko <glider@google.com> | |
37 | Acked-by: Neil Horman <nhorman@tuxdriver.com> | |
38 | Signed-off-by: David S. Miller <davem@davemloft.net> | |
39 | Signed-off-by: Sasha Levin <sashal@kernel.org> | |
40 | --- | |
41 | net/sctp/protocol.c | 1 + | |
42 | 1 file changed, 1 insertion(+) | |
43 | ||
44 | diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c | |
45 | index 1c9f079e8a50..d97b2b4b7a8b 100644 | |
46 | --- a/net/sctp/protocol.c | |
47 | +++ b/net/sctp/protocol.c | |
48 | @@ -600,6 +600,7 @@ static struct sock *sctp_v4_create_accept_sk(struct sock *sk, | |
49 | static int sctp_v4_addr_to_user(struct sctp_sock *sp, union sctp_addr *addr) | |
50 | { | |
51 | /* No address mapping for V4 sockets */ | |
52 | + memset(addr->v4.sin_zero, 0, sizeof(addr->v4.sin_zero)); | |
53 | return sizeof(struct sockaddr_in); | |
54 | } | |
55 | ||
56 | -- | |
57 | 2.19.1 | |
58 |