From: sashiko-bot@kernel.org
To: "Karuna Ramkumar" <rkaruna@google.com>
Cc: linux-ide@vger.kernel.org, dlemoal@kernel.org, cassel@kernel.org
Subject: Re: [PATCH] ata: libata-scsi: add out-of-bounds checks in ata_scsiop_inq_b9
Date: Fri, 10 Jul 2026 19:43:39 +0000 [thread overview]
Message-ID: <20260710194339.AE0161F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260710193235.334782-1-rkaruna@google.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] The newly added bounds check to prevent `page_len > ATA_SCSI_RBUF_SIZE` is mathematically dead code.
--
--- Patch [1]: [PATCH] ata: libata-scsi: add out-of-bounds checks in ata_scsiop_inq_b9 ---
commit bacad4b494e8c54b7f847f50ed2b764d2bdf3fde
Author: Karuna Ramkumar <rkaruna@google.com>
ata: libata-scsi: add out-of-bounds checks in ata_scsiop_inq_b9
This commit adds a bounds check to ata_scsiop_inq_b9() to ensure the
calculated page length does not exceed the SCSI request buffer size. If the
calculated size is larger, the command is aborted to prevent a buffer
overflow.
Link: https://lore.kernel.org/all/0E78BE5F-B4EE-460A-A6D5-F0CE47BFC7DF@kernel.org/
> diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
> --- a/drivers/ata/libata-scsi.c
> +++ b/drivers/ata/libata-scsi.c
[ ... ]
> @@ -2361,15 +2361,22 @@ static unsigned int ata_scsiop_inq_b9(struct ata_device *dev,
[ ... ]
> if (!cpr_log) {
> ata_scsi_set_invalid_field(dev, cmd, 2, 0xff);
> return 0;
> }
>
> + page_len = 64 + (int)cpr_log->nr_cpr * 32;
> + if (page_len > ATA_SCSI_RBUF_SIZE) {
> + ata_scsi_set_sense(dev, cmd, ABORTED_COMMAND, 0, 0);
> + return 0;
> + }
[Severity: Low]
Is this bounds check reachable during normal operation?
Looking at how cpr_log is populated in ata_read_cpr_log(), nr_cpr is
already explicitly validated against ATA_DEV_MAX_CPR. Since ATA_DEV_MAX_CPR
is mathematically derived from ATA_SCSI_RBUF_SIZE, a device reporting a
value exceeding this limit has its log discarded, leaving dev->cpr_log as
NULL.
Because ata_scsiop_inq_b9() immediately returns if cpr_log is NULL right
above this snippet, it seems page_len can never evaluate to a value greater
than ATA_SCSI_RBUF_SIZE. Does this make the new check mathematically dead
code under real inputs?
> +
> /* SCSI Concurrent Positioning Ranges VPD page: SBC-5 rev 1 or later */
> rbuf[1] = 0xb9;
> - put_unaligned_be16(64 + (int)cpr_log->nr_cpr * 32 - 4, &rbuf[2]);
> + put_unaligned_be16(page_len - 4, &rbuf[2]);
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260710193235.334782-1-rkaruna@google.com?part=1
prev parent reply other threads:[~2026-07-10 19:43 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-10 19:32 [PATCH] ata: libata-scsi: add out-of-bounds checks in ata_scsiop_inq_b9 Karuna Ramkumar
2026-07-10 19:43 ` sashiko-bot [this message]
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=20260710194339.AE0161F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=cassel@kernel.org \
--cc=dlemoal@kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=rkaruna@google.com \
--cc=sashiko-reviews@lists.linux.dev \
/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