]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.4.172/tipc-fix-uninit-value-in-tipc_nl_compat_link_reset_stats.patch
4.14-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.4.172 / tipc-fix-uninit-value-in-tipc_nl_compat_link_reset_stats.patch
1 From 8b66fee7f8ee18f9c51260e7a43ab37db5177a05 Mon Sep 17 00:00:00 2001
2 From: Ying Xue <ying.xue@windriver.com>
3 Date: Mon, 14 Jan 2019 17:22:25 +0800
4 Subject: tipc: fix uninit-value in tipc_nl_compat_link_reset_stats
5
6 From: Ying Xue <ying.xue@windriver.com>
7
8 commit 8b66fee7f8ee18f9c51260e7a43ab37db5177a05 upstream.
9
10 syzbot reports following splat:
11
12 BUG: KMSAN: uninit-value in strlen+0x3b/0xa0 lib/string.c:486
13 CPU: 1 PID: 11057 Comm: syz-executor0 Not tainted 4.20.0-rc7+ #2
14 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
15 Call Trace:
16 __dump_stack lib/dump_stack.c:77 [inline]
17 dump_stack+0x173/0x1d0 lib/dump_stack.c:113
18 kmsan_report+0x12e/0x2a0 mm/kmsan/kmsan.c:613
19 __msan_warning+0x82/0xf0 mm/kmsan/kmsan_instr.c:295
20 strlen+0x3b/0xa0 lib/string.c:486
21 nla_put_string include/net/netlink.h:1154 [inline]
22 tipc_nl_compat_link_reset_stats+0x1f0/0x360 net/tipc/netlink_compat.c:760
23 __tipc_nl_compat_doit net/tipc/netlink_compat.c:311 [inline]
24 tipc_nl_compat_doit+0x3aa/0xaf0 net/tipc/netlink_compat.c:344
25 tipc_nl_compat_handle net/tipc/netlink_compat.c:1107 [inline]
26 tipc_nl_compat_recv+0x14d7/0x2760 net/tipc/netlink_compat.c:1210
27 genl_family_rcv_msg net/netlink/genetlink.c:601 [inline]
28 genl_rcv_msg+0x185f/0x1a60 net/netlink/genetlink.c:626
29 netlink_rcv_skb+0x444/0x640 net/netlink/af_netlink.c:2477
30 genl_rcv+0x63/0x80 net/netlink/genetlink.c:637
31 netlink_unicast_kernel net/netlink/af_netlink.c:1310 [inline]
32 netlink_unicast+0xf40/0x1020 net/netlink/af_netlink.c:1336
33 netlink_sendmsg+0x127f/0x1300 net/netlink/af_netlink.c:1917
34 sock_sendmsg_nosec net/socket.c:621 [inline]
35 sock_sendmsg net/socket.c:631 [inline]
36 ___sys_sendmsg+0xdb9/0x11b0 net/socket.c:2116
37 __sys_sendmsg net/socket.c:2154 [inline]
38 __do_sys_sendmsg net/socket.c:2163 [inline]
39 __se_sys_sendmsg+0x305/0x460 net/socket.c:2161
40 __x64_sys_sendmsg+0x4a/0x70 net/socket.c:2161
41 do_syscall_64+0xbc/0xf0 arch/x86/entry/common.c:291
42 entry_SYSCALL_64_after_hwframe+0x63/0xe7
43 RIP: 0033:0x457ec9
44 Code: 6d b7 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 3b b7 fb ff c3 66 2e 0f 1f 84 00 00 00 00
45 RSP: 002b:00007f2557338c78 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
46 RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000000457ec9
47 RDX: 0000000000000000 RSI: 00000000200001c0 RDI: 0000000000000003
48 RBP: 000000000073bf00 R08: 0000000000000000 R09: 0000000000000000
49 R10: 0000000000000000 R11: 0000000000000246 R12: 00007f25573396d4
50 R13: 00000000004cb478 R14: 00000000004d86c8 R15: 00000000ffffffff
51
52 Uninit was created at:
53 kmsan_save_stack_with_flags mm/kmsan/kmsan.c:204 [inline]
54 kmsan_internal_poison_shadow+0x92/0x150 mm/kmsan/kmsan.c:158
55 kmsan_kmalloc+0xa6/0x130 mm/kmsan/kmsan_hooks.c:176
56 kmsan_slab_alloc+0xe/0x10 mm/kmsan/kmsan_hooks.c:185
57 slab_post_alloc_hook mm/slab.h:446 [inline]
58 slab_alloc_node mm/slub.c:2759 [inline]
59 __kmalloc_node_track_caller+0xe18/0x1030 mm/slub.c:4383
60 __kmalloc_reserve net/core/skbuff.c:137 [inline]
61 __alloc_skb+0x309/0xa20 net/core/skbuff.c:205
62 alloc_skb include/linux/skbuff.h:998 [inline]
63 netlink_alloc_large_skb net/netlink/af_netlink.c:1182 [inline]
64 netlink_sendmsg+0xb82/0x1300 net/netlink/af_netlink.c:1892
65 sock_sendmsg_nosec net/socket.c:621 [inline]
66 sock_sendmsg net/socket.c:631 [inline]
67 ___sys_sendmsg+0xdb9/0x11b0 net/socket.c:2116
68 __sys_sendmsg net/socket.c:2154 [inline]
69 __do_sys_sendmsg net/socket.c:2163 [inline]
70 __se_sys_sendmsg+0x305/0x460 net/socket.c:2161
71 __x64_sys_sendmsg+0x4a/0x70 net/socket.c:2161
72 do_syscall_64+0xbc/0xf0 arch/x86/entry/common.c:291
73 entry_SYSCALL_64_after_hwframe+0x63/0xe7
74
75 The uninitialised access happened in tipc_nl_compat_link_reset_stats:
76 nla_put_string(skb, TIPC_NLA_LINK_NAME, name)
77
78 This is because name string is not validated before it's used.
79
80 Reported-by: syzbot+e01d94b5a4c266be6e4c@syzkaller.appspotmail.com
81 Signed-off-by: Ying Xue <ying.xue@windriver.com>
82 Signed-off-by: David S. Miller <davem@davemloft.net>
83 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
84
85 ---
86 net/tipc/netlink_compat.c | 15 +++++++++++++++
87 1 file changed, 15 insertions(+)
88
89 --- a/net/tipc/netlink_compat.c
90 +++ b/net/tipc/netlink_compat.c
91 @@ -87,6 +87,11 @@ static int tipc_skb_tailroom(struct sk_b
92 return limit;
93 }
94
95 +static inline int TLV_GET_DATA_LEN(struct tlv_desc *tlv)
96 +{
97 + return TLV_GET_LEN(tlv) - TLV_SPACE(0);
98 +}
99 +
100 static int tipc_add_tlv(struct sk_buff *skb, u16 type, void *data, u16 len)
101 {
102 struct tlv_desc *tlv = (struct tlv_desc *)skb_tail_pointer(skb);
103 @@ -166,6 +171,11 @@ static struct sk_buff *tipc_get_err_tlv(
104 return buf;
105 }
106
107 +static inline bool string_is_valid(char *s, int len)
108 +{
109 + return memchr(s, '\0', len) ? true : false;
110 +}
111 +
112 static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
113 struct tipc_nl_compat_msg *msg,
114 struct sk_buff *arg)
115 @@ -711,6 +721,7 @@ static int tipc_nl_compat_link_reset_sta
116 {
117 char *name;
118 struct nlattr *link;
119 + int len;
120
121 name = (char *)TLV_DATA(msg->req);
122
123 @@ -718,6 +729,10 @@ static int tipc_nl_compat_link_reset_sta
124 if (!link)
125 return -EMSGSIZE;
126
127 + len = min_t(int, TLV_GET_DATA_LEN(msg->req), TIPC_MAX_LINK_NAME);
128 + if (!string_is_valid(name, len))
129 + return -EINVAL;
130 +
131 if (nla_put_string(skb, TIPC_NLA_LINK_NAME, name))
132 return -EMSGSIZE;
133