Re: [PATCH] spi: spidev: fix possible NULL dereference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi

On 09/10/2015 02:18 PM, Sudip Mukherjee wrote:
During the last close we are freeing spidev if spidev->spi is NULL, but
just before checking if spidev->spi is NULL we are dereferencing it.
Lets add a check there to avoid the NULL dereference.

Signed-off-by: Sudip Mukherjee <sudip@xxxxxxxxxxxxxxx>
---
  drivers/spi/spidev.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index fba92a5..ef008e5 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -651,7 +651,8 @@ static int spidev_release(struct inode *inode, struct file *filp)
  		kfree(spidev->rx_buffer);
  		spidev->rx_buffer = NULL;

-		spidev->speed_hz = spidev->spi->max_speed_hz;
+		if (spidev->spi)
+			spidev->speed_hz = spidev->spi->max_speed_hz;

  		/* ... after we unbound from the underlying device? */
  		spin_lock_irq(&spidev->spi_lock);

Actually this fixes a *real* NULL dereference case but it is not related to normal open/close life cycle of spidev. It requires that spidev is kept open when SPI master is removed.

spidev->spi is set to NULL in spidev_remove() and it is called before spidev_release() in case master is removed while spidev is in use

It would be good to update this to commit log, add a tag below and Cc <stable@xxxxxxxxxxxxxxx>

Fixes: 9169051617df ("spi: spidev: Don't mangle max_speed_hz in underlying spi device")

You can add these too:

Reviewed-by: Jarkko Nikula <jarkko.nikula@xxxxxxxxxxxxxxx>
Tested-by: Jarkko Nikula <jarkko.nikula@xxxxxxxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux