mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] nvmem: layouts: onie-tlv: check both field header and value bounds
@ 2026-11-17 22:19 James Hilliard
  2026-11-24 21:19 ` Srinivas Kandagatla
  0 siblings, 1 reply; 2+ messages in thread
From: James Hilliard @ 2026-11-17 22:19 UTC (permalink / raw)
  To: Miquel Raynal, Srinivas Kandagatla, Greg Kroah-Hartman
  Cc: linux-kernel, stable, James Hilliard

The table CRC does not validate individual field lengths. The field
iterator can read a two-byte header when only one byte remains. Its
value length check also counts the header as available space and can
publish a cell extending beyond the table.

Check the remaining space before reading the header and exclude the
header from the space available for the value. Stop at the first
truncated field, keeping any complete cells already registered.

Fixes: d3c0d12f6474 ("nvmem: layouts: onie-tlv: Add new layout driver")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/sashiko-outbox-219531@kernel.org/
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 drivers/nvmem/layouts/onie-tlv.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c
index 4da3a704388e..1e397565b928 100644
--- a/drivers/nvmem/layouts/onie-tlv.c
+++ b/drivers/nvmem/layouts/onie-tlv.c
@@ -110,8 +110,15 @@ static int onie_tlv_add_cells(struct device *dev, struct nvmem_device *nvmem,
 		return -ENOENT;
 
 	while (offset < data_len) {
+		size_t remaining = data_len - offset;
+
+		if (remaining < sizeof(tlv)) {
+			dev_err(dev, "Truncated field header at 0x%x\n", hdr_len + offset);
+			break;
+		}
+
 		memcpy(&tlv, data + offset, sizeof(tlv));
-		if (offset + tlv.len >= data_len) {
+		if (tlv.len > remaining - sizeof(tlv)) {
 			dev_err(dev, "Out of bounds field (0x%x bytes at 0x%x)\n",
 				tlv.len, hdr_len + offset);
 			break;

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
base-tree: https://git.kernel.org/pub/scm/linux/kernel/git/srini/nvmem.git for-fixes
change-id: 20261117-submit-nvmem-onie-tlv-bounds-v1-81e03449bcf6

Best regards,
--  
James Hilliard <james.hilliard1@gmail.com>


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] nvmem: layouts: onie-tlv: check both field header and value bounds
  2026-11-17 22:19 [PATCH] nvmem: layouts: onie-tlv: check both field header and value bounds James Hilliard
@ 2026-11-24 21:19 ` Srinivas Kandagatla
  0 siblings, 0 replies; 2+ messages in thread
From: Srinivas Kandagatla @ 2026-11-24 21:19 UTC (permalink / raw)
  To: Miquel Raynal, Greg Kroah-Hartman, James Hilliard; +Cc: linux-kernel, stable


On Tue, 17 Nov 2026 15:19:45 -0700, James Hilliard wrote:
> The table CRC does not validate individual field lengths. The field
> iterator can read a two-byte header when only one byte remains. Its
> value length check also counts the header as available space and can
> publish a cell extending beyond the table.
> 
> Check the remaining space before reading the header and exclude the
> header from the space available for the value. Stop at the first
> truncated field, keeping any complete cells already registered.
> 
> [...]

Applied, thanks!

[1/1] nvmem: layouts: onie-tlv: check both field header and value bounds
      commit: 1f2bc0f3b7bd5e459f6f751d912ecc85009b170a

Best regards,
-- 
Srinivas Kandagatla <srini@kernel.org>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-24 21:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 22:19 [PATCH] nvmem: layouts: onie-tlv: check both field header and value bounds James Hilliard
2026-11-24 21:19 ` Srinivas Kandagatla

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®