Re: [PATCH] nvmem: layouts: onie-tlv: validate the base MAC address length
From: Miquel Raynal
Date: Thu Nov 19 2026 - 07:21:33 EST
On 17/11/2026 at 15:27:53 -07, James Hilliard <james.hilliard1@xxxxxxxxx> wrote:
> 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")
Not sure this qualifies as a fix.
> Cc: stable@xxxxxxxxxxxxxxx
Especially not for stable kernels.
> 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;
How useful is it in the ONIE case? I don't know. Doesn't hurt...
Reviewed-by: Miquel Raynal <miquel.raynal@xxxxxxxxxxx>