Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: John Garry <john.g.garry@oracle.com>
To: Chao S <coshi036@gmail.com>
Cc: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
	Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	Daniel Wagner <dwagner@suse.de>, Hannes Reinecke <hare@suse.de>,
	Maurizio Lombardi <mlombard@arkamax.eu>,
	Sungwoo Kim <iam@sung-woo.kim>, Dave Tian <daveti@purdue.edu>,
	Weidong Zhu <weizhu@fiu.edu>
Subject: Re: [PATCH v3] nvme: core: reject invalid LBA data size from Identify Namespace
Date: Tue, 14 Jul 2026 09:18:37 +0100	[thread overview]
Message-ID: <1be7cde9-e065-4980-ade9-6efc9278c12d@oracle.com> (raw)
In-Reply-To: <CACd_6n2AZvgi1B8Vn8S6NwytDkqHmS=4z-1sxjmk+FPfWv_JMQ@mail.gmail.com>

This response took almost 3 weeks. The previous response took again 
almost 3 weeks. kernel development may be relatively slow moving, but 
it's not that slow. You need to respond much more promptly to keep up 
with current development.

> 
> Here is the concrete change (drivers/nvme/host/core.c,
> nvme_update_ns_info_block()):
> 
>    unsigned int memflags;
>    sector_t capacity;
>    unsigned lbaf;
> + u64 nsze;
>    int ret;
> ...
> - if (id->lbaf[lbaf].ds < SECTOR_SHIFT ||
> -    check_shl_overflow(le64_to_cpu(id->nsze),
> -       id->lbaf[lbaf].ds - SECTOR_SHIFT,
> -       &capacity)) {
> + /*
> + * check_shl_overflow() also rejects a data size below SECTOR_SHIFT,
> + * as that makes the shift count negative, so no separate lower-bound
> + * test is needed.  Feed nsze through a plain u64 so sparse does not
> + * trip over the __le64 provenance of le64_to_cpu().
> + */
> + nsze = le64_to_cpu(id->nsze);
> + if (check_shl_overflow(nsze, id->lbaf[lbaf].ds - SECTOR_SHIFT,
> +       &capacity)) {
>    dev_warn_once(ns->ctrl->device,
>    "invalid LBA data size %u, skipping namespace\n",
>    id->lbaf[lbaf].ds);
>    ret = -ENODEV;
>    goto out;
>    }
> 
> Two things:
> 
> 1. Drops the explicit ds < SECTOR_SHIFT test as redundant --
>     check_shl_overflow() already returns true for the resulting negative
>     shift. I confirmed ds=0 and ds=8 are still rejected without it.
> 
> 2. Routes le64_to_cpu(id->nsze) through a plain u64 local, which is what
>     silences the C=1 warning (sparse loses the __le64 provenance when the
>     value is passed straight into check_shl_overflow()).
> 
> Behavior is otherwise unchanged. Since the original is already in
> v7.2-rc1, I'll send this as a standalone patch on top of mainline
> (Reported-by: you) unless you'd prefer a different form.

My fix is now in mainline 
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v7.2-rc3&id=92f58587a04c94985fd4a9e3575720b054c432bf, 
so any change which you want to make must be on top of that.

> 
> Thanks,
> Chao
> 
> On Wed, Jun 24, 2026 at 9:15 AM John Garry <john.g.garry@oracle.com> wrote:
>>
>> On 23/06/2026 21:37, Chao S wrote:
>>>> BTW, I have thought that check_shl_overflow would catch
>>>> id->lbaf[lbaf].ds < SECTOR_SHIFT (so that we don't need the extra check).
>>> Confirmed -- check_shl_overflow() returns true for the negative shift
>>> that ds < SECTOR_SHIFT produces (_to_shift collapses to 0 and the
>>> _to_shift != _s test fires). I checked ds=0 and ds=8: both are still
>>> rejected with the explicit lower-bound test removed, so it is redundant.
>>>
>>> For the C=1 warning, the minimal fix is to drop that redundant check and
>>> feed nsze through a plain u64 local -- as Keith found, laundering the
>>> le64_to_cpu() result through a non-__le64 type makes the warning go away:
>>>
>>> u64 nsze;
>>> ...
>>> nsze = le64_to_cpu(id->nsze);
>>> if (check_shl_overflow(nsze, id->lbaf[lbaf].ds - SECTOR_SHIFT,
>>>         &capacity)) {
>>> dev_warn_once(...);
>>> ret = -ENODEV;
>>> goto out;
>>> }
>>>
>>> This keeps check_shl_overflow() in one tested helper and avoids a
>>> wrapper. John's nvme_valid_ds() works too; if we prefer that, I'd name it
>>> for its actual sense (it returns true on overflow, i.e. invalid), e.g.
>>> nvme_ds_overflows().
>>>
>>> One note: I'd lean toward keeping check_shl_overflow() rather than
>>> open-coding the bound. It folds the lower-bound (negative shift) and the
>>> overflow case into one tested helper, so we don't have to re-derive the
>>> boundary by hand -- e.g. the lower bound is on ds itself, not on the
>>> post-subtract (ds - SECTOR_SHIFT) shift, which I found easy to get
>>> subtly wrong.
>>
>> What exactly is your proposed change (to what is in the tree)?
>>
>>>
>>> Keith, since v3 is already in your tree: do you want an incremental fixup
>>> on top, or a v4 to replace the applied commit? I have both ready.
>>>
>>
>>
>>



  reply	other threads:[~2026-07-14  8:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-15 18:58 [PATCH v3] nvme: core: reject invalid LBA data size from Identify Namespace Chao Shi
2026-05-20 19:33 ` Keith Busch
2026-06-02 13:10 ` John Garry
2026-06-02 15:15   ` Keith Busch
2026-06-02 15:42     ` Keith Busch
2026-06-02 16:18       ` John Garry
2026-06-03 10:08         ` John Garry
2026-06-23 20:37           ` Chao S
2026-06-24 13:14             ` John Garry
2026-07-13 16:58               ` Chao S
2026-07-14  8:18                 ` John Garry [this message]
2026-07-14 16:07                   ` Chao S

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=1be7cde9-e065-4980-ade9-6efc9278c12d@oracle.com \
    --to=john.g.garry@oracle.com \
    --cc=axboe@kernel.dk \
    --cc=coshi036@gmail.com \
    --cc=daveti@purdue.edu \
    --cc=dwagner@suse.de \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=iam@sung-woo.kim \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=mlombard@arkamax.eu \
    --cc=sagi@grimberg.me \
    --cc=weizhu@fiu.edu \
    /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