]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-4.4/fs-proc-proc_sysctl.c-fix-a-null-pointer-dereference.patch
4.4-stable patches
[thirdparty/kernel/stable-queue.git] / queue-4.4 / fs-proc-proc_sysctl.c-fix-a-null-pointer-dereference.patch
1 From 89189557b47b35683a27c80ee78aef18248eefb4 Mon Sep 17 00:00:00 2001
2 From: YueHaibing <yuehaibing@huawei.com>
3 Date: Thu, 25 Apr 2019 22:24:05 -0700
4 Subject: fs/proc/proc_sysctl.c: Fix a NULL pointer dereference
5
6 From: YueHaibing <yuehaibing@huawei.com>
7
8 commit 89189557b47b35683a27c80ee78aef18248eefb4 upstream.
9
10 Syzkaller report this:
11
12 sysctl could not get directory: /net//bridge -12
13 kasan: CONFIG_KASAN_INLINE enabled
14 kasan: GPF could be caused by NULL-ptr deref or user memory access
15 general protection fault: 0000 [#1] SMP KASAN PTI
16 CPU: 1 PID: 7027 Comm: syz-executor.0 Tainted: G C 5.1.0-rc3+ #8
17 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.10.2-1ubuntu1 04/01/2014
18 RIP: 0010:__write_once_size include/linux/compiler.h:220 [inline]
19 RIP: 0010:__rb_change_child include/linux/rbtree_augmented.h:144 [inline]
20 RIP: 0010:__rb_erase_augmented include/linux/rbtree_augmented.h:186 [inline]
21 RIP: 0010:rb_erase+0x5f4/0x19f0 lib/rbtree.c:459
22 Code: 00 0f 85 60 13 00 00 48 89 1a 48 83 c4 18 5b 5d 41 5c 41 5d 41 5e 41 5f c3 48 89 f2 48 b8 00 00 00 00 00 fc ff df 48 c1 ea 03 <80> 3c 02 00 0f 85 75 0c 00 00 4d 85 ed 4c 89 2e 74 ce 4c 89 ea 48
23 RSP: 0018:ffff8881bb507778 EFLAGS: 00010206
24 RAX: dffffc0000000000 RBX: ffff8881f224b5b8 RCX: ffffffff818f3f6a
25 RDX: 000000000000000a RSI: 0000000000000050 RDI: ffff8881f224b568
26 RBP: 0000000000000000 R08: ffffed10376a0ef4 R09: ffffed10376a0ef4
27 R10: 0000000000000001 R11: ffffed10376a0ef4 R12: ffff8881f224b558
28 R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
29 FS: 00007f3e7ce13700(0000) GS:ffff8881f7300000(0000) knlGS:0000000000000000
30 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
31 CR2: 00007fd60fbe9398 CR3: 00000001cb55c001 CR4: 00000000007606e0
32 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
33 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
34 PKRU: 55555554
35 Call Trace:
36 erase_entry fs/proc/proc_sysctl.c:178 [inline]
37 erase_header+0xe3/0x160 fs/proc/proc_sysctl.c:207
38 start_unregistering fs/proc/proc_sysctl.c:331 [inline]
39 drop_sysctl_table+0x558/0x880 fs/proc/proc_sysctl.c:1631
40 get_subdir fs/proc/proc_sysctl.c:1022 [inline]
41 __register_sysctl_table+0xd65/0x1090 fs/proc/proc_sysctl.c:1335
42 br_netfilter_init+0x68/0x1000 [br_netfilter]
43 do_one_initcall+0xbc/0x47d init/main.c:901
44 do_init_module+0x1b5/0x547 kernel/module.c:3456
45 load_module+0x6405/0x8c10 kernel/module.c:3804
46 __do_sys_finit_module+0x162/0x190 kernel/module.c:3898
47 do_syscall_64+0x9f/0x450 arch/x86/entry/common.c:290
48 entry_SYSCALL_64_after_hwframe+0x49/0xbe
49 Modules linked in: br_netfilter(+) backlight comedi(C) hid_sensor_hub max3100 ti_ads8688 udc_core fddi snd_mona leds_gpio rc_streamzap mtd pata_netcell nf_log_common rc_winfast udp_tunnel snd_usbmidi_lib snd_usb_toneport snd_usb_line6 snd_rawmidi snd_seq_device snd_hwdep videobuf2_v4l2 videobuf2_common videodev media videobuf2_vmalloc videobuf2_memops rc_gadmei_rm008z 8250_of smm665 hid_tmff hid_saitek hwmon_vid rc_ati_tv_wonder_hd_600 rc_core pata_pdc202xx_old dn_rtmsg as3722 ad714x_i2c ad714x snd_soc_cs4265 hid_kensington panel_ilitek_ili9322 drm drm_panel_orientation_quirks ipack cdc_phonet usbcore phonet hid_jabra hid extcon_arizona can_dev industrialio_triggered_buffer kfifo_buf industrialio adm1031 i2c_mux_ltc4306 i2c_mux ipmi_msghandler mlxsw_core snd_soc_cs35l34 snd_soc_core snd_pcm_dmaengine snd_pcm snd_timer ac97_bus snd_compress snd soundcore gpio_da9055 uio ecdh_generic mdio_thunder of_mdio fixed_phy libphy mdio_cavium iptable_security iptable_raw iptable_mangle
50 iptable_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 iptable_filter bpfilter ip6_vti ip_vti ip_gre ipip sit tunnel4 ip_tunnel hsr veth netdevsim vxcan batman_adv cfg80211 rfkill chnl_net caif nlmon dummy team bonding vcan bridge stp llc ip6_gre gre ip6_tunnel tunnel6 tun joydev mousedev ppdev tpm kvm_intel kvm irqbypass crct10dif_pclmul crc32_pclmul crc32c_intel ghash_clmulni_intel aesni_intel ide_pci_generic piix aes_x86_64 crypto_simd cryptd ide_core glue_helper input_leds psmouse intel_agp intel_gtt serio_raw ata_generic i2c_piix4 agpgart pata_acpi parport_pc parport floppy rtc_cmos sch_fq_codel ip_tables x_tables sha1_ssse3 sha1_generic ipv6 [last unloaded: br_netfilter]
51 Dumping ftrace buffer:
52 (ftrace buffer empty)
53 ---[ end trace 68741688d5fbfe85 ]---
54
55 commit 23da9588037e ("fs/proc/proc_sysctl.c: fix NULL pointer
56 dereference in put_links") forgot to handle start_unregistering() case,
57 while header->parent is NULL, it calls erase_header() and as seen in the
58 above syzkaller call trace, accessing &header->parent->root will trigger
59 a NULL pointer dereference.
60
61 As that commit explained, there is also no need to call
62 start_unregistering() if header->parent is NULL.
63
64 Link: http://lkml.kernel.org/r/20190409153622.28112-1-yuehaibing@huawei.com
65 Fixes: 23da9588037e ("fs/proc/proc_sysctl.c: fix NULL pointer dereference in put_links")
66 Fixes: 0e47c99d7fe25 ("sysctl: Replace root_list with links between sysctl_table_sets")
67 Signed-off-by: YueHaibing <yuehaibing@huawei.com>
68 Reported-by: Hulk Robot <hulkci@huawei.com>
69 Reviewed-by: Kees Cook <keescook@chromium.org>
70 Cc: Luis Chamberlain <mcgrof@kernel.org>
71 Cc: Alexey Dobriyan <adobriyan@gmail.com>
72 Cc: Al Viro <viro@zeniv.linux.org.uk>
73 Cc: "Eric W. Biederman" <ebiederm@xmission.com>
74 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
75 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
76 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
77
78 ---
79 fs/proc/proc_sysctl.c | 6 ++++--
80 1 file changed, 4 insertions(+), 2 deletions(-)
81
82 --- a/fs/proc/proc_sysctl.c
83 +++ b/fs/proc/proc_sysctl.c
84 @@ -1550,9 +1550,11 @@ static void drop_sysctl_table(struct ctl
85 if (--header->nreg)
86 return;
87
88 - if (parent)
89 + if (parent) {
90 put_links(header);
91 - start_unregistering(header);
92 + start_unregistering(header);
93 + }
94 +
95 if (!--header->count)
96 kfree_rcu(header, rcu);
97