{"id":"CVE-2026-139004","state":"PUBLISHED","title":"spi: spi-qpic-snand: publish the ECC context to snandc->qspi","description":"In the Linux kernel, the following vulnerability has been resolved:\n\nspi: spi-qpic-snand: publish the ECC context to snandc->qspi\n\nqcom_spi_ooblayout_ecc() and qcom_spi_ooblayout_free() read the ECC\nconfiguration through snandc->qspi->ecc. qcom_spi_probe() points it at a\nzeroed scratch struct and only qcom_spi_ecc_prepare_io_req_pipelined(),\nwhich runs on page I/O, ever updates it. qcom_spi_ecc_init_ctx_pipelined()\ninstalls the ooblayout but does not publish the context it just\nallocated, and qcom_spi_ecc_cleanup_ctx_pipelined() frees that context\nwithout clearing the pointer.\n\nspinand_init() calls mtd_ooblayout_count_freebytes() right after the ECC\ncontext is created and before any page I/O, so the ooblayout always runs\nagainst a pointer that does not describe the current context:\n\n  - On a first probe it reads the zeroed struct from qcom_spi_probe(),\n    so steps, bytes and bbm_size are 0. The count then returns 0 rather\n    than an error, so the probe continues with mtd->oobavail set to 0.\n\n  - On a probe retry it reads the ecc_cfg the previous attempt freed.\n\nA retry is easy to hit. On IPQ5018 with the qcom,smem-part parser the\npartition parse returns -EPROBE_DEFER until SMEM has probed, so the\nfirst spi-nand probe defers. It defers inside\nmtd_device_parse_register(), after mtd_otp_nvmem_add() has already read\nthe factory OTP - that read goes through prepare_io_req and leaves\nsnandc->qspi->ecc pointing at the context that spinand_cleanup() then\nfrees. The second probe allocates a new context, never publishes it, and\ncomputes the OOB layout from the freed one. Once the slab has been\nreused, qecc->steps holds garbage and\n\n  oobregion->length = qecc->steps * 4;\n\ngoes negative. qcom_spi_ooblayout_free() only reports -ERANGE for\nsection 1 and later, so mtd_ooblayout_count_bytes() sums the regions and\nreturns that negative length as the byte count. The -512 below is\nsteps * 4 with steps == -128. It is a byte count that happens to\ncollide with -ERESTARTSYS, not an error the driver returned.\nspinand_init() takes it as an error, and because it is not\n-EPROBE_DEFER the driver core never retries and the NAND never appears:\n\n  spi-nand spi0.0: ESMT SPI NAND was found.\n  spi-nand spi0.0: probe with driver spi-nand failed with error -512\n  UBI error: cannot open mtd rootfs, error -2\n  Waiting for root device /dev/ubiblock0_1...\n\nOn a Mercusys MR80X (IPQ5018, ESMT F50D1G41LB) about half of the boots\nfailed to mount the rootfs, the outcome depending on whether the freed\nmemory had been overwritten yet.\n\nPublish the context when it is created and clear the pointer when it is\ndestroyed. Clearing leaves snandc->qspi->ecc NULL after cleanup, which\nis safe: the mtd is unregistered before cleanup_ctx runs, so no\nooblayout callback can follow.","publishedAt":"2026-11-30T13:26:58.979Z","updatedAt":"2026-11-30T13:26:58.979Z","severity":null,"assigner":"Linux","products":["Linux Linux"],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"7304d1909080ef0c9da703500a97f46c98393fcd","status":"affected","lessThan":"fc00ea2413ee6b3743e341c588360c5b3a5ec6b8","versionType":"git"},{"version":"7304d1909080ef0c9da703500a97f46c98393fcd","status":"affected","lessThan":"432fd21eec8b3199e3fc06332b8c081b8a8a6ba9","versionType":"git"},{"version":"7304d1909080ef0c9da703500a97f46c98393fcd","status":"affected","lessThan":"f94c9b68bb5fdbef9f841da493d5305ff634ebb5","versionType":"git"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["drivers/spi/spi-qpic-snand.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"6.15","status":"affected"},{"version":"0","status":"unaffected","lessThan":"6.15","versionType":"semver"},{"version":"6.18.63","status":"unaffected","lessThanOrEqual":"6.18.*","versionType":"semver"},{"version":"7.3.4","status":"unaffected","lessThanOrEqual":"7.3.*","versionType":"semver"},{"version":"7.4-rc1","status":"unaffected","lessThanOrEqual":"*","versionType":"original_commit_for_fix"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["drivers/spi/spi-qpic-snand.c"]}],"references":["https://git.kernel.org/stable/c/fc00ea2413ee6b3743e341c588360c5b3a5ec6b8","https://git.kernel.org/stable/c/432fd21eec8b3199e3fc06332b8c081b8a8a6ba9","https://git.kernel.org/stable/c/f94c9b68bb5fdbef9f841da493d5305ff634ebb5"],"weaknesses":[],"ingestedAt":"2026-11-30T13:40:04.421Z","source":{"repository":"CVEProject/cvelistV5","path":"cves/2026/139xxx/CVE-2026-139004.json","commit":"5317bbbde1916a58cb1fadabb726eb126daf44c1","baselineCommit":"556c9d3a8cd17e218bb8e452ba7cd619a384ff47"},"raw":{"dataType":"CVE_RECORD","dataVersion":"5.2","cveMetadata":{"cveId":"CVE-2026-139004","state":"PUBLISHED","datePublished":"2026-11-30T13:26:58.979Z","dateUpdated":"2026-11-30T13:26:58.979Z","assignerShortName":"Linux","assignerOrgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateReserved":"2026-11-30T13:22:15.908Z"},"containers":{"cna":{"title":"spi: spi-qpic-snand: publish the ECC context to snandc->qspi","descriptions":[{"lang":"en","value":"In the Linux kernel, the following vulnerability has been resolved:\n\nspi: spi-qpic-snand: publish the ECC context to snandc->qspi\n\nqcom_spi_ooblayout_ecc() and qcom_spi_ooblayout_free() read the ECC\nconfiguration through snandc->qspi->ecc. qcom_spi_probe() points it at a\nzeroed scratch struct and only qcom_spi_ecc_prepare_io_req_pipelined(),\nwhich runs on page I/O, ever updates it. qcom_spi_ecc_init_ctx_pipelined()\ninstalls the ooblayout but does not publish the context it just\nallocated, and qcom_spi_ecc_cleanup_ctx_pipelined() frees that context\nwithout clearing the pointer.\n\nspinand_init() calls mtd_ooblayout_count_freebytes() right after the ECC\ncontext is created and before any page I/O, so the ooblayout always runs\nagainst a pointer that does not describe the current context:\n\n  - On a first probe it reads the zeroed struct from qcom_spi_probe(),\n    so steps, bytes and bbm_size are 0. The count then returns 0 rather\n    than an error, so the probe continues with mtd->oobavail set to 0.\n\n  - On a probe retry it reads the ecc_cfg the previous attempt freed.\n\nA retry is easy to hit. On IPQ5018 with the qcom,smem-part parser the\npartition parse returns -EPROBE_DEFER until SMEM has probed, so the\nfirst spi-nand probe defers. It defers inside\nmtd_device_parse_register(), after mtd_otp_nvmem_add() has already read\nthe factory OTP - that read goes through prepare_io_req and leaves\nsnandc->qspi->ecc pointing at the context that spinand_cleanup() then\nfrees. The second probe allocates a new context, never publishes it, and\ncomputes the OOB layout from the freed one. Once the slab has been\nreused, qecc->steps holds garbage and\n\n  oobregion->length = qecc->steps * 4;\n\ngoes negative. qcom_spi_ooblayout_free() only reports -ERANGE for\nsection 1 and later, so mtd_ooblayout_count_bytes() sums the regions and\nreturns that negative length as the byte count. The -512 below is\nsteps * 4 with steps == -128. It is a byte count that happens to\ncollide with -ERESTARTSYS, not an error the driver returned.\nspinand_init() takes it as an error, and because it is not\n-EPROBE_DEFER the driver core never retries and the NAND never appears:\n\n  spi-nand spi0.0: ESMT SPI NAND was found.\n  spi-nand spi0.0: probe with driver spi-nand failed with error -512\n  UBI error: cannot open mtd rootfs, error -2\n  Waiting for root device /dev/ubiblock0_1...\n\nOn a Mercusys MR80X (IPQ5018, ESMT F50D1G41LB) about half of the boots\nfailed to mount the rootfs, the outcome depending on whether the freed\nmemory had been overwritten yet.\n\nPublish the context when it is created and clear the pointer when it is\ndestroyed. Clearing leaves snandc->qspi->ecc NULL after cleanup, which\nis safe: the mtd is unregistered before cleanup_ctx runs, so no\nooblayout callback can follow."}],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"7304d1909080ef0c9da703500a97f46c98393fcd","status":"affected","lessThan":"fc00ea2413ee6b3743e341c588360c5b3a5ec6b8","versionType":"git"},{"version":"7304d1909080ef0c9da703500a97f46c98393fcd","status":"affected","lessThan":"432fd21eec8b3199e3fc06332b8c081b8a8a6ba9","versionType":"git"},{"version":"7304d1909080ef0c9da703500a97f46c98393fcd","status":"affected","lessThan":"f94c9b68bb5fdbef9f841da493d5305ff634ebb5","versionType":"git"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["drivers/spi/spi-qpic-snand.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"6.15","status":"affected"},{"version":"0","status":"unaffected","lessThan":"6.15","versionType":"semver"},{"version":"6.18.63","status":"unaffected","lessThanOrEqual":"6.18.*","versionType":"semver"},{"version":"7.3.4","status":"unaffected","lessThanOrEqual":"7.3.*","versionType":"semver"},{"version":"7.4-rc1","status":"unaffected","lessThanOrEqual":"*","versionType":"original_commit_for_fix"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["drivers/spi/spi-qpic-snand.c"]}],"references":[{"url":"https://git.kernel.org/stable/c/fc00ea2413ee6b3743e341c588360c5b3a5ec6b8"},{"url":"https://git.kernel.org/stable/c/432fd21eec8b3199e3fc06332b8c081b8a8a6ba9"},{"url":"https://git.kernel.org/stable/c/f94c9b68bb5fdbef9f841da493d5305ff634ebb5"}],"providerMetadata":{"shortName":"Linux","orgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateUpdated":"2026-11-30T13:26:58.979Z"},"cpeApplicability":[{"nodes":[{"operator":"OR","negate":false,"cpeMatch":[{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.15","versionEndExcluding":"6.18.63"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.15","versionEndExcluding":"7.3.4"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.15","versionEndExcluding":"7.4-rc1"}]}]}],"x_generator":{"engine":"bippy-1.2.0"}}}}}