From: sashiko-bot@kernel.org
To: "James Hilliard" <james.hilliard1@gmail.com>,
"Srinivas Kandagatla" <srini@kernel.org>,
"Mathieu Dubois-Briand" <mathieu.dubois-briand@bootlin.com>,
"Michael Walle" <mwalle@kernel.org>,
"Rafał Miłecki" <rafal@milecki.pl>
Cc: "Bartosz Golaszewski" <bartosz.golaszewski@oss.qualcomm.com>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Miquel Raynal" <miquel.raynal@bootlin.com>,
"Paul Cercueil" <paul@crapouillou.net>,
linux-mtd@lists.infradead.org
Subject: Re: [PATCH 07/11] nvmem: distinguish layout cells from provider cells
Date: Tue, 17 Nov 2026 19:51:58 +0000 [thread overview]
Message-ID: <sashiko-outbox-219531@kernel.org> (raw)
In-Reply-To: <20261117-submit-nvmem-provider-lifetime-v1-v1-7-3cfbd48812b5@gmail.com>
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 2 related pre-existing issues it does not
introduce:
- [Medium] nvmem: core: memory leak on error path in
nvmem_add_cells_from_dt() [1]
- [Critical] nvmem: layouts: onie-tlv: out-of-bounds read in
onie_tlv_add_cells() [2]
--
commit 0c2f98425a6e2037eca692b433e46249d579c5ee
Author: James Hilliard <james.hilliard1@gmail.com>
nvmem: distinguish layout cells from provider cells
This commit records the owning layout on NVMEM cell entries and adds
layout-specific cell registration helpers so layout cells can be
distinguished from provider cells.
> diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c
> index 14cc70e8ce785..57c1da5ab547c 100644
> --- a/drivers/nvmem/core.c
> +++ b/drivers/nvmem/core.c
[ ... ]
> @@ -882,7 +907,8 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem)
> return 0;
> }
>
> -int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
> +static int __nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np,
> + struct nvmem_layout *layout)
> {
> struct device *dev = &nvmem->dev;
> const __be32 *addr;
> @@ -924,7 +950,7 @@ int nvmem_add_cells_from_dt(struct nvmem_device *nvmem, struct device_node *np)
> if (nvmem->fixup_dt_cell_info)
> nvmem->fixup_dt_cell_info(nvmem, &info);
>
> - ret = nvmem_add_one_cell(nvmem, &info);
> + ret = __nvmem_add_one_cell(nvmem, &info, layout);
> kfree(info.name);
> if (ret) {
> of_node_put(info.np);
[Severity: Medium]
This problem wasn't introduced by this patch, but does
__nvmem_add_cells_from_dt() leak info.name [1] when the "bits"
property is invalid?
drivers/nvmem/core.c:__nvmem_add_cells_from_dt() {
...
info.name = kasprintf(GFP_KERNEL, "%pOFn", child);
addr = of_get_property(child, "bits", &len);
if (addr && len == (2 * sizeof(u32))) {
info.bit_offset = be32_to_cpup(addr++);
info.nbits = be32_to_cpup(addr);
if (info.bit_offset >= BITS_PER_BYTE * info.bytes ||
info.nbits < 1 ||
info.bit_offset + info.nbits > BITS_PER_BYTE * info.bytes) {
dev_err(dev, "nvmem: invalid bits on %pOF\n", child);
return -EINVAL;
}
}
...
}
Returning -EINVAL directly skips kfree(info.name).
[ ... ]
> diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c
> index 4da3a704388e9..99e7a5406b4ce 100644
> --- a/drivers/nvmem/layouts/onie-tlv.c
> +++ b/drivers/nvmem/layouts/onie-tlv.c
> @@ -95,18 +95,19 @@ static nvmem_cell_post_process_t onie_tlv_read_cb(u8 type, u8 *buf)
> return NULL;
> }
>
> -static int onie_tlv_add_cells(struct device *dev, struct nvmem_device *nvmem,
> +static int onie_tlv_add_cells(struct nvmem_layout *layout,
> size_t data_len, u8 *data)
> {
> + struct device *dev = &layout->dev;
> struct nvmem_cell_info cell = {};
> - struct device_node *layout;
> + struct device_node *layout_np;
> struct onie_tlv tlv;
> unsigned int hdr_len = sizeof(struct onie_tlv_hdr);
> unsigned int offset = 0;
> int ret;
>
> - layout = of_nvmem_layout_get_container(nvmem);
> - if (!layout)
> + layout_np = of_nvmem_layout_get_container(layout->nvmem);
> + if (!layout_np)
> return -ENOENT;
>
> while (offset < data_len) {
> @@ -123,13 +124,13 @@ static int onie_tlv_add_cells(struct device *dev, struct nvmem_device *nvmem,
>
> cell.offset = hdr_len + offset + sizeof(tlv.type) + sizeof(tlv.len);
> cell.bytes = tlv.len;
> - cell.np = of_get_child_by_name(layout, cell.name);
> + cell.np = of_get_child_by_name(layout_np, cell.name);
> cell.read_post_process = onie_tlv_read_cb(tlv.type, data + offset + sizeof(tlv));
>
> - ret = nvmem_add_one_cell(nvmem, &cell);
> + ret = nvmem_layout_add_cell(layout, &cell);
[Severity: Critical]
This problem wasn't introduced by this patch, but can a malformed ONIE TLV
table trigger an out-of-bounds read in onie_tlv_add_cells() [2]?
drivers/nvmem/layouts/onie-tlv.c:onie_tlv_add_cells() {
...
while (offset < data_len) {
memcpy(&tlv, data + offset, sizeof(tlv));
if (offset + tlv.len >= data_len) {
...
}
Neither the loop condition nor the bounds check accounts for sizeof(tlv).
If fewer than sizeof(tlv) bytes remain in data, memcpy() reads past the end
of the heap buffer, and a truncated entry with offset + sizeof(tlv) +
tlv.len > data_len can still pass the check and register a cell extending
past the table.
[1] https://sashiko.dev/#/bug/linux-c0ac748f-5eb4-43f2-ad9b-c1ed0e5f7c40
[2] https://sashiko.dev/#/bug/linux-dabf598f-cde5-44cc-a226-fd0a93723e20
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117-submit-nvmem-provider-lifetime-v1-v1-0-3cfbd48812b5@gmail.com?part=7
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2026-11-17 19:52 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 19:38 [PATCH 00/11] nvmem: complete provider and layout disconnection James Hilliard
2026-11-17 19:38 ` James Hilliard
2026-11-17 19:38 ` [PATCH 01/11] nvmem: retain the provider node until device release James Hilliard
2026-11-17 19:38 ` James Hilliard
2026-11-17 19:38 ` [PATCH 02/11] nvmem: drain keepout and cell post-processing accesses James Hilliard
2026-11-17 19:38 ` James Hilliard
2026-11-17 19:50 ` sashiko-bot
2026-11-17 19:38 ` [PATCH 03/11] nvmem: exclude disconnected providers from callback admission James Hilliard
2026-11-17 19:38 ` James Hilliard
2026-11-17 20:07 ` sashiko-bot
2026-11-17 19:38 ` [PATCH 04/11] nvmem: release write protection when the provider disconnects James Hilliard
2026-11-17 19:38 ` James Hilliard
2026-11-17 19:38 ` [PATCH 05/11] nvmem: reference cell entries independently of their provider list James Hilliard
2026-11-17 19:38 ` James Hilliard
2026-11-17 19:48 ` sashiko-bot
2026-11-17 19:38 ` [PATCH 06/11] nvmem: manage cell attributes independently of device resources James Hilliard
2026-11-17 19:38 ` James Hilliard
2026-11-17 19:59 ` sashiko-bot
2026-11-17 19:38 ` [PATCH 07/11] nvmem: distinguish layout cells from provider cells James Hilliard
2026-11-17 19:38 ` James Hilliard
2026-11-17 19:51 ` sashiko-bot [this message]
2026-11-17 19:38 ` [PATCH 08/11] nvmem: disconnect cells before removing their layout James Hilliard
2026-11-17 19:38 ` James Hilliard
2026-11-17 19:38 ` [PATCH 09/11] nvmem: disconnect published devices before registration rollback James Hilliard
2026-11-17 19:38 ` James Hilliard
2026-11-17 19:38 ` [PATCH 10/11] nvmem: u-boot-env: propagate cell registration errors James Hilliard
2026-11-17 19:38 ` James Hilliard
2026-11-17 19:38 ` [PATCH 11/11] nvmem: allow providers to specify an explicit NULL owner James Hilliard
2026-11-17 19:38 ` James Hilliard
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=sashiko-outbox-219531@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=bartosz.golaszewski@oss.qualcomm.com \
--cc=gregkh@linuxfoundation.org \
--cc=james.hilliard1@gmail.com \
--cc=linux-mtd@lists.infradead.org \
--cc=mathieu.dubois-briand@bootlin.com \
--cc=miquel.raynal@bootlin.com \
--cc=mwalle@kernel.org \
--cc=paul@crapouillou.net \
--cc=rafal@milecki.pl \
--cc=sashiko-reviews@lists.linux.dev \
--cc=srini@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 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.