From: Jay Vadayath <jay@artiphishell.com>
To: "Martin K. Petersen" <martin.petersen@oracle.com>,
"James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>
Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Jay Vadayath <jay@artiphishell.com>
Subject: [PATCH] scsi: sd: bound MODE SENSE offset in sd_read_app_tag_own()
Date: Fri, 17 Jul 2026 15:14:38 -0700 [thread overview]
Message-ID: <20260717221442.57163-1-jay@artiphishell.com> (raw)
sd_read_app_tag_own() issues a MODE SENSE(10) against the target and
then indexes into the returned buffer at
offset = data.header_length + data.block_descriptor_length;
buffer[offset] and buffer[offset + 4]. data.block_descriptor_length is
copied verbatim from the untrusted device response and can be as large
as 65535, so with a hostile response the offset can point well past the
36-byte SD_BUF_SIZE buffer the caller passes in, producing a
slab-out-of-bounds read.
KASAN report from an emulated USB mass storage device (raw-gadget +
dummy_hcd) returning a MODE SENSE(10) response with
block_descriptor_length = 600:
BUG: KASAN: slab-out-of-bounds in sd_revalidate_disk+0x863f/0x8940
Read of size 1 at addr ffff88800634de60 by task kworker/u8:0/12
Call Trace:
dump_stack_lvl+0x64/0x80
print_report+0xce/0x620
kasan_report+0xec/0x120
sd_revalidate_disk+0x863f/0x8940
sd_probe+0x79f/0xf20
really_probe+0x1c8/0x950
__driver_probe_device+0x1a5/0x430
driver_probe_device+0x45/0xd0
__device_attach_driver+0x156/0x230
bus_for_each_drv+0x10f/0x190
__device_attach+0x18e/0x3b0
device_initial_probe+0x78/0xa0
bus_probe_device+0x57/0x130
Reject responses whose mode page offset does not leave room for the
five bytes of the ATO mode page that this function subsequently
touches, and log the rejection.
This bug was discovered by Artiphishell's vTriage pipeline, which
generated a userspace raw-gadget reproducer that reliably triggers the
KASAN report on an unpatched kernel. The fix below was drafted with the
Claude coding assistant; a userspace reproducer is available on
request.
Assisted-by: Claude:claude-opus-4-7
Signed-off-by: Jay Vadayath <jay@artiphishell.com>
---
drivers/scsi/sd.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -3366,6 +3366,18 @@ static void sd_read_app_tag_own(struct scsi_disk *sdkp, unsigned char *buffer)
}
offset = data.header_length + data.block_descriptor_length;
+
+ /*
+ * block_descriptor_length is taken verbatim from the (untrusted)
+ * device response and can be as large as 65535, so the computed
+ * offset may point well past the SD_BUF_SIZE buffer that only holds
+ * the 36 bytes we asked for. Validate it before dereferencing to
+ * avoid a slab out-of-bounds read.
+ */
+ if (offset < 0 || offset + 5 >= 36) {
+ sd_first_printk(KERN_ERR, sdkp, "ATO mode page too long\n");
+ return;
+ }
if ((buffer[offset] & 0x3f) != 0x0a) {
sd_first_printk(KERN_ERR, sdkp, "ATO Got wrong page\n");
next reply other threads:[~2026-07-17 22:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 22:14 Jay Vadayath [this message]
2026-07-17 22:29 ` [PATCH] scsi: sd: bound MODE SENSE offset in sd_read_app_tag_own() sashiko-bot
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=20260717221442.57163-1-jay@artiphishell.com \
--to=jay@artiphishell.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.