linux/drivers/mtd/spi-nor
Tudor Ambarus e47029b977 mtd: spi-nor: debugfs: fix out-of-bounds read in spi_nor_params_show()
Sashiko noticed an out-of-bounds read [1].

In spi_nor_params_show(), the snor_f_names array is passed to
spi_nor_print_flags() using sizeof(snor_f_names).

Since snor_f_names is an array of pointers, sizeof() returns the total
number of bytes occupied by the pointers
	(element_count * sizeof(void *))
rather than the element count itself. On 64-bit systems, this makes the
passed length 8x larger than intended.

Inside spi_nor_print_flags(), the 'names_len' argument is used to
bounds-check the 'names' array access. An out-of-bounds read occurs
if a flag bit is set that exceeds the array's actual element count
but is within the inflated byte-size count.

Correct this by using ARRAY_SIZE() to pass the actual number of
string pointers in the array.

Cc: stable@vger.kernel.org
Fixes: 0257be79fc ("mtd: spi-nor: expose internal parameters via debugfs")
Closes: https://sashiko.dev/#/patchset/20260417-die-erase-fix-v2-1-73bb7004ebad%40infineon.com [1]
Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Reviewed-by: Takahiro Kuwano <takahiro.kuwano@infineon.com>
Reviewed-by: Michael Walle <mwalle@kernel.org>
Reviewed-by: Pratyush Yadav <pratyush@kernel.org>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
2026-04-27 15:04:11 +02:00
..
controllers mtd: spi-nor: hisi-sfc: fix refcounting bug in hisi_spi_nor_register_all() 2026-02-06 15:22:42 +01:00
atmel.c mtd: spi-nor: atmel: add at25sf321 entry 2024-12-06 15:13:19 +00:00
core.c * MTD changes 2026-04-17 17:57:04 -07:00
core.h mtd: spi-nor: update spi_nor_fixups::post_sfdp() documentation 2026-03-13 10:47:18 +00:00
debugfs.c mtd: spi-nor: debugfs: fix out-of-bounds read in spi_nor_params_show() 2026-04-27 15:04:11 +02:00
eon.c mtd: spi-nor: eon: sort flash_info database 2023-09-19 18:59:21 +03:00
esmt.c mtd: spi-nor: esmt: convert flash_info to new format 2023-09-19 18:57:50 +03:00
everspin.c mtd: spi-nor: get rid of SPI_NOR_NO_FR 2024-05-27 17:07:15 +02:00
gigadevice.c mtd: spi-nor: gigadevice: sort flash_info database 2023-09-19 18:59:21 +03:00
intel.c mtd: spi-nor: intel: convert flash_info to new format 2023-09-19 18:59:19 +03:00
issi.c mtd: spi-nor: issi: sort flash_info database 2023-09-19 18:59:21 +03:00
Kconfig mtd: spi-nor: keep lock bits if they are non-volatile 2020-12-07 23:01:15 +05:30
macronix.c mtd: spi-nor: macronix: Add fixups for MX25L3255E 2025-04-08 15:04:54 +00:00
Makefile mtd: spi-nor: Remove support for Xilinx S3AN flashes 2024-05-27 16:39:21 +02:00
micron-st.c mtd: spi-nor: micron-st: Enable die erase support for MT35XU02GCBA 2026-03-31 15:46:47 +00:00
otp.c mtd: spi-nor: explicitly include <linux/math64.h> 2025-03-07 08:36:38 +02:00
sfdp.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
sfdp.h mtd: spi-nor: sfdp: Get the 8D-8D-8D byte order from BFPT 2024-10-02 10:28:40 +03:00
spansion.c mtd: spi-nor: spansion: SMPT fixups for S25FS-S 2025-11-10 11:12:06 +01:00
sst.c mtd: spi-nor: sst: Fix write enable before AAI sequence 2026-03-30 14:24:38 +00:00
swp.c mtd: spi-nor: swp: check SR_TB flag when getting tb_mask 2026-03-13 11:13:46 +00:00
sysfs.c sysfs: treewide: switch back to attribute_group::bin_attrs 2025-06-17 10:44:15 +02:00
winbond.c mtd: spi-nor: winbond: Fix locking support for w25q256jw 2026-03-30 15:00:34 +00:00
xmc.c mtd: spi-nor: xmc: convert flash_info to new format 2023-09-19 18:59:20 +03:00