Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

driver core: auxiliary bus: Fix auxiliary bus shutdown null auxdrv ptr

If the probe of the auxdrv failed, the device->driver is set to NULL.
During kernel shutdown, the bus shutdown will call auxdrv->shutdown and
cause an invalid ptr dereference. Add check to make sure device->driver is
not NULL before we proceed.

Fixes: 7de3697e9cbd ("Add auxiliary bus support")
Cc: Dave Ertman <david.m.ertman@intel.com>
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Link: https://lore.kernel.org/r/160710040926.1889434.8840329810698403478.stgit@djiang5-desk3.ch.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Dave Jiang and committed by
Greg Kroah-Hartman
784b2c48 5812b32e

+8 -3
+8 -3
drivers/base/auxiliary.c
··· 92 92 93 93 static void auxiliary_bus_shutdown(struct device *dev) 94 94 { 95 - struct auxiliary_driver *auxdrv = to_auxiliary_drv(dev->driver); 96 - struct auxiliary_device *auxdev = to_auxiliary_dev(dev); 95 + struct auxiliary_driver *auxdrv = NULL; 96 + struct auxiliary_device *auxdev; 97 97 98 - if (auxdrv->shutdown) 98 + if (dev->driver) { 99 + auxdrv = to_auxiliary_drv(dev->driver); 100 + auxdev = to_auxiliary_dev(dev); 101 + } 102 + 103 + if (auxdrv && auxdrv->shutdown) 99 104 auxdrv->shutdown(auxdev); 100 105 } 101 106