2018-05-18 14:24:14

by Alexander Potapenko

[permalink] [raw]
Subject: [PATCH] scsi: sg: allocate with __GFP_ZERO in sg_build_indirect()

This shall help avoid copying uninitialized memory to the userspace
when calling ioctl(fd, SG_IO) with an empty command.

Reported-by: [email protected]
Cc: [email protected]
Signed-off-by: Alexander Potapenko <[email protected]>
Acked-by: Douglas Gilbert <[email protected]>
Reviewed-by: Johannes Thumshirn <[email protected]>
---
drivers/scsi/sg.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index c198b96368dd..5c40d809830f 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1894,7 +1894,7 @@ sg_build_indirect(Sg_scatter_hold * schp, Sg_fd * sfp, int buff_size)
num = (rem_sz > scatter_elem_sz_prev) ?
scatter_elem_sz_prev : rem_sz;

- schp->pages[k] = alloc_pages(gfp_mask, order);
+ schp->pages[k] = alloc_pages(gfp_mask | __GFP_ZERO, order);
if (!schp->pages[k])
goto out;

--
2.17.0.441.gb46fe60e1d-goog



2018-05-18 14:32:35

by Martin K. Petersen

[permalink] [raw]
Subject: Re: [PATCH] scsi: sg: allocate with __GFP_ZERO in sg_build_indirect()


Alexander,

> This shall help avoid copying uninitialized memory to the userspace
> when calling ioctl(fd, SG_IO) with an empty command.

Applied to 4.17/scsi-fixes. Thank you!

--
Martin K. Petersen Oracle Linux Engineering

2018-05-18 16:19:17

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [PATCH] scsi: sg: allocate with __GFP_ZERO in sg_build_indirect()

On Fri, May 18, 2018 at 04:23:18PM +0200, Alexander Potapenko wrote:
> This shall help avoid copying uninitialized memory to the userspace
> when calling ioctl(fd, SG_IO) with an empty command.

Looks good,

Reviewed-by: Christoph Hellwig <[email protected]>