]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/ipv6-flowlabel-wait-rcu-grace-period-before-put_pid.patch
4.4-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.4 / ipv6-flowlabel-wait-rcu-grace-period-before-put_pid.patch
1 From foo@baz Sat 04 May 2019 12:23:27 PM CEST
2 From: Eric Dumazet <edumazet@google.com>
3 Date: Sat, 27 Apr 2019 16:49:06 -0700
4 Subject: ipv6/flowlabel: wait rcu grace period before put_pid()
5
6 From: Eric Dumazet <edumazet@google.com>
7
8 [ Upstream commit 6c0afef5fb0c27758f4d52b2210c61b6bd8b4470 ]
9
10 syzbot was able to catch a use-after-free read in pid_nr_ns() [1]
11
12 ip6fl_seq_show() seems to use RCU protection, dereferencing fl->owner.pid
13 but fl_free() releases fl->owner.pid before rcu grace period is started.
14
15 [1]
16
17 BUG: KASAN: use-after-free in pid_nr_ns+0x128/0x140 kernel/pid.c:407
18 Read of size 4 at addr ffff888094012a04 by task syz-executor.0/18087
19
20 CPU: 0 PID: 18087 Comm: syz-executor.0 Not tainted 5.1.0-rc6+ #89
21 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
22 Call Trace:
23 __dump_stack lib/dump_stack.c:77 [inline]
24 dump_stack+0x172/0x1f0 lib/dump_stack.c:113
25 print_address_description.cold+0x7c/0x20d mm/kasan/report.c:187
26 kasan_report.cold+0x1b/0x40 mm/kasan/report.c:317
27 __asan_report_load4_noabort+0x14/0x20 mm/kasan/generic_report.c:131
28 pid_nr_ns+0x128/0x140 kernel/pid.c:407
29 ip6fl_seq_show+0x2f8/0x4f0 net/ipv6/ip6_flowlabel.c:794
30 seq_read+0xad3/0x1130 fs/seq_file.c:268
31 proc_reg_read+0x1fe/0x2c0 fs/proc/inode.c:227
32 do_loop_readv_writev fs/read_write.c:701 [inline]
33 do_loop_readv_writev fs/read_write.c:688 [inline]
34 do_iter_read+0x4a9/0x660 fs/read_write.c:922
35 vfs_readv+0xf0/0x160 fs/read_write.c:984
36 kernel_readv fs/splice.c:358 [inline]
37 default_file_splice_read+0x475/0x890 fs/splice.c:413
38 do_splice_to+0x12a/0x190 fs/splice.c:876
39 splice_direct_to_actor+0x2d2/0x970 fs/splice.c:953
40 do_splice_direct+0x1da/0x2a0 fs/splice.c:1062
41 do_sendfile+0x597/0xd00 fs/read_write.c:1443
42 __do_sys_sendfile64 fs/read_write.c:1498 [inline]
43 __se_sys_sendfile64 fs/read_write.c:1490 [inline]
44 __x64_sys_sendfile64+0x15a/0x220 fs/read_write.c:1490
45 do_syscall_64+0x103/0x610 arch/x86/entry/common.c:290
46 entry_SYSCALL_64_after_hwframe+0x49/0xbe
47 RIP: 0033:0x458da9
48 Code: ad b8 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 7b b8 fb ff c3 66 2e 0f 1f 84 00 00 00 00
49 RSP: 002b:00007f300d24bc78 EFLAGS: 00000246 ORIG_RAX: 0000000000000028
50 RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 0000000000458da9
51 RDX: 00000000200000c0 RSI: 0000000000000008 RDI: 0000000000000007
52 RBP: 000000000073bf00 R08: 0000000000000000 R09: 0000000000000000
53 R10: 000000000000005a R11: 0000000000000246 R12: 00007f300d24c6d4
54 R13: 00000000004c5fa3 R14: 00000000004da748 R15: 00000000ffffffff
55
56 Allocated by task 17543:
57 save_stack+0x45/0xd0 mm/kasan/common.c:75
58 set_track mm/kasan/common.c:87 [inline]
59 __kasan_kmalloc mm/kasan/common.c:497 [inline]
60 __kasan_kmalloc.constprop.0+0xcf/0xe0 mm/kasan/common.c:470
61 kasan_slab_alloc+0xf/0x20 mm/kasan/common.c:505
62 slab_post_alloc_hook mm/slab.h:437 [inline]
63 slab_alloc mm/slab.c:3393 [inline]
64 kmem_cache_alloc+0x11a/0x6f0 mm/slab.c:3555
65 alloc_pid+0x55/0x8f0 kernel/pid.c:168
66 copy_process.part.0+0x3b08/0x7980 kernel/fork.c:1932
67 copy_process kernel/fork.c:1709 [inline]
68 _do_fork+0x257/0xfd0 kernel/fork.c:2226
69 __do_sys_clone kernel/fork.c:2333 [inline]
70 __se_sys_clone kernel/fork.c:2327 [inline]
71 __x64_sys_clone+0xbf/0x150 kernel/fork.c:2327
72 do_syscall_64+0x103/0x610 arch/x86/entry/common.c:290
73 entry_SYSCALL_64_after_hwframe+0x49/0xbe
74
75 Freed by task 7789:
76 save_stack+0x45/0xd0 mm/kasan/common.c:75
77 set_track mm/kasan/common.c:87 [inline]
78 __kasan_slab_free+0x102/0x150 mm/kasan/common.c:459
79 kasan_slab_free+0xe/0x10 mm/kasan/common.c:467
80 __cache_free mm/slab.c:3499 [inline]
81 kmem_cache_free+0x86/0x260 mm/slab.c:3765
82 put_pid.part.0+0x111/0x150 kernel/pid.c:111
83 put_pid+0x20/0x30 kernel/pid.c:105
84 fl_free+0xbe/0xe0 net/ipv6/ip6_flowlabel.c:102
85 ip6_fl_gc+0x295/0x3e0 net/ipv6/ip6_flowlabel.c:152
86 call_timer_fn+0x190/0x720 kernel/time/timer.c:1325
87 expire_timers kernel/time/timer.c:1362 [inline]
88 __run_timers kernel/time/timer.c:1681 [inline]
89 __run_timers kernel/time/timer.c:1649 [inline]
90 run_timer_softirq+0x652/0x1700 kernel/time/timer.c:1694
91 __do_softirq+0x266/0x95a kernel/softirq.c:293
92
93 The buggy address belongs to the object at ffff888094012a00
94 which belongs to the cache pid_2 of size 88
95 The buggy address is located 4 bytes inside of
96 88-byte region [ffff888094012a00, ffff888094012a58)
97 The buggy address belongs to the page:
98 page:ffffea0002500480 count:1 mapcount:0 mapping:ffff88809a483080 index:0xffff888094012980
99 flags: 0x1fffc0000000200(slab)
100 raw: 01fffc0000000200 ffffea00018a3508 ffffea0002524a88 ffff88809a483080
101 raw: ffff888094012980 ffff888094012000 000000010000001b 0000000000000000
102 page dumped because: kasan: bad access detected
103
104 Memory state around the buggy address:
105 ffff888094012900: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
106 ffff888094012980: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
107 >ffff888094012a00: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
108 ^
109 ffff888094012a80: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
110 ffff888094012b00: fb fb fb fb fb fb fb fb fb fb fb fc fc fc fc fc
111
112 Fixes: 4f82f45730c6 ("net ip6 flowlabel: Make owner a union of struct pid * and kuid_t")
113 Signed-off-by: Eric Dumazet <edumazet@google.com>
114 Cc: Eric W. Biederman <ebiederm@xmission.com>
115 Reported-by: syzbot <syzkaller@googlegroups.com>
116 Signed-off-by: David S. Miller <davem@davemloft.net>
117 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
118 ---
119 net/ipv6/ip6_flowlabel.c | 18 ++++++++++++------
120 1 file changed, 12 insertions(+), 6 deletions(-)
121
122 --- a/net/ipv6/ip6_flowlabel.c
123 +++ b/net/ipv6/ip6_flowlabel.c
124 @@ -94,15 +94,21 @@ static struct ip6_flowlabel *fl_lookup(s
125 return fl;
126 }
127
128 +static void fl_free_rcu(struct rcu_head *head)
129 +{
130 + struct ip6_flowlabel *fl = container_of(head, struct ip6_flowlabel, rcu);
131 +
132 + if (fl->share == IPV6_FL_S_PROCESS)
133 + put_pid(fl->owner.pid);
134 + kfree(fl->opt);
135 + kfree(fl);
136 +}
137 +
138
139 static void fl_free(struct ip6_flowlabel *fl)
140 {
141 - if (fl) {
142 - if (fl->share == IPV6_FL_S_PROCESS)
143 - put_pid(fl->owner.pid);
144 - kfree(fl->opt);
145 - kfree_rcu(fl, rcu);
146 - }
147 + if (fl)
148 + call_rcu(&fl->rcu, fl_free_rcu);
149 }
150
151 static void fl_release(struct ip6_flowlabel *fl)