Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Loic Poulain" <loic.poulain@oss.qualcomm.com>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v9 06/10] block: implement NVMEM provider
Date: Fri, 31 Jul 2026 16:01:23 +0000	[thread overview]
Message-ID: <20260731160124.148EB1F00ACA@smtp.kernel.org> (raw)
In-Reply-To: <20260730-block-as-nvmem-v9-6-f72935817dbf@oss.qualcomm.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Information Leak and TOCTOU race via dev_t reuse in NVMEM reads.
- [Medium] API Contract Violation: NVMEM reads use BLK_OPEN_EXCL, causing legitimate reads to fail with -EBUSY.
--

--- Patch [6]: [PATCH v9 06/10] block: implement NVMEM provider ---
commit 0a2168c8881ee78cc2df1f1e3f11c57aff14d1fd
Author: Loic Poulain <loic.poulain@oss.qualcomm.com>

block: implement NVMEM provider

Allow referencing a partition in device tree for the kernel and Wi-Fi
drivers to access it via the NVMEM layer. The NVMEM device is registered
for a block device whose OF node describes an NVMEM layout.

> The NVMEM device is a read-only side channel: the block device stays
> fully usable, reads are performed with a non-exclusive BLK_OPEN_READ
> open, and no synchronization is done against concurrent writes to the
> same region. This is acceptable for the intended use case of write-once,
> factory-provisioned data.

[Severity: Medium]
The commit message states that reads are performed with a non-exclusive
BLK_OPEN_READ open, but the implementation uses BLK_OPEN_EXCL. Will this
cause legitimate NVMEM reads to fail with -EBUSY if the underlying block
device or any of its partitions are already claimed by a filesystem?

> diff --git a/block/blk-nvmem.c b/block/blk-nvmem.c
> new file mode 100644
> index 0000000000000..05bc35b9b8f37
> --- /dev/null
> +++ b/block/blk-nvmem.c

[ ... ]

> +static int blk_nvmem_reg_read(void *priv, unsigned int from,
> +			      void *val, size_t bytes)
> +{
> +	struct block_device *bdev = priv;
> +	struct file *bdev_file;
> +	loff_t pos = from;
> +	ssize_t ret;
> +
> +	/* open and prevent other exclusive openers */
> +	bdev_file = bdev_file_open_by_dev(bdev->bd_dev,
> +					  BLK_OPEN_READ | BLK_OPEN_EXCL,
> +					  blk_nvmem_reg_read, NULL);

[Severity: High]
Is there a risk of a TOCTOU race and information leak here via dev_t reuse?

If the original partition is logically deleted, making its dev_t available,
and a new partition is created with the same dev_t, bdev_file_open_by_dev()
could look up and read from the newly created partition instead of the
original NVMEM partition.

Could we verify that file_bdev(bdev_file) == bdev after opening to ensure
the dev_t has not been reassigned to a different block device?

> +	if (IS_ERR(bdev_file))
> +		return PTR_ERR(bdev_file);
> +
> +	ret = kernel_read(bdev_file, val, bytes, &pos);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260730-block-as-nvmem-v9-0-f72935817dbf@oss.qualcomm.com?part=6

  reply	other threads:[~2026-07-31 16:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-30 16:00 [PATCH v9 00/10] Support for block device NVMEM providers Loic Poulain
2026-07-30 16:00 ` [PATCH v9 01/10] dt-bindings: mmc: Document fixed-layout NVMEM provider support Loic Poulain
2026-07-31  8:39   ` Bartosz Golaszewski
2026-07-31 16:01   ` sashiko-bot
2026-07-30 16:00 ` [PATCH v9 02/10] dt-bindings: net: wireless: qcom,ath10k: Document NVMEM cells Loic Poulain
2026-07-30 16:00 ` [PATCH v9 03/10] dt-bindings: bluetooth: qcom: Add NVMEM BD address cell Loic Poulain
2026-07-30 16:00 ` [PATCH v9 04/10] nvmem: layouts: Support fixed-layout as the nvmem device node itself Loic Poulain
2026-07-31 16:01   ` sashiko-bot
2026-07-30 16:00 ` [PATCH v9 05/10] block: partitions: of: Attach partition fwnode to the block device Loic Poulain
2026-07-31  8:40   ` Bartosz Golaszewski
2026-07-31 16:01   ` sashiko-bot
2026-07-30 16:00 ` [PATCH v9 06/10] block: implement NVMEM provider Loic Poulain
2026-07-31 16:01   ` sashiko-bot [this message]
2026-07-30 16:00 ` [PATCH v9 07/10] net: of_net: Add of_get_nvmem_eui48() helper for EUI-48 lookup Loic Poulain
2026-07-30 16:00 ` [PATCH v9 08/10] Bluetooth: hci_sync: Add NVMEM-backed BD address retrieval Loic Poulain
2026-07-31 16:01   ` sashiko-bot
2026-07-30 16:00 ` [PATCH v9 09/10] Bluetooth: qca: Set NVMEM BD address quirks when address is invalid Loic Poulain
2026-07-30 16:00 ` [PATCH v9 10/10] arm64: dts: qcom: arduino-imola: Describe NVMEM layout for WiFi/BT addresses Loic Poulain
2026-07-31 16:01   ` sashiko-bot

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=20260731160124.148EB1F00ACA@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=loic.poulain@oss.qualcomm.com \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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