Skip to content

Commit f930c70

Browse files
Johannes Thumshirnmartinkpetersen
authored andcommitted
scsi: sg: only check for dxfer_len greater than 256M
Don't make any assumptions on the sg_io_hdr_t::dxfer_direction or the sg_io_hdr_t::dxferp in order to determine if it is a valid request. The only way we can check for bad requests is by checking if the length exceeds 256M. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Fixes: 28676d8 (scsi: sg: check for valid direction before starting the request) Reported-by: Jason L Tibbitts III <tibbs@math.uh.edu> Tested-by: Jason L Tibbitts III <tibbs@math.uh.edu> Suggested-by: Doug Gilbert <dgilbert@interlog.com> Cc: Doug Gilbert <dgilbert@interlog.com> Cc: <stable@vger.kernel.org> Reviewed-by: Hannes Reinecke <hare@suse.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent e6fd916 commit f930c70

File tree

1 file changed

+1
-30
lines changed

1 file changed

+1
-30
lines changed

drivers/scsi/sg.c

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -751,35 +751,6 @@ sg_new_write(Sg_fd *sfp, struct file *file, const char __user *buf,
751751
return count;
752752
}
753753

754-
static bool sg_is_valid_dxfer(sg_io_hdr_t *hp)
755-
{
756-
switch (hp->dxfer_direction) {
757-
case SG_DXFER_NONE:
758-
if (hp->dxferp || hp->dxfer_len > 0)
759-
return false;
760-
return true;
761-
case SG_DXFER_FROM_DEV:
762-
/*
763-
* for SG_DXFER_FROM_DEV we always set dxfer_len to > 0. dxferp
764-
* can either be NULL or != NULL so there's no point in checking
765-
* it either. So just return true.
766-
*/
767-
return true;
768-
case SG_DXFER_TO_DEV:
769-
case SG_DXFER_TO_FROM_DEV:
770-
if (!hp->dxferp || hp->dxfer_len == 0)
771-
return false;
772-
return true;
773-
case SG_DXFER_UNKNOWN:
774-
if ((!hp->dxferp && hp->dxfer_len) ||
775-
(hp->dxferp && hp->dxfer_len == 0))
776-
return false;
777-
return true;
778-
default:
779-
return false;
780-
}
781-
}
782-
783754
static int
784755
sg_common_write(Sg_fd * sfp, Sg_request * srp,
785756
unsigned char *cmnd, int timeout, int blocking)
@@ -800,7 +771,7 @@ sg_common_write(Sg_fd * sfp, Sg_request * srp,
800771
"sg_common_write: scsi opcode=0x%02x, cmd_size=%d\n",
801772
(int) cmnd[0], (int) hp->cmd_len));
802773

803-
if (!sg_is_valid_dxfer(hp))
774+
if (hp->dxfer_len >= SZ_256M)
804775
return -EINVAL;
805776

806777
k = sg_start_req(srp, cmnd);

0 commit comments

Comments
 (0)