mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-31 10:31:33 -04:00
nvmem: brcm_nvram: reject empty NVRAM partition
If the partition is completely erased (all padding bytes), the trimming loop reduces data_len to 0. devm_kzalloc(dev, 0, GFP_KERNEL) returns ZERO_SIZE_PTR ((void *)16), which is non-NULL and bypasses the NULL check. The subsequent cast of priv->data to struct brcm_nvram_header * and dereference of header->magic causes a page fault on address 0x10. Reject data_len smaller than the header before allocating. Assisted-by: opencode:big-pickle Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: Srinivas Kandagatla <srini@kernel.org> Link: https://patch.msgid.link/20260729094647.111468-13-srini@kernel.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
1ae37d3551
commit
fde46579cf
@@ -84,6 +84,11 @@ static int brcm_nvram_copy_data(struct brcm_nvram *priv, struct platform_device
|
||||
}
|
||||
WARN(priv->data_len > SZ_128K, "Unexpected (big) NVRAM size: %zu B\n", priv->data_len);
|
||||
|
||||
if (priv->data_len < sizeof(struct brcm_nvram_header)) {
|
||||
dev_err(priv->dev, "NVRAM data too small (%zu)\n", priv->data_len);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
priv->data = devm_kzalloc(priv->dev, priv->data_len, GFP_KERNEL);
|
||||
if (!priv->data)
|
||||
return -ENOMEM;
|
||||
|
||||
Reference in New Issue
Block a user