linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND] scsi: sg: Prevent potential double frees in sg driver
@ 2018-10-01 16:15 Evan Green
  2018-10-01 17:12 ` Nick Desaulniers
  2018-10-01 23:34 ` Douglas Gilbert
  0 siblings, 2 replies; 5+ messages in thread
From: Evan Green @ 2018-10-01 16:15 UTC (permalink / raw)
  To: Doug Gilbert, James E.J. Bottomley, Martin K. Petersen,
	linux-scsi, linux-kernel
  Cc: Nick Desaulniers, Christoph Hellwig, Robb Glasser, Evan Green, stable

From: Robb Glasser <rglasser@google.com>

sg_ioctl could be spammed by requests, leading to a double free in
__free_pages. This protects the entry points of sg_ioctl where the
memory could be corrupted by a double call to __free_pages if multiple
requests are happening concurrently.

Signed-off-by: Robb Glasser <rglasser@google.com>
Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
Signed-off-by: Evan Green <evgreen@chromium.org>
Cc: stable@vger.kernel.org

---
Reposting this patch from last summer, as it looks like it fell in between
the cracks.

 drivers/scsi/sg.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index 8a254bb46a9b..25579d8a16b5 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -924,8 +924,10 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
 			return -ENXIO;
 		if (!access_ok(VERIFY_WRITE, p, SZ_SG_IO_HDR))
 			return -EFAULT;
+		mutex_lock(&sfp->parentdp->open_rel_lock);
 		result = sg_new_write(sfp, filp, p, SZ_SG_IO_HDR,
 				 1, read_only, 1, &srp);
+		mutex_unlock(&sfp->parentdp->open_rel_lock);
 		if (result < 0)
 			return result;
 		result = wait_event_interruptible(sfp->read_wait,
-- 
2.19.0.605.g01d371f741-goog


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

* Re: [PATCH RESEND] scsi: sg: Prevent potential double frees in sg driver
  2018-10-01 16:15 [PATCH RESEND] scsi: sg: Prevent potential double frees in sg driver Evan Green
@ 2018-10-01 17:12 ` Nick Desaulniers
  2018-10-01 17:20   ` Bart Van Assche
  2018-10-01 23:34 ` Douglas Gilbert
  1 sibling, 1 reply; 5+ messages in thread
From: Nick Desaulniers @ 2018-10-01 17:12 UTC (permalink / raw)
  To: hch
  Cc: Doug Gilbert, James E.J. Bottomley, Martin K. Petersen,
	linux-scsi, LKML, Robb Glasser, evgreen, stable

On Mon, Oct 1, 2018 at 9:16 AM Evan Green <evgreen@chromium.org> wrote:
>
> From: Robb Glasser <rglasser@google.com>
>
> sg_ioctl could be spammed by requests, leading to a double free in
> __free_pages. This protects the entry points of sg_ioctl where the
> memory could be corrupted by a double call to __free_pages if multiple
> requests are happening concurrently.
>
> Signed-off-by: Robb Glasser <rglasser@google.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Evan Green <evgreen@chromium.org>
> Cc: stable@vger.kernel.org
>
> ---
> Reposting this patch from last summer, as it looks like it fell in between
> the cracks.

Christoph, do you still feel strongly about: https://lkml.org/lkml/2017/8/5/75 ?

>
>  drivers/scsi/sg.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 8a254bb46a9b..25579d8a16b5 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -924,8 +924,10 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
>                         return -ENXIO;
>                 if (!access_ok(VERIFY_WRITE, p, SZ_SG_IO_HDR))
>                         return -EFAULT;
> +               mutex_lock(&sfp->parentdp->open_rel_lock);
>                 result = sg_new_write(sfp, filp, p, SZ_SG_IO_HDR,
>                                  1, read_only, 1, &srp);
> +               mutex_unlock(&sfp->parentdp->open_rel_lock);
>                 if (result < 0)
>                         return result;
>                 result = wait_event_interruptible(sfp->read_wait,
> --
> 2.19.0.605.g01d371f741-goog
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH RESEND] scsi: sg: Prevent potential double frees in sg driver
  2018-10-01 17:12 ` Nick Desaulniers
@ 2018-10-01 17:20   ` Bart Van Assche
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2018-10-01 17:20 UTC (permalink / raw)
  To: Nick Desaulniers, hch
  Cc: Doug Gilbert, James E.J. Bottomley, Martin K. Petersen,
	linux-scsi, LKML, Robb Glasser, evgreen, stable

On Mon, 2018-10-01 at 10:12 -0700, Nick Desaulniers wrote:
> On Mon, Oct 1, 2018 at 9:16 AM Evan Green <evgreen@chromium.org> wrote:
> > 
> > From: Robb Glasser <rglasser@google.com>
> > 
> > sg_ioctl could be spammed by requests, leading to a double free in
> > __free_pages. This protects the entry points of sg_ioctl where the
> > memory could be corrupted by a double call to __free_pages if multiple
> > requests are happening concurrently.
> > 
> > Signed-off-by: Robb Glasser <rglasser@google.com>
> > Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> > Signed-off-by: Evan Green <evgreen@chromium.org>
> > Cc: stable@vger.kernel.org
> > 
> > ---
> > Reposting this patch from last summer, as it looks like it fell in between
> > the cracks.
> 
> Christoph, do you still feel strongly about: https://lkml.org/lkml/2017/8/5/75 ?

I don't know how Christoph feels about it, but serializing all SG I/O seems
like a regression to me. If one sg command hangs I usually try to send
another sg command to the same SCSI device from another shell to get more
information about the nature of the hang. Serializing all SG I/O would make
that impossible.

Bart.

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

* Re: [PATCH RESEND] scsi: sg: Prevent potential double frees in sg driver
  2018-10-01 16:15 [PATCH RESEND] scsi: sg: Prevent potential double frees in sg driver Evan Green
  2018-10-01 17:12 ` Nick Desaulniers
@ 2018-10-01 23:34 ` Douglas Gilbert
  2018-10-02 15:21   ` Evan Green
  1 sibling, 1 reply; 5+ messages in thread
From: Douglas Gilbert @ 2018-10-01 23:34 UTC (permalink / raw)
  To: Evan Green, James E.J. Bottomley, Martin K. Petersen, linux-scsi,
	linux-kernel
  Cc: Nick Desaulniers, Christoph Hellwig, Robb Glasser, stable

On 2018-10-02 02:15 AM, Evan Green wrote:
> From: Robb Glasser <rglasser@google.com>
> 
> sg_ioctl could be spammed by requests, leading to a double free in
> __free_pages. This protects the entry points of sg_ioctl where the
> memory could be corrupted by a double call to __free_pages if multiple
> requests are happening concurrently.

Hi,
I  don't like this patch. I would like to see the trace for the double
call to the __free_pages you are referring too. A test program that
show the fault, perhaps?

I have test code to "spam" the sg driver and have not seen a double
__free_pages that you refer to (see sg3_utils package version 1.44,
testing/sg_tst_async.cpp).

Currently I am dusting off 20 years of "laparoscopic" patches to the sg
driver that have made a bit of a mess of the naming and comments. Also
the 16 outstanding requests per file descriptor limit is being removed.
Then I want to add the SG_IOSUBMIT and SG_IORECEIVE ioctls proposed by
Linus Torvalds two week ago.

Executive summary: nak, without further information

Doug Gilbert

> Signed-off-by: Robb Glasser <rglasser@google.com>
> Signed-off-by: Nick Desaulniers <ndesaulniers@google.com>
> Signed-off-by: Evan Green <evgreen@chromium.org>
> Cc: stable@vger.kernel.org
> 
> ---
> Reposting this patch from last summer, as it looks like it fell in between
> the cracks.
> 
>   drivers/scsi/sg.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 8a254bb46a9b..25579d8a16b5 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -924,8 +924,10 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
>   			return -ENXIO;
>   		if (!access_ok(VERIFY_WRITE, p, SZ_SG_IO_HDR))
>   			return -EFAULT;
> +		mutex_lock(&sfp->parentdp->open_rel_lock);
>   		result = sg_new_write(sfp, filp, p, SZ_SG_IO_HDR,
>   				 1, read_only, 1, &srp);
> +		mutex_unlock(&sfp->parentdp->open_rel_lock);
>   		if (result < 0)
>   			return result;
>   		result = wait_event_interruptible(sfp->read_wait,
> 


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

* Re: [PATCH RESEND] scsi: sg: Prevent potential double frees in sg driver
  2018-10-01 23:34 ` Douglas Gilbert
@ 2018-10-02 15:21   ` Evan Green
  0 siblings, 0 replies; 5+ messages in thread
From: Evan Green @ 2018-10-02 15:21 UTC (permalink / raw)
  To: dgilbert
  Cc: jejb, martin.petersen, linux-scsi, linux-kernel, ndesaulniers,
	hch, rglasser, stable

On Mon, Oct 1, 2018 at 4:34 PM Douglas Gilbert <dgilbert@interlog.com> wrote:
>
> On 2018-10-02 02:15 AM, Evan Green wrote:
> > From: Robb Glasser <rglasser@google.com>
> >
> > sg_ioctl could be spammed by requests, leading to a double free in
> > __free_pages. This protects the entry points of sg_ioctl where the
> > memory could be corrupted by a double call to __free_pages if multiple
> > requests are happening concurrently.
>
> Hi,
> I  don't like this patch. I would like to see the trace for the double
> call to the __free_pages you are referring too. A test program that
> show the fault, perhaps?
>
> I have test code to "spam" the sg driver and have not seen a double
> __free_pages that you refer to (see sg3_utils package version 1.44,
> testing/sg_tst_async.cpp).
>
> Currently I am dusting off 20 years of "laparoscopic" patches to the sg
> driver that have made a bit of a mess of the naming and comments. Also
> the 16 outstanding requests per file descriptor limit is being removed.
> Then I want to add the SG_IOSUBMIT and SG_IORECEIVE ioctls proposed by
> Linus Torvalds two week ago.
>
> Executive summary: nak, without further information

That makes sense. Thanks for taking a look.

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

end of thread, other threads:[~2018-10-02 15:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-01 16:15 [PATCH RESEND] scsi: sg: Prevent potential double frees in sg driver Evan Green
2018-10-01 17:12 ` Nick Desaulniers
2018-10-01 17:20   ` Bart Van Assche
2018-10-01 23:34 ` Douglas Gilbert
2018-10-02 15:21   ` Evan Green

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