Linux ATA/IDE development
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: Zhao Gongyi <zhaogongyi@bytedance.com>,
	Niklas Cassel <cassel@kernel.org>
Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] ata: libata-scsi: reject data-in commands with a data-out buffer
Date: Fri, 30 Oct 2026 08:18:04 +0700	[thread overview]
Message-ID: <2def2444-0b73-4371-9ba2-78af235e64cb@kernel.org> (raw)
In-Reply-To: <36648b88-c295-4acb-8b6e-25d742d50946@bytedance.com>

On 2026/10/29 11:37, Zhao Gongyi wrote:
> Hi Damien,
> 
> Thanks for the review.
> 
> On 10/28/26 9:59 PM, Damien Le Moal wrote:
>> On 2026/10/28 18:39, Zhao Gongyi wrote:
>>
>> No they cannot, as long as the kernel is correct for internally issued commands.
>> But t is not clear here if you are still talking about commands passed through
>> SG_IO.
>>
> 
> Yes, by "translated commands" I meant commands submitted through SG_IO
> and subsequently translated by libata, not commands issued internally
> by the kernel. I will make that explicit and narrow the description to
> the affected ZBC IN and GET PHYSICAL ELEMENT STATUS paths.
> 
>>
>> Why is this being checked here and not in the SCSI layer (sg driver and bsg)? It
>> seems sensible to check this there.
>>
> 
> I checked the SG and BSG submission paths. For data-direction purposes,
> they derive the request direction from the SG_IO descriptor and otherwise
> treat the CDB as opaque. I could not find a generic helper that derives
> the transfer direction of arbitrary standard, service-action, ATA
> pass-through, and vendor-specific CDBs.

Yeah, forgot about that. Ideally, we should get the ioctl(SG_IO) to return
-EINVAL for an invalid data direction but that indeed requires parsing the
commands, which we do *not* want to do.

> For simulated commands, libata itself performs the CPU-side write. For
> the ZBC IN and GET PHYSICAL ELEMENT STATUS translation paths, the actual
> ATA data direction is known after xlat_func() has built qc->tf, and their
> completion handlers may modify the receive buffer.

Yep, these are the only ones we can catch easily. Other commands we do not look
at/know about will keep potentially triggering iommu page faults, but that is
fine as that is not a crash. However, ideally, that should lead to the command
being failed, which it seems we are unable to do... Did you check if we can
propagate the fault into a the request to indicate a failure?

>> The CDB may be perfectly correct. The error is in the SG_IO descriptor setup,
>> NOT in the CDB. So returning invalid field in CDB seems very misleading.
>> This is not something that SAT defines as far as I know, so we need to find a
>> sense code that is more informative. Please have a loo at
>> include/scsi/scsi_sense.h to see if something better exist.
>>
> 
> Agreed. INVALID FIELD IN CDB is misleading here. I propose returning
> ABORTED COMMAND / DATA PHASE ERROR (4b/00) instead.

Not sure if that one is ideal either. Let me check and get back to you next week.


-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2026-10-30  1:18 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-27  9:08 [PATCH] ata: libata-scsi: reject to-device transfers for simulated commands Zhao Gongyi
2026-10-27 21:22 ` Niklas Cassel
2026-10-28 11:39 ` [PATCH v2] ata: libata-scsi: reject data-in commands with a data-out buffer Zhao Gongyi
2026-10-28 11:53   ` sashiko-bot
2026-10-28 13:16     ` Niklas Cassel
2026-10-28 13:59   ` Damien Le Moal
2026-10-29  4:37     ` Zhao Gongyi
2026-10-30  1:18       ` Damien Le Moal [this message]
2026-10-30  3:19         ` Zhao Gongyi

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=2def2444-0b73-4371-9ba2-78af235e64cb@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=cassel@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=zhaogongyi@bytedance.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