Re: [PATCH v7 4/7] nvmem: layouts: add Microchip/SST SFDP EUI layout driver

[email protected]
Newsgroups org.kernel.vger.linux-devicetree
Message-ID <[email protected]>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Unloading the `microchip-sst26vf-sfdp-eui` module leaves a dangling `read_post_process` function pointer in the NVMEM core, leading to a kernel panic when the cell is subsequently read.
--

--- Patch [4]: [PATCH v7 4/7] nvmem: layouts: add Microchip/SST SFDP EUI layout driver ---
commit ede7813294e82294452049f0c0c040524f47bb8e
Author: Manikandan Muralidharan <[email protected]>

nvmem: layouts: add Microchip/SST SFDP EUI layout driver

This commit adds an NVMEM layout driver for Microchip/SST SFDP flashes.
It locates the vendor-specific parameter table at runtime and exposes the
EUI-48 identifier as an NVMEM cell to be used as a MAC address.

> diff --git a/drivers/nvmem/layouts/sst26vf-sfdp-eui.c b/drivers/nvmem/layouts/sst26vf-sfdp-eui.c
> new file mode 100644
> index 0000000000000..641318d6f0af6
> --- /dev/null
> +++ b/drivers/nvmem/layouts/sst26vf-sfdp-eui.c
[ ... ]
> +static int sfdp_eui_add_cells(struct nvmem_layout *layout)
> +{
[ ... ]
> +	info.name = "mac-address";
> +	info.offset = base + SFDP_MCHP_EUI48_OFFSET;
> +	info.bytes = ETH_ALEN;
> +	info.np = of_get_child_by_name(layout_np, "mac-address");
> +	info.read_post_process = sfdp_eui_read_post_process;
> +
> +	ret = nvmem_add_one_cell(nvmem, &info);

[Severity: High]
Does registering this read_post_process callback create a dangling pointer
when the module is unloaded?

[ ... ]
> +static void sfdp_eui_remove(struct nvmem_layout *layout)
> +{
> +	nvmem_layout_unregister(layout);
> +}

[Severity: High]
Can unloading this module lead to a kernel panic?

Because nvmem_layout_unregister() is an empty stub in the NVMEM core, the
cells added by this layout are never removed.

If the module is unloaded, the sysfs entry for the cell remains active.
A subsequent read of the sysfs file will invoke the read_post_process
callback, which now points to freed module memory, causing a panic.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.