Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] mtd: spi-nor: sfdp: bound two optional parameter tables
@ 2026-07-19  1:08 HyeongJun An
  2026-07-19  1:08 ` [PATCH 1/2] mtd: spi-nor: sfdp: check the length of the xSPI Profile 1.0 table HyeongJun An
  2026-07-19  1:08 ` [PATCH 2/2] mtd: spi-nor: sfdp: check the length of the SCCR map HyeongJun An
  0 siblings, 2 replies; 4+ messages in thread
From: HyeongJun An @ 2026-07-19  1:08 UTC (permalink / raw)
  To: Pratyush Yadav, Michael Walle, Tudor Ambarus, Miquel Raynal,
	Richard Weinberger, Vignesh Raghavendra
  Cc: Takahiro Kuwano, linux-mtd, linux-kernel, stable, HyeongJun An

Two of the optional SFDP parameter table parsers allocate a bounce buffer
from the table length the flash reports, then index it at fixed offsets
without checking the table is long enough to hold them.

  spi_nor_parse_profile1()  reads up to DWORD5,  never checks the length
  spi_nor_parse_sccr()      reads up to DWORD22, never checks the length

The length is a u8 supplied by the flash, so a device that advertises
either table with a shorter length makes the read run past the
allocation, and a length of zero makes kmalloc() hand back
ZERO_SIZE_PTR, which the parsers then dereference.

spi_nor_parse_4bait() already guards its table this way with
SFDP_4BAIT_DWORD_MAX, so both patches just apply the same check.
spi_nor_parse_sccr_mc() is left alone: it derives its highest index from
the length it allocated with, so it stays in bounds.

The two parsers were added at different times, so they carry different
Fixes tags and are split into one patch each.

Found by code inspection; I have no xSPI or multi-die part to reproduce
this on, so this is not runtime tested.

HyeongJun An (2):
  mtd: spi-nor: sfdp: check the length of the xSPI Profile 1.0 table
  mtd: spi-nor: sfdp: check the length of the SCCR map

 drivers/mtd/spi-nor/sfdp.c | 8 ++++++++
 1 file changed, 8 insertions(+)

-- 
2.43.0


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-20  7:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-19  1:08 [PATCH 0/2] mtd: spi-nor: sfdp: bound two optional parameter tables HyeongJun An
2026-07-19  1:08 ` [PATCH 1/2] mtd: spi-nor: sfdp: check the length of the xSPI Profile 1.0 table HyeongJun An
2026-07-20  7:41   ` Michael Walle
2026-07-19  1:08 ` [PATCH 2/2] mtd: spi-nor: sfdp: check the length of the SCCR map HyeongJun An

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox