Merge pull request #624 from ecsv/batadv-for-18.06
[feed/routing.git] / batman-adv / patches / 0033-batman-adv-fix-uninit-value-in-batadv_netlink_get_if.patch
1 From: Eric Dumazet <edumazet@google.com>
2 Date: Mon, 12 Aug 2019 04:57:27 -0700
3 Subject: batman-adv: fix uninit-value in batadv_netlink_get_ifindex()
4
5 batadv_netlink_get_ifindex() needs to make sure user passed
6 a correct u32 attribute.
7
8 syzbot reported :
9 BUG: KMSAN: uninit-value in batadv_netlink_dump_hardif+0x70d/0x880 net/batman-adv/netlink.c:968
10 CPU: 1 PID: 11705 Comm: syz-executor888 Not tainted 5.1.0+ #1
11 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
12 Call Trace:
13 __dump_stack lib/dump_stack.c:77 [inline]
14 dump_stack+0x191/0x1f0 lib/dump_stack.c:113
15 kmsan_report+0x130/0x2a0 mm/kmsan/kmsan.c:622
16 __msan_warning+0x75/0xe0 mm/kmsan/kmsan_instr.c:310
17 batadv_netlink_dump_hardif+0x70d/0x880 net/batman-adv/netlink.c:968
18 genl_lock_dumpit+0xc6/0x130 net/netlink/genetlink.c:482
19 netlink_dump+0xa84/0x1ab0 net/netlink/af_netlink.c:2253
20 __netlink_dump_start+0xa3a/0xb30 net/netlink/af_netlink.c:2361
21 genl_family_rcv_msg net/netlink/genetlink.c:550 [inline]
22 genl_rcv_msg+0xfc1/0x1a40 net/netlink/genetlink.c:627
23 netlink_rcv_skb+0x431/0x620 net/netlink/af_netlink.c:2486
24 genl_rcv+0x63/0x80 net/netlink/genetlink.c:638
25 netlink_unicast_kernel net/netlink/af_netlink.c:1311 [inline]
26 netlink_unicast+0xf3e/0x1020 net/netlink/af_netlink.c:1337
27 netlink_sendmsg+0x127e/0x12f0 net/netlink/af_netlink.c:1926
28 sock_sendmsg_nosec net/socket.c:651 [inline]
29 sock_sendmsg net/socket.c:661 [inline]
30 ___sys_sendmsg+0xcc6/0x1200 net/socket.c:2260
31 __sys_sendmsg net/socket.c:2298 [inline]
32 __do_sys_sendmsg net/socket.c:2307 [inline]
33 __se_sys_sendmsg+0x305/0x460 net/socket.c:2305
34 __x64_sys_sendmsg+0x4a/0x70 net/socket.c:2305
35 do_syscall_64+0xbc/0xf0 arch/x86/entry/common.c:291
36 entry_SYSCALL_64_after_hwframe+0x63/0xe7
37 RIP: 0033:0x440209
38
39 Fixes: 55d368c3a57e ("batman-adv: netlink: hardif query")
40 Signed-off-by: Eric Dumazet <edumazet@google.com>
41 Reported-by: syzbot <syzkaller@googlegroups.com>
42 Signed-off-by: Sven Eckelmann <sven@narfation.org>
43
44 Origin: upstream, https://git.open-mesh.org/batman-adv.git/commit/9b470b8a2b9ef4ce68d6e95febd3a0574be1ac14
45
46 diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c
47 index 0d9459b69bdb812b1b68e28e6b68fec8ec95df2d..c32820963b8e706b4cdde10d46ec582bc51ec4eb 100644
48 --- a/net/batman-adv/netlink.c
49 +++ b/net/batman-adv/netlink.c
50 @@ -118,7 +118,7 @@ batadv_netlink_get_ifindex(const struct nlmsghdr *nlh, int attrtype)
51 {
52 struct nlattr *attr = nlmsg_find_attr(nlh, GENL_HDRLEN, attrtype);
53
54 - return attr ? nla_get_u32(attr) : 0;
55 + return (attr && nla_len(attr) == sizeof(u32)) ? nla_get_u32(attr) : 0;
56 }
57
58 /**