linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: George Kennedy <george.kennedy@oracle.com>,
	syzkaller <syzkaller@googlegroups.com>,
	Douglas Gilbert <dgilbert@interlog.com>,
	"Martin K . Petersen" <martin.petersen@oracle.com>,
	Sasha Levin <sashal@kernel.org>,
	jejb@linux.ibm.com, linux-scsi@vger.kernel.org
Subject: [PATCH AUTOSEL 5.10 21/43] scsi: scsi_debug: Sanity check block descriptor length in resp_mode_select()
Date: Tue, 30 Nov 2021 09:49:58 -0500	[thread overview]
Message-ID: <20211130145022.945517-21-sashal@kernel.org> (raw)
In-Reply-To: <20211130145022.945517-1-sashal@kernel.org>

From: George Kennedy <george.kennedy@oracle.com>

[ Upstream commit e0a2c28da11e2c2b963fc01d50acbf03045ac732 ]

In resp_mode_select() sanity check the block descriptor len to avoid UAF.

BUG: KASAN: use-after-free in resp_mode_select+0xa4c/0xb40 drivers/scsi/scsi_debug.c:2509
Read of size 1 at addr ffff888026670f50 by task scsicmd/15032

CPU: 1 PID: 15032 Comm: scsicmd Not tainted 5.15.0-01d0625 #15
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
Call Trace:
 <TASK>
 dump_stack_lvl+0x89/0xb5 lib/dump_stack.c:107
 print_address_description.constprop.9+0x28/0x160 mm/kasan/report.c:257
 kasan_report.cold.14+0x7d/0x117 mm/kasan/report.c:443
 __asan_report_load1_noabort+0x14/0x20 mm/kasan/report_generic.c:306
 resp_mode_select+0xa4c/0xb40 drivers/scsi/scsi_debug.c:2509
 schedule_resp+0x4af/0x1a10 drivers/scsi/scsi_debug.c:5483
 scsi_debug_queuecommand+0x8c9/0x1e70 drivers/scsi/scsi_debug.c:7537
 scsi_queue_rq+0x16b4/0x2d10 drivers/scsi/scsi_lib.c:1521
 blk_mq_dispatch_rq_list+0xb9b/0x2700 block/blk-mq.c:1640
 __blk_mq_sched_dispatch_requests+0x28f/0x590 block/blk-mq-sched.c:325
 blk_mq_sched_dispatch_requests+0x105/0x190 block/blk-mq-sched.c:358
 __blk_mq_run_hw_queue+0xe5/0x150 block/blk-mq.c:1762
 __blk_mq_delay_run_hw_queue+0x4f8/0x5c0 block/blk-mq.c:1839
 blk_mq_run_hw_queue+0x18d/0x350 block/blk-mq.c:1891
 blk_mq_sched_insert_request+0x3db/0x4e0 block/blk-mq-sched.c:474
 blk_execute_rq_nowait+0x16b/0x1c0 block/blk-exec.c:63
 sg_common_write.isra.18+0xeb3/0x2000 drivers/scsi/sg.c:837
 sg_new_write.isra.19+0x570/0x8c0 drivers/scsi/sg.c:775
 sg_ioctl_common+0x14d6/0x2710 drivers/scsi/sg.c:941
 sg_ioctl+0xa2/0x180 drivers/scsi/sg.c:1166
 __x64_sys_ioctl+0x19d/0x220 fs/ioctl.c:52
 do_syscall_64+0x3a/0x80 arch/x86/entry/common.c:50
 entry_SYSCALL_64_after_hwframe+0x44/0xae arch/x86/entry/entry_64.S:113

Link: https://lore.kernel.org/r/1637262208-28850-1-git-send-email-george.kennedy@oracle.com
Reported-by: syzkaller <syzkaller@googlegroups.com>
Acked-by: Douglas Gilbert <dgilbert@interlog.com>
Signed-off-by: George Kennedy <george.kennedy@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/scsi/scsi_debug.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index f2f202424c6b2..54075d57729cb 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -2501,11 +2501,11 @@ static int resp_mode_select(struct scsi_cmnd *scp,
 			    __func__, param_len, res);
 	md_len = mselect6 ? (arr[0] + 1) : (get_unaligned_be16(arr + 0) + 2);
 	bd_len = mselect6 ? arr[3] : get_unaligned_be16(arr + 6);
-	if (md_len > 2) {
+	off = bd_len + (mselect6 ? 4 : 8);
+	if (md_len > 2 || off >= res) {
 		mk_sense_invalid_fld(scp, SDEB_IN_DATA, 0, -1);
 		return check_condition_result;
 	}
-	off = bd_len + (mselect6 ? 4 : 8);
 	mpage = arr[off] & 0x3f;
 	ps = !!(arr[off] & 0x80);
 	if (ps) {
-- 
2.33.0


  parent reply	other threads:[~2021-11-30 14:53 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-30 14:49 [PATCH AUTOSEL 5.10 01/43] ASoC: mediatek: mt8173-rt5650: Rename Speaker control to Ext Spk Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 02/43] ASoC: Intel: sof_sdw: Add support for SKU 0AF3 product Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 03/43] ASoC: Intel: sof_sdw: Add support for SKU 0B00 and 0B01 products Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 04/43] ASoC: Intel: sof_sdw: Add support for SKU 0B11 product Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 05/43] ASoC: Intel: sof_sdw: Add support for SKU 0B13 product Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 06/43] ASoC: Intel: sof_sdw: Add support for SKU 0B29 product Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 07/43] ASoC: Intel: sof_sdw: Add support for SKU 0B12 product Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 08/43] ASoC: mediatek: mt8173: Fix debugfs registration for components Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 09/43] ASoC: qdsp6: q6adm: improve error reporting Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 10/43] ASoC: qdsp6: q6routing: validate port id before setting up route Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 11/43] xen/privcmd: make option visible in Kconfig Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 12/43] NFSv4.1: handle NFS4ERR_NOSPC by CREATE_SESSION Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 13/43] scsi: scsi_debug: Fix type in min_t to avoid stack OOB Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 14/43] atlantic: fix double-free in aq_ring_tx_clean Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 15/43] stmmac_pci: Fix underflow size in stmmac_rx Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 16/43] HID: multitouch: Fix Iiyama ProLite T1931SAW (0eef:0001 again!) Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 17/43] parisc: Provide an extru_safe() macro to extract unsigned bits Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 18/43] parisc: Fix extraction of hash lock bits in syscall.S Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 19/43] parisc: Convert PTE lookup to use extru_safe() macro Sasha Levin
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 20/43] selftests/tc-testings: Be compatible with newer tc output Sasha Levin
2021-11-30 14:49 ` Sasha Levin [this message]
2021-11-30 14:49 ` [PATCH AUTOSEL 5.10 22/43] locking/rwsem: Optimize down_read_trylock() under highly contended case Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 23/43] i2c: i801: Fix interrupt storm from SMB_ALERT signal Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 24/43] mmc: spi: Add device-tree SPI IDs Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 25/43] net: chelsio: cxgb4vf: Fix an error code in cxgb4vf_pci_probe() Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 26/43] smb2: clarify rc initialization in smb2_reconnect Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 27/43] nvmet-tcp: fix a race condition between release_queue and io_work Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 28/43] nvmet-tcp: add an helper to free the cmd buffers Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 29/43] nvmet-tcp: fix memory leak when performing a controller reset Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 30/43] nvme-tcp: validate R2T PDU in nvme_tcp_handle_r2t() Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 31/43] nvme-tcp: fix memory leak when freeing a queue Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 32/43] nvme-pci: add NO APST quirk for Kioxia device Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 33/43] nvme: fix write zeroes pi Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 34/43] xen: add "not_essential" flag to struct xenbus_driver Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 35/43] xen: flag xen_drm_front to be not essential for system boot Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 36/43] xen: flag hvc_xen " Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 37/43] xen: flag pvcalls-front " Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 38/43] xen: flag xen_snd_front " Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 39/43] PM: hibernate: Fix snapshot partial write lengths Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 40/43] vhost-vdpa: clean irqs before reseting vdpa device Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 41/43] net: qed: fix the array may be out of bound Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 42/43] net: ptp: add a definition for the UDP port for IEEE 1588 general messages Sasha Levin
2021-11-30 14:50 ` [PATCH AUTOSEL 5.10 43/43] fs: ntfs: Limit NTFS_RW to page sizes smaller than 64k Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211130145022.945517-21-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=dgilbert@interlog.com \
    --cc=george.kennedy@oracle.com \
    --cc=jejb@linux.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=stable@vger.kernel.org \
    --cc=syzkaller@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).