linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: spidev: fix possible NULL dereference
@ 2015-09-10 11:18 Sudip Mukherjee
       [not found] ` <1441883893-20596-1-git-send-email-sudipm.mukherjee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Sudip Mukherjee @ 2015-09-10 11:18 UTC (permalink / raw)
  To: Mark Brown
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-spi-u79uwXL29TY76Z2rM5mHXA, 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.

Signed-off-by: Sudip Mukherjee <sudip-ofJRbWXBVFamYgehrs7/Lw@public.gmane.org>
---
 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);
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] spi: spidev: fix possible NULL dereference
       [not found] ` <1441883893-20596-1-git-send-email-sudipm.mukherjee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2015-09-11 12:11   ` Jarkko Nikula
       [not found]     ` <55F2C4F4.3090704-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Jarkko Nikula @ 2015-09-11 12:11 UTC (permalink / raw)
  To: Sudip Mukherjee, Mark Brown
  Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA, linux-spi-u79uwXL29TY76Z2rM5mHXA

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-ofJRbWXBVFamYgehrs7/Lw@public.gmane.org>
> ---
>   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-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>

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-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Tested-by: Jarkko Nikula <jarkko.nikula-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] spi: spidev: fix possible NULL dereference
       [not found]     ` <55F2C4F4.3090704-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
@ 2015-09-11 12:25       ` Mark Brown
       [not found]         ` <20150911122513.GT12027-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2015-09-11 12:25 UTC (permalink / raw)
  To: Jarkko Nikula
  Cc: Sudip Mukherjee, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-spi-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 643 bytes --]

On Fri, Sep 11, 2015 at 03:11:32PM +0300, Jarkko Nikula wrote:

> 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-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>

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

The patch was already applied :(

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] spi: spidev: fix possible NULL dereference
       [not found]         ` <20150911122513.GT12027-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
@ 2015-09-11 12:49           ` Sudip Mukherjee
  2015-09-11 14:21             ` Mark Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Sudip Mukherjee @ 2015-09-11 12:49 UTC (permalink / raw)
  To: Mark Brown
  Cc: Jarkko Nikula, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-spi-u79uwXL29TY76Z2rM5mHXA

On Fri, Sep 11, 2015 at 01:25:13PM +0100, Mark Brown wrote:
> On Fri, Sep 11, 2015 at 03:11:32PM +0300, Jarkko Nikula wrote:
> 
> > 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-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
> 
> > 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 majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] spi: spidev: fix possible NULL dereference
  2015-09-11 12:49           ` Sudip Mukherjee
@ 2015-09-11 14:21             ` Mark Brown
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2015-09-11 14:21 UTC (permalink / raw)
  To: Sudip Mukherjee
  Cc: Jarkko Nikula, linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	linux-spi-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 365 bytes --]

On Fri, Sep 11, 2015 at 06:19:45PM +0530, Sudip Mukherjee wrote:
> On Fri, Sep 11, 2015 at 01:25:13PM +0100, Mark Brown wrote:

> > 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.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-11 14:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-10 11:18 [PATCH] spi: spidev: fix possible NULL dereference Sudip Mukherjee
     [not found] ` <1441883893-20596-1-git-send-email-sudipm.mukherjee-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2015-09-11 12:11   ` Jarkko Nikula
     [not found]     ` <55F2C4F4.3090704-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-09-11 12:25       ` Mark Brown
     [not found]         ` <20150911122513.GT12027-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-09-11 12:49           ` Sudip Mukherjee
2015-09-11 14:21             ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).