Skip to content

Commit 2a4b6e8

Browse files
Wu BoLee Jones
authored andcommitted
scsi: sg: add sg_remove_request in sg_write
commit 83c6f23 upstream. If the __copy_from_user function failed we need to call sg_remove_request in sg_write. Link: https://lore.kernel.org/r/610618d9-e983-fd56-ed0f-639428343af7@huawei.com Acked-by: Douglas Gilbert <dgilbert@interlog.com> Signed-off-by: Wu Bo <wubo40@huawei.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org> [groeck: Backport to v5.4.y and older kernels] Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Lee Jones <lee.jones@linaro.org> Change-Id: I827ec9cf2ac7d7b94941956db5b7a37af8413bf6
1 parent baf235d commit 2a4b6e8

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

drivers/scsi/sg.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,10 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
707707
hp->flags = input_size; /* structure abuse ... */
708708
hp->pack_id = old_hdr.pack_id;
709709
hp->usr_ptr = NULL;
710-
if (__copy_from_user(cmnd, buf, cmd_size))
710+
if (__copy_from_user(cmnd, buf, cmd_size)) {
711+
sg_remove_request(sfp, srp);
711712
return -EFAULT;
713+
}
712714
/*
713715
* SG_DXFER_TO_FROM_DEV is functionally equivalent to SG_DXFER_FROM_DEV,
714716
* but is is possible that the app intended SG_DXFER_TO_DEV, because there

0 commit comments

Comments
 (0)