Skip to content

Commit

Permalink
scsi: sg: add sg_remove_request in sg_write
Browse files Browse the repository at this point in the history
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]>
Signed-off-by: Lee Jones <[email protected]>
Change-Id: I827ec9cf2ac7d7b94941956db5b7a37af8413bf6
  • Loading branch information
Wu Bo authored and Lee Jones committed Jun 2, 2020
1 parent baf235d commit 2a4b6e8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/scsi/sg.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,10 @@ sg_write(struct file *filp, const char __user *buf, size_t count, loff_t * ppos)
hp->flags = input_size; /* structure abuse ... */
hp->pack_id = old_hdr.pack_id;
hp->usr_ptr = NULL;
if (__copy_from_user(cmnd, buf, cmd_size))
if (__copy_from_user(cmnd, buf, cmd_size)) {
sg_remove_request(sfp, srp);
return -EFAULT;
}
/*
* SG_DXFER_TO_FROM_DEV is functionally equivalent to SG_DXFER_FROM_DEV,
* but is is possible that the app intended SG_DXFER_TO_DEV, because there
Expand Down

0 comments on commit 2a4b6e8

Please sign in to comment.