Linux ATA/IDE development
 help / color / mirror / Atom feed
From: Damien Le Moal <dlemoal@kernel.org>
To: hexlabsecurity@proton.me, Niklas Cassel <cassel@kernel.org>
Cc: linux-ide@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] ata: libata-core: Clamp the concurrent positioning ranges count
Date: Mon, 22 Jun 2026 20:36:59 +0900	[thread overview]
Message-ID: <3c3c4501-b91f-4066-9865-db734e1e77cd@kernel.org> (raw)
In-Reply-To: <20260619-b4-disp-6200c44e-v1-1-4624a4707d9e@proton.me>

On 6/20/26 11:36, Bryam Vargas via B4 Relay wrote:
> From: Bryam Vargas <hexlabsecurity@proton.me>
> 
> ata_dev_config_cpr() sizes the log buffer from the length reported in
> the GPL directory but takes the number of range descriptors from buf[0],
> which the device reports independently. A device advertising a small log
> but a large count makes the descriptor loop read past the buffer: a
> one-sector log with buf[0] = 255 reaches up to 7704 bytes beyond the
> 512-byte allocation, a slab out-of-bounds read whose contents are then
> handed to the initiator through INQUIRY VPD page B9h.
> 
> Clamp the descriptor count to what the allocated buffer holds, as
> sd_read_cpr() already does on the SCSI side.
> 
> Fixes: c745dfc541e7 ("libata: fix reading concurrent positioning ranges log")
> Cc: stable@vger.kernel.org
> Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
> ---
>  drivers/ata/libata-core.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
> index 3d0027ec33c2..e8d708f0810e 100644
> --- a/drivers/ata/libata-core.c
> +++ b/drivers/ata/libata-core.c
> @@ -2832,6 +2832,17 @@ static void ata_dev_config_cpr(struct ata_device *dev)
>  	if (!nr_cpr)
>  		goto out;
>  
> +	/*
> +	 * The log size is reported in the GPL directory independently of the
> +	 * number of range descriptors in buf[0]. Clamp the count to what the
> +	 * allocated buffer holds so the loop below cannot read past it.
> +	 */
> +	if (buf_len < 64 + (size_t)nr_cpr * 32) {
> +		nr_cpr = buf_len > 64 ? (buf_len - 64) / 32 : 0;
> +		if (!nr_cpr)
> +			goto out;
> +	}

If the device gives an invalid number of ranges, we should not try to fix the
broken value and warn and ignore it entirely. So let's simplify this:

	if (buf_len < 64 + (size_t)nr_cpr * 32) {
		ata_dev_warn(dev,
			"Invalid number of concurrent positioning ranges\n");
		goto out;
	}


-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2026-06-22 11:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-20  2:36 [PATCH 0/2] ata: bound the concurrent positioning ranges count from the device Bryam Vargas via B4 Relay
2026-06-20  2:36 ` [PATCH 1/2] ata: libata-core: Clamp the concurrent positioning ranges count Bryam Vargas via B4 Relay
2026-06-22 11:36   ` Damien Le Moal [this message]
2026-06-20  2:36 ` [PATCH 2/2] ata: libata-scsi: Bound the VPD B9h ranges to the response buffer Bryam Vargas via B4 Relay
2026-06-22 11:42   ` 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=3c3c4501-b91f-4066-9865-db734e1e77cd@kernel.org \
    --to=dlemoal@kernel.org \
    --cc=cassel@kernel.org \
    --cc=hexlabsecurity@proton.me \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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