All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Eugene Korenevsky <ekorenevsky@aliyun.com>
Cc: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] nvme: nvme_identify_ns_descs: prevent oob
Date: Mon, 1 Dec 2025 07:21:06 +0100	[thread overview]
Message-ID: <20251201062106.GA19164@lst.de> (raw)
In-Reply-To: <aStReVPqMORJssLT@localhost.localdomain>

On Sat, Nov 29, 2025 at 11:03:05PM +0300, Eugene Korenevsky wrote:
> -	int status, pos, len;
> +	int status, len, remain;

Pre-existing issue, but all but len here should be unsigned.

> +	remain = NVME_IDENTIFY_DATA_SIZE;
> +	cur = data;
> +	while (remain >= sizeof(*cur)) {
>  		if (cur->nidl == 0)
>  			break;
> +		if (sizeof(*cur) + cur->nidl > remain)
> +			break;
>  
>  		len = nvme_process_ns_desc(ctrl, &info->ids, cur, &csi_seen);
>  		if (len < 0)
>  			break;
>  
>  		len += sizeof(*cur);
> +		remain -= len;
> +		cur += len;
>  	}

I don't think this works, cur is a nvme_ns_id_desc pointer, so it will
be increased by len multiplied by the size of it.

I think this would work muc heasier if you'd do away with remain,
use and just use cur locally, and instead maintain an offet;  Something
like:

	offset = 0;
	do {
		cur = data + offset;

		...

		offset += len;
	} while (offset < NVME_IDENTIFY_DATA_SIZE - sizeof(*cur));



      reply	other threads:[~2025-12-01  6:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-29 20:03 [PATCH v2] nvme: nvme_identify_ns_descs: prevent oob Eugene Korenevsky
2025-12-01  6:21 ` Christoph Hellwig [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=20251201062106.GA19164@lst.de \
    --to=hch@lst.de \
    --cc=axboe@kernel.dk \
    --cc=ekorenevsky@aliyun.com \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sagi@grimberg.me \
    /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.