scsi: bsg: fix buffer overflow in scsi_bsg_uring_cmd()
Subsystems (2)
PATCH 1/1 scsi: bsg: fix buffer overflow in scsi_bsg_uring_cmd()
The bounds checking in scsi_bsg_uring_cmd() does not work because cmd->request_len is a u32 and scmd->cmd_len is a u16. We check that scmd->cmd_len is valid but if the cmd->request_len is more than USHRT_MAX it would still lead to a buffer overflow when we do the copy_from_user().
---
This email is a free service from the Smatch-CI project [smatch.sf.net].
drivers/scsi/scsi_bsg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/scsi_bsg.c +2 -2
@@ -137,11 +137,11 @@ static int scsi_bsg_uring_cmd(struct request_queue *q, struct io_uring_cmd *ioucreturn PTR_ERR (req); scmd =blk_mq_rq_to_pdu (req); - scmd->cmd_len = cmd->request_len; -if (scmd->cmd_len >sizeof (scmd->cmnd)) { +if (cmd->request_len >sizeof (scmd->cmnd)) { ret = -EINVAL ; goto out_free_req; } + scmd->cmd_len = cmd->request_len; scmd->allowed =SG_DEFAULT_RETRIES ;if (copy_from_user (scmd->cmnd,uptr64 (cmd->request), cmd->request_len)) {
Signature · 1 line
2.53.0
Jens Axboe
AppliedQuoted 8 lines · Dan Carpenter
The bounds checking in
scsi_bsg_uring_cmd()does not work becausecmd->request_lenis a u32 andscmd->cmd_lenis a u16. We check thatscmd->cmd_lenis valid but if thecmd->request_lenis more thanUSHRT_MAXit would still lead to a buffer overflow when we do thecopy_from_user().[...]
Applied, thanks!
[1/1] scsi: bsg: fix buffer overflow in scsi_bsg_uring_cmd()
commit: 0a42ca4d2bff6306dd574a7897258fd02c2e6930
Best regards,
Signature · 1 line
Jens Axboe