]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.9.164/net-x25-fix-use-after-free-in-x25_device_event.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.9.164 / net-x25-fix-use-after-free-in-x25_device_event.patch
1 From foo@baz Fri Mar 15 21:00:09 PDT 2019
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Sun, 10 Mar 2019 09:07:14 -0700
4 Subject: net/x25: fix use-after-free in x25_device_event()
5
6 From: Eric Dumazet <edumazet@google.com>
7
8 [ Upstream commit 95d6ebd53c79522bf9502dbc7e89e0d63f94dae4 ]
9
10 In case of failure x25_connect() does a x25_neigh_put(x25->neighbour)
11 but forgets to clear x25->neighbour pointer, thus triggering use-after-free.
12
13 Since the socket is visible in x25_list, we need to hold x25_list_lock
14 to protect the operation.
15
16 syzbot report :
17
18 BUG: KASAN: use-after-free in x25_kill_by_device net/x25/af_x25.c:217 [inline]
19 BUG: KASAN: use-after-free in x25_device_event+0x296/0x2b0 net/x25/af_x25.c:252
20 Read of size 8 at addr ffff8880a030edd0 by task syz-executor003/7854
21
22 CPU: 0 PID: 7854 Comm: syz-executor003 Not tainted 5.0.0+ #97
23 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
24 Call Trace:
25 __dump_stack lib/dump_stack.c:77 [inline]
26 dump_stack+0x172/0x1f0 lib/dump_stack.c:113
27 print_address_description.cold+0x7c/0x20d mm/kasan/report.c:187
28 kasan_report.cold+0x1b/0x40 mm/kasan/report.c:317
29 __asan_report_load8_noabort+0x14/0x20 mm/kasan/generic_report.c:135
30 x25_kill_by_device net/x25/af_x25.c:217 [inline]
31 x25_device_event+0x296/0x2b0 net/x25/af_x25.c:252
32 notifier_call_chain+0xc7/0x240 kernel/notifier.c:93
33 __raw_notifier_call_chain kernel/notifier.c:394 [inline]
34 raw_notifier_call_chain+0x2e/0x40 kernel/notifier.c:401
35 call_netdevice_notifiers_info+0x3f/0x90 net/core/dev.c:1739
36 call_netdevice_notifiers_extack net/core/dev.c:1751 [inline]
37 call_netdevice_notifiers net/core/dev.c:1765 [inline]
38 __dev_notify_flags+0x1e9/0x2c0 net/core/dev.c:7607
39 dev_change_flags+0x10d/0x170 net/core/dev.c:7643
40 dev_ifsioc+0x2b0/0x940 net/core/dev_ioctl.c:237
41 dev_ioctl+0x1b8/0xc70 net/core/dev_ioctl.c:488
42 sock_do_ioctl+0x1bd/0x300 net/socket.c:995
43 sock_ioctl+0x32b/0x610 net/socket.c:1096
44 vfs_ioctl fs/ioctl.c:46 [inline]
45 file_ioctl fs/ioctl.c:509 [inline]
46 do_vfs_ioctl+0xd6e/0x1390 fs/ioctl.c:696
47 ksys_ioctl+0xab/0xd0 fs/ioctl.c:713
48 __do_sys_ioctl fs/ioctl.c:720 [inline]
49 __se_sys_ioctl fs/ioctl.c:718 [inline]
50 __x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:718
51 do_syscall_64+0x103/0x610 arch/x86/entry/common.c:290
52 entry_SYSCALL_64_after_hwframe+0x49/0xbe
53 RIP: 0033:0x4467c9
54 Code: e8 0c e8 ff ff 48 83 c4 18 c3 0f 1f 80 00 00 00 00 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 5b 07 fc ff c3 66 2e 0f 1f 84 00 00 00 00
55 RSP: 002b:00007fdbea222d98 EFLAGS: 00000246 ORIG_RAX: 0000000000000010
56 RAX: ffffffffffffffda RBX: 00000000006dbc58 RCX: 00000000004467c9
57 RDX: 0000000020000340 RSI: 0000000000008914 RDI: 0000000000000003
58 RBP: 00000000006dbc50 R08: 00007fdbea223700 R09: 0000000000000000
59 R10: 00007fdbea223700 R11: 0000000000000246 R12: 00000000006dbc5c
60 R13: 6000030030626669 R14: 0000000000000000 R15: 0000000030626669
61
62 Allocated by task 7843:
63 save_stack+0x45/0xd0 mm/kasan/common.c:73
64 set_track mm/kasan/common.c:85 [inline]
65 __kasan_kmalloc mm/kasan/common.c:495 [inline]
66 __kasan_kmalloc.constprop.0+0xcf/0xe0 mm/kasan/common.c:468
67 kasan_kmalloc+0x9/0x10 mm/kasan/common.c:509
68 kmem_cache_alloc_trace+0x151/0x760 mm/slab.c:3615
69 kmalloc include/linux/slab.h:545 [inline]
70 x25_link_device_up+0x46/0x3f0 net/x25/x25_link.c:249
71 x25_device_event+0x116/0x2b0 net/x25/af_x25.c:242
72 notifier_call_chain+0xc7/0x240 kernel/notifier.c:93
73 __raw_notifier_call_chain kernel/notifier.c:394 [inline]
74 raw_notifier_call_chain+0x2e/0x40 kernel/notifier.c:401
75 call_netdevice_notifiers_info+0x3f/0x90 net/core/dev.c:1739
76 call_netdevice_notifiers_extack net/core/dev.c:1751 [inline]
77 call_netdevice_notifiers net/core/dev.c:1765 [inline]
78 __dev_notify_flags+0x121/0x2c0 net/core/dev.c:7605
79 dev_change_flags+0x10d/0x170 net/core/dev.c:7643
80 dev_ifsioc+0x2b0/0x940 net/core/dev_ioctl.c:237
81 dev_ioctl+0x1b8/0xc70 net/core/dev_ioctl.c:488
82 sock_do_ioctl+0x1bd/0x300 net/socket.c:995
83 sock_ioctl+0x32b/0x610 net/socket.c:1096
84 vfs_ioctl fs/ioctl.c:46 [inline]
85 file_ioctl fs/ioctl.c:509 [inline]
86 do_vfs_ioctl+0xd6e/0x1390 fs/ioctl.c:696
87 ksys_ioctl+0xab/0xd0 fs/ioctl.c:713
88 __do_sys_ioctl fs/ioctl.c:720 [inline]
89 __se_sys_ioctl fs/ioctl.c:718 [inline]
90 __x64_sys_ioctl+0x73/0xb0 fs/ioctl.c:718
91 do_syscall_64+0x103/0x610 arch/x86/entry/common.c:290
92 entry_SYSCALL_64_after_hwframe+0x49/0xbe
93
94 Freed by task 7865:
95 save_stack+0x45/0xd0 mm/kasan/common.c:73
96 set_track mm/kasan/common.c:85 [inline]
97 __kasan_slab_free+0x102/0x150 mm/kasan/common.c:457
98 kasan_slab_free+0xe/0x10 mm/kasan/common.c:465
99 __cache_free mm/slab.c:3494 [inline]
100 kfree+0xcf/0x230 mm/slab.c:3811
101 x25_neigh_put include/net/x25.h:253 [inline]
102 x25_connect+0x8d8/0xde0 net/x25/af_x25.c:824
103 __sys_connect+0x266/0x330 net/socket.c:1685
104 __do_sys_connect net/socket.c:1696 [inline]
105 __se_sys_connect net/socket.c:1693 [inline]
106 __x64_sys_connect+0x73/0xb0 net/socket.c:1693
107 do_syscall_64+0x103/0x610 arch/x86/entry/common.c:290
108 entry_SYSCALL_64_after_hwframe+0x49/0xbe
109
110 The buggy address belongs to the object at ffff8880a030edc0
111 which belongs to the cache kmalloc-256 of size 256
112 The buggy address is located 16 bytes inside of
113 256-byte region [ffff8880a030edc0, ffff8880a030eec0)
114 The buggy address belongs to the page:
115 page:ffffea000280c380 count:1 mapcount:0 mapping:ffff88812c3f07c0 index:0x0
116 flags: 0x1fffc0000000200(slab)
117 raw: 01fffc0000000200 ffffea0002806788 ffffea00027f0188 ffff88812c3f07c0
118 raw: 0000000000000000 ffff8880a030e000 000000010000000c 0000000000000000
119 page dumped because: kasan: bad access detected
120
121 Signed-off-by: Eric Dumazet <edumazet@google.com>
122 Reported-by: syzbot+04babcefcd396fabec37@syzkaller.appspotmail.com
123 Cc: andrew hendry <andrew.hendry@gmail.com>
124 Signed-off-by: David S. Miller <davem@davemloft.net>
125 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
126 ---
127 net/x25/af_x25.c | 6 +++++-
128 1 file changed, 5 insertions(+), 1 deletion(-)
129
130 --- a/net/x25/af_x25.c
131 +++ b/net/x25/af_x25.c
132 @@ -812,8 +812,12 @@ static int x25_connect(struct socket *so
133 sock->state = SS_CONNECTED;
134 rc = 0;
135 out_put_neigh:
136 - if (rc)
137 + if (rc) {
138 + read_lock_bh(&x25_list_lock);
139 x25_neigh_put(x25->neighbour);
140 + x25->neighbour = NULL;
141 + read_unlock_bh(&x25_list_lock);
142 + }
143 out_put_route:
144 x25_route_put(rt);
145 out: