Skip to contentSkip to conversation

spi: spidev: fix possible NULL dereference

PATCH In review Sudip Mukherjee 3 participants 5 messages Sep 10, 2015 – Sep 11, 2015 SPI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: spidev: fix possible NULL dereference

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.

---
 drivers/spi/spidev.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spidev.c +2 -1
index fba92a5..ef008e5 100644
@@ -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);
Signature · 6 lines
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reviewed-by Tested-by on v1 1/1
#1 lore raw

Hi

Quoted 14 lines · Sudip Mukherjee

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.

---
  drivers/spi/spidev.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/spidev.c +0 -0
index fba92a5..ef008e5 100644

drivers/spi/spidev.c static int spidev_release(struct inode *inode, struct file *filp) · line 658

Quoted 9 lines
drivers/spi/spidev.c +2 -1
@@ -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 <[email protected]>

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

You can add these too:

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#2 lore raw
Quoted 4 lines · Jarkko Nikula

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.

Quoted 8 lines

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 <[email protected]>

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

spi device")

The patch was already applied :(

#3 lore raw
Quoted 9 lines · Mark Brown
Quoted 6 lines · Jarkko Nikula

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

Quoted 7 lines
Quoted 5 lines

It would be good to update this to commit log, add a tag below and Cc <[email protected]>

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

spi device")

The patch was already applied :(

Applied? But usually I will receive an auto mail from you after applying. I dont think I have received any.

regards
sudip
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#4 lore raw
Quoted 6 lines · Sudip Mukherjee
Quoted 1 line · Mark Brown

The patch was already applied :(

Applied? But usually I will receive an auto mail from you after applying. I dont think I have received any.

You get a mail when the changes are pushed, which had happened by the time I replied.