Skip to content

Commit 6950c27

Browse files
Wu Bogregkh
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/[email protected] Acked-by: Douglas Gilbert <[email protected]> Signed-off-by: Wu Bo <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]> Signed-off-by: Sasha Levin <[email protected]> [groeck: Backport to v5.4.y and older kernels] Signed-off-by: Guenter Roeck <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 23d07a9 commit 6950c27

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

drivers/scsi/sg.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,10 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
695695
hp->flags = input_size; /* structure abuse ... */
696696
hp->pack_id = old_hdr.pack_id;
697697
hp->usr_ptr = NULL;
698-
if (__copy_from_user(cmnd, buf, cmd_size))
698+
if (__copy_from_user(cmnd, buf, cmd_size)) {
699+
sg_remove_request(sfp, srp);
699700
return -EFAULT;
701+
}
700702
/*
701703
* SG_DXFER_TO_FROM_DEV is functionally equivalent to SG_DXFER_FROM_DEV,
702704
* but is is possible that the app intended SG_DXFER_TO_DEV, because there

0 commit comments

Comments
 (0)