Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1517918
| From | Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH 4.4 02/69] i2c: core: fix NULL pointer dereference under race condition |
| Date | 2016-11-09 12:00 +0100 |
| Message-ID | <sByLL-6cP-9@gated-at.bofh.it> (permalink) |
| References | <sByC5-69v-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
4.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
commit 147b36d5b70c083cc76770c47d60b347e8eaf231 upstream.
Race condition between registering an I2C device driver and
deregistering an I2C adapter device which is assumed to manage that
I2C device may lead to a NULL pointer dereference due to the
uninitialized list head of driver clients.
The root cause of the issue is that the I2C bus may know about the
registered device driver and thus it is matched by bus_for_each_drv(),
but the list of clients is not initialized and commonly it is NULL,
because I2C device drivers define struct i2c_driver as static and
clients field is expected to be initialized by I2C core:
i2c_register_driver() i2c_del_adapter()
driver_register() ...
bus_add_driver() ...
... bus_for_each_drv(..., __process_removed_adapter)
... i2c_do_del_adapter()
... list_for_each_entry_safe(..., &driver->clients, ...)
INIT_LIST_HEAD(&driver->clients);
To solve the problem it is sufficient to do clients list head
initialization before calling driver_register().
The problem was found while using an I2C device driver with a sluggish
registration routine on a bus provided by a physically detachable I2C
master controller, but practically the oops may be reproduced under
the race between arbitraty I2C device driver registration and managing
I2C bus device removal e.g. by unbinding the latter over sysfs:
% echo 21a4000.i2c > /sys/bus/platform/drivers/imx-i2c/unbind
Unable to handle kernel NULL pointer dereference at virtual address 00000000
Internal error: Oops: 17 [#1] SMP ARM
CPU: 2 PID: 533 Comm: sh Not tainted 4.9.0-rc3+ #61
Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
task: e5ada400 task.stack: e4936000
PC is at i2c_do_del_adapter+0x20/0xcc
LR is at __process_removed_adapter+0x14/0x1c
Flags: NzCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment none
Control: 10c5387d Table: 35bd004a DAC: 00000051
Process sh (pid: 533, stack limit = 0xe4936210)
Stack: (0xe4937d28 to 0xe4938000)
Backtrace:
[<c0667be0>] (i2c_do_del_adapter) from [<c0667cc0>] (__process_removed_adapter+0x14/0x1c)
[<c0667cac>] (__process_removed_adapter) from [<c0516998>] (bus_for_each_drv+0x6c/0xa0)
[<c051692c>] (bus_for_each_drv) from [<c06685ec>] (i2c_del_adapter+0xbc/0x284)
[<c0668530>] (i2c_del_adapter) from [<bf0110ec>] (i2c_imx_remove+0x44/0x164 [i2c_imx])
[<bf0110a8>] (i2c_imx_remove [i2c_imx]) from [<c051a838>] (platform_drv_remove+0x2c/0x44)
[<c051a80c>] (platform_drv_remove) from [<c05183d8>] (__device_release_driver+0x90/0x12c)
[<c0518348>] (__device_release_driver) from [<c051849c>] (device_release_driver+0x28/0x34)
[<c0518474>] (device_release_driver) from [<c0517150>] (unbind_store+0x80/0x104)
[<c05170d0>] (unbind_store) from [<c0516520>] (drv_attr_store+0x28/0x34)
[<c05164f8>] (drv_attr_store) from [<c0298acc>] (sysfs_kf_write+0x50/0x54)
[<c0298a7c>] (sysfs_kf_write) from [<c029801c>] (kernfs_fop_write+0x100/0x214)
[<c0297f1c>] (kernfs_fop_write) from [<c0220130>] (__vfs_write+0x34/0x120)
[<c02200fc>] (__vfs_write) from [<c0221088>] (vfs_write+0xa8/0x170)
[<c0220fe0>] (vfs_write) from [<c0221e74>] (SyS_write+0x4c/0xa8)
[<c0221e28>] (SyS_write) from [<c0108a20>] (ret_fast_syscall+0x0/0x1c)
Signed-off-by: Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
drivers/i2c/i2c-core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -1876,6 +1876,7 @@ int i2c_register_driver(struct module *o
/* add the driver to the list of i2c drivers in the driver core */
driver->driver.owner = owner;
driver->driver.bus = &i2c_bus_type;
+ INIT_LIST_HEAD(&driver->clients);
/* When registration returns, the driver core
* will have called probe() for all matching-but-unbound devices.
@@ -1886,7 +1887,6 @@ int i2c_register_driver(struct module *o
pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
- INIT_LIST_HEAD(&driver->clients);
/* Walk the adapters that are already present */
i2c_for_each_dev(driver, __process_new_driver);
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH 4.4 00/69] 4.4.31-stable review Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 23/69] USB: serial: ftdi_sio: add support for Infineon TriBoard TC2X7 Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 27/69] Fix potential infoleak in older kernels Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 32/69] USB: serial: cp210x: fix tiocmget error handling Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 04/69] h8300: fix syscall restarting Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 01/69] i2c: xgene: Avoid dma_buffer overrun Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 19/69] ubifs: Fix regression in ubifs_readdir() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 29/69] hv: do not lose pending heartbeat vmbus packets Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 31/69] tty: limit terminal size to 4M chars Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 11/69] ALSA: hda - Raise AZX_DCAPS_RIRB_DELAY handling into top drivers Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 06/69] mm/list_lru.c: avoid error-path NULL pointer deref Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 20/69] mei: txe: dont clean an unprocessed interrupt cause. Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 22/69] USB: serial: fix potential NULL-dereference at probe Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 18/69] ubifs: Abort readdir upon error Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 26/69] GenWQE: Fix bad page access during abort of resource allocation Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 11:50 +0100 [PATCH 4.4 08/69] KEYS: Fix short sprintf buffer in /proc/keys show function Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:00 +0100 [PATCH 4.4 02/69] i2c: core: fix NULL pointer dereference under race condition Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:00 +0100 [PATCH 4.4 07/69] mm: memcontrol: do not recurse in direct reclaim Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:00 +0100 [PATCH 4.4 67/69] kvm: x86: Check memopp before dereference (CVE-2016-8630) Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 60/69] cgroup: avoid false positive gcc-6 warning Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 37/69] parisc: Ensure consistent state when switching to kernel stack at syscall entry Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 46/69] scsi: scsi_debug: Fix memory leak if LBP enabled and module is unloaded Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 39/69] virtio: console: Unlock vqs while freeing buffers Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 47/69] scsi: arcmsr: Send SYNCHRONIZE_CACHE command to firmware Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 65/69] usb: dwc3: Fix size used in dma_free_coherent() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 54/69] perf build: Fix traceevent plugins build race Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 38/69] virtio_ring: Make interrupt suppression spec compliant Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 57/69] ARM: 8584/1: floppy: avoid gcc-6 warning Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 51/69] drm/radeon/si_dpm: workaround for SI kickers Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 64/69] pwm: Unexport children before chip removal Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 36/69] ovl: fsync after copy-up Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 42/69] firewire: net: guard against rx buffer overflows Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:10 +0100 [PATCH 4.4 68/69] ubi: fastmap: Fix add_vol() return value test in ubi_attach_fastmap() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:40 +0100 [PATCH 4.4 44/69] mac80211: discard multicast and 4-addr A-MSDUs Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:40 +0100 [PATCH 4.4 43/69] firewire: net: fix fragmented datagram_size off-by-one Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:40 +0100 [PATCH 4.4 45/69] scsi: megaraid_sas: Fix data integrity failure for JBOD (passthrough) devices Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:40 +0100 [PATCH 4.4 69/69] HID: usbhid: add ATEN CS962 to list of quirky devices Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:40 +0100 [PATCH 4.4 50/69] drm/radeon/si_dpm: Limit clocks on HD86xx part Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:50 +0100 [PATCH 4.4 58/69] mm/cma: silence warnings due to max() usage Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:50 +0100 [PATCH 4.4 59/69] drm/exynos: fix error handling in exynos_drm_subdrv_open Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:50 +0100 [PATCH 4.4 41/69] Input: i8042 - add XMG C504 to keyboard reset table Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:50 +0100 [PATCH 4.4 48/69] mmc: dw_mmc-pltfm: fix the potential NULL pointer dereference Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:50 +0100 [PATCH 4.4 63/69] UBI: fastmap: scrub PEB when bitflips are detected in a free PEB EC header Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:50 +0100 [PATCH 4.4 55/69] x86/xen: fix upper bound of pmd loop in xen_cleanhighmap() Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:50 +0100 [PATCH 4.4 56/69] powerpc/ptrace: Fix out of bounds array access warning Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:50 +0100 [PATCH 4.4 40/69] dm mirror: fix read error on recovery after default leg failure Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:50 +0100 [PATCH 4.4 61/69] smc91x: avoid self-comparison warning Greg Kroah-Hartman <gregkh@linuxfoundation.org> - 2016-11-09 12:50 +0100 Re: [PATCH 4.4 00/69] 4.4.31-stable review Shuah Khan <shuah.kh@samsung.com> - 2016-11-09 19:30 +0100 Re: [PATCH 4.4 00/69] 4.4.31-stable review Guenter Roeck <linux@roeck-us.net> - 2016-11-09 20:40 +0100
csiph-web