mtd: rawnand: rockchip_nfc: size the page buffer for data and OOB
Subsystems (3)
PATCH 1/1 mtd: rawnand: rockchip_nfc: size the page buffer for data and OOB
The page buffer holds a whole raw page, data plus OOB, but was allocated with NFC_MAX_PAGE_SIZE only. With a 16 KiB page and 1280 bytes of OOB (Hynix H27UCG8T2BTR) the raw accesses run past it and corrupt the heap.
Also refuse an ECC layout with more ECC bytes than the eccpos[] array holds (CONFIG_SYS_NAND_MAX_ECCPOS) instead of overflowing it.
Tested on an MK808B (RK3066) with H27UCG8T2BTR: nand read/write/erase, UBI.
Co-Authored-By Claude Opus 5.5 <[email protected]>
Signed-off-by Yalçın Can <[email protected]>
--- drivers/mtd/nand/raw/rockchip_nfc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/mtd/nand/raw/rockchip_nfc.c +8 -1
@@ -880,6 +880,12 @@ static int rk_nfc_ecc_init(struct rk_nfc *nfc, struct nand_chip *chip)return -ENOMEM ; ecc->layout->eccbytes = ecc->bytes * ecc->steps; +if (ecc->layout->eccbytes >MTD_MAX_ECCPOS_ENTRIES_LARGE ) { +dev_err (nfc->dev,"%u ECC bytes per page exceed CONFIG_SYS_NAND_MAX_ECCPOS (%u)\n" , + ecc->layout->eccbytes,MTD_MAX_ECCPOS_ENTRIES_LARGE ); +kfree (ecc->layout); +return -EINVAL ; + }for (i =0 ; i < ecc->layout->eccbytes; i++) ecc->layout->eccpos[i] = rknand->metadata_size + i;
@@ -991,7 +997,8 @@ static int rk_nfc_nand_chip_init(ofnode node, struct rk_nfc *nfc, int devnum) rknand->boot_ecc = ret ? ecc->strength : tmp;if (!nfc->page_buf) { - nfc->page_buf =kzalloc (NFC_MAX_PAGE_SIZE ,GFP_KERNEL ); +/* holds a whole raw page: data + OOB (16 KiB + 1280 on H27UCG8T2BTR) */ + nfc->page_buf =kzalloc (NFC_MAX_PAGE_SIZE +NFC_MAX_OOB_SIZE ,GFP_KERNEL );if (!nfc->page_buf) {kfree (ecc->layout);return -ENOMEM ;
Signature · 1 line
2.47.3