mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] nvmem: layouts: onie-tlv: validate the base MAC address length
@ 2026-11-17 22:27 James Hilliard
  0 siblings, 0 replies; only message in thread
From: James Hilliard @ 2026-11-17 22:27 UTC (permalink / raw)
  To: Miquel Raynal, Srinivas Kandagatla, Greg Kroah-Hartman
  Cc: linux-kernel, stable, James Hilliard

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@vger.kernel.org
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 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@gmail.com>


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-17 22:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 22:27 [PATCH] nvmem: layouts: onie-tlv: validate the base MAC address length James Hilliard

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®