Linux ATA/IDE development
 help / color / mirror / Atom feed
From: Niklas Cassel <cassel@kernel.org>
To: Karuna Ramkumar <rkaruna@google.com>,
	Damien Le Moal <dlemoal@kernel.org>
Cc: sashiko-reviews@lists.linux.dev, linux-ide@vger.kernel.org,
	Igor Pylypiv <ipylypiv@google.com>,
	TJ Adams <tadamsjr@google.com>
Subject: Re: [PATCH v2] ata: libata-scsi: limit simulated SCSI command copy to response length
Date: Thu, 09 Jul 2026 15:11:16 +0200	[thread overview]
Message-ID: <0E78BE5F-B4EE-460A-A6D5-F0CE47BFC7DF@kernel.org> (raw)
In-Reply-To: <CAD50Xqra-_2CnJdGPJtWeOZT-Ne4wRRcQEL+6uy1--jPRYwACQ@mail.gmail.com>

On 9 July 2026 05:34:14 CEST, Karuna Ramkumar <rkaruna@google.com> wrote:
>On Mon, Jul 6, 2026 at 6:10 PM Damien Le Moal <dlemoal@kernel.org> wrote:
>>
>> On 7/7/26 08:10, Karuna Ramkumar wrote:
>> > Before I start working on this, I would love to hear your feedback on:
>> > 1. Whether you think this API update (passing `rbuf_len` down to all
>> > actors and helper functions) is the right approach, or if you prefer
>> > simpler, and more localized checks elsewhere.
>>
>> I do not think it is necessary at all because rbuf is statically declared:
>>
>> static u8 ata_scsi_rbuf[ATA_SCSI_RBUF_SIZE];
>>
>> So the buffer address and maximum size is known to all functions using it.
>>
>> > 2. What would be the best way to test all these simulated command
>> > paths to ensure the fix is verified appropriately?
>>
>> Most functions for emulated commands generate only a very small amount of data,
>> far below ATA_SCSI_RBUF_SIZE. So I would suggest that we simply add checks to
>> the functions which may potentially exceed that. Off the top of my head, I do
>> not know if we have any, but we should just check.
>>
>> Note that ideally, we should have each function allocate their own local buffer
>> to handle the translation. But this is right now a little hard to do because
>> these translation/emulation functions are called with the port locked, so we
>> would have a memory allocation for a potentially large-ish buffer under a spin
>> lock, which means no reclaim/no wait allocation, and thus potential for failure
>> which we do not have right now. A proper/ideal fix would need to drop
>> ata_scsi_rbuf, have some helpers for managing the internal buffer and redesign
>> the submission path to not have the port locked until the translation is
>> actually generated. That is all more work and more changes.
>>
>> So as a first step, let's check the emulation function if any of them can exceed
>> ATA_SCSI_RBUF_SIZE in size, fail them with internal target failure.
>
>Hi Damien,
>
>I went through all the SCSI actor functions in libata-scsi.c and
>calculated their maximum size consumption.
>
>As you mentioned, most command emulations triggered via actor
>callbacks write a fixed or small amount of payload, and are well
>within the 2048 byte limit of `ata_scsi_rbuf`.
>
>There are two functions that can potentially overflow though:
>
>1. ata_scsiop_inq_b9: Writes 64 + nr_cpr * 32 bytes. If nr_cpr crosses
>62, then this can cause an overflow
>2. ata_format_dsm_trim_descr: Writes trmax * 8 bytes. If trmax > 2048
>/ 8, then this can cause an overflow too.
>


Please note that ata_format_dsm_trim_descr()
was changed recently, on libata for-7.3 branch:

https://git.kernel.org/pub/scm/linux/kernel/git/libata/linux.git/log/?h=for-7.3

I don't think that this function can overflow anymore.


Kind regards,
Niklas

  parent reply	other threads:[~2026-07-09 13:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-02  2:01 [PATCH v2] ata: libata-scsi: limit simulated SCSI command copy to response length Karuna Ramkumar
2026-07-02  2:14 ` sashiko-bot
2026-07-02  2:30   ` Damien Le Moal
2026-07-06 23:10     ` Karuna Ramkumar
2026-07-07  1:10       ` Damien Le Moal
2026-07-09  3:34         ` Karuna Ramkumar
2026-07-09  5:45           ` Damien Le Moal
2026-07-09 13:11           ` Niklas Cassel [this message]
2026-07-03  6:17 ` Damien Le Moal

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=0E78BE5F-B4EE-460A-A6D5-F0CE47BFC7DF@kernel.org \
    --to=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=ipylypiv@google.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=rkaruna@google.com \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tadamsjr@google.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