[PATCH] nvmem: layouts: onie-tlv: validate the base MAC address length

From: James Hilliard

Date: Tue Nov 17 2026 - 17:28:12 EST


The ONIE base MAC address field is six bytes, but the layout accepts
any length from the TLV. Its read callback calls eth_addr_add(), which
always accesses six bytes, even if the cell is shorter.

Check the declared field length before registering the cell. The read
callback gets the transfer length rounded up to the provider's word
size, which can be larger than a valid six-byte address. Skip a
malformed MAC field and continue registering the other cells.

Fixes: d3c0d12f6474 ("nvmem: layouts: onie-tlv: Add new layout driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: James Hilliard <james.hilliard1@xxxxxxxxx>
---
drivers/nvmem/layouts/onie-tlv.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c
index 4da3a704388e..85562fc6b06f 100644
--- a/drivers/nvmem/layouts/onie-tlv.c
+++ b/drivers/nvmem/layouts/onie-tlv.c
@@ -30,9 +30,9 @@ struct onie_tlv {
u8 len;
} __packed;

-static const char *onie_tlv_cell_name(u8 type)
+static const char *onie_tlv_cell_name(const struct onie_tlv *tlv)
{
- switch (type) {
+ switch (tlv->type) {
case 0x21:
return "product-name";
case 0x22:
@@ -40,7 +40,7 @@ static const char *onie_tlv_cell_name(u8 type)
case 0x23:
return "serial-number";
case 0x24:
- return "mac-address";
+ return tlv->len == ETH_ALEN ? "mac-address" : NULL;
case 0x25:
return "manufacture-date";
case 0x26:
@@ -117,7 +117,7 @@ static int onie_tlv_add_cells(struct device *dev, struct nvmem_device *nvmem,
break;
}

- cell.name = onie_tlv_cell_name(tlv.type);
+ cell.name = onie_tlv_cell_name(&tlv);
if (!cell.name)
goto next;


---
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-mac-length-v1-a1fd08e2b185

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