nvmem: brcm_nvram: fix out-of-bounds access on malformed flash data
PATCH 1/1 nvmem: brcm_nvram: fix out-of-bounds access on malformed flash data
The length check in brcm_nvram_parse() validated header->len against priv->nvmem_size (the full partition size) instead of priv->data_len (the actual allocated data buffer). A malformed flash partition with header->len between the two would pass the check, causing brcm_nvram_add_cells() to read and write priv->data[len - 1] beyond the heap allocation.
Also add a minimum bound: len < sizeof(*header) could underflow the data[len - 1] access.
Fix both bounds by rejecting len outside [sizeof(*header), priv->data_len].
--- drivers/nvmem/brcm_nvram.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/nvmem/brcm_nvram.c +7 -3
@@ -187,9 +187,13 @@ static int brcm_nvram_parse(struct brcm_nvram *priv) } len =le32_to_cpu (header->len); -if (len > priv->nvmem_size) { -dev_err (dev,"NVRAM length (%zd) exceeds mapped size (%zd)\n" , len, - priv->nvmem_size); +if (len <sizeof (*header)) { +dev_err (dev,"NVRAM length (%zd) too small\n" , len); +return -EINVAL ; + } +if (len > priv->data_len) { +dev_err (dev,"NVRAM length (%zd) exceeds data size (%zd)\n" , len, + priv->data_len);return -EINVAL ; }
Signature · 1 line
2.55.0
Quoted 8 lines · Rosen Penev
The length check in
brcm_nvram_parse()validatedheader->lenagainstpriv->nvmem_size(the full partition size) instead ofpriv->data_len(the actual allocated data buffer). A malformed flash partition withheader->lenbetween the two would pass the check, causingbrcm_nvram_add_cells()to read and write priv->data[len - 1] beyond the heap allocation.[...]
Applied, thanks!
[1/1] nvmem: brcm_nvram: fix out-of-bounds access on malformed flash data
commit: 95e486974c4a0a567e57212fcfca82b372dd8df6
Best regards,
Signature · 1 line
Srinivas Kandagatla <[email protected]>