Commit 2b8aa4c3 authored by Dinghao Liu's avatar Dinghao Liu Committed by Miquel Raynal

mtd: rawnand: diskonchip: fix a potential double free in doc_probe

When nand_scan() fails, it has cleaned up related resources
in its error paths. Therefore, the following nand_cleanup()
may lead to a double-free. One possible trace is:

doc_probe
  |-> nand_scan
  |     |-> nand_scan_with_ids
  |           |-> nand_scan_tail
  |                 |-> kfree(chip->data_buf) [First free]
  |
  |-> nand_cleanup
        |-> kfree(chip->data_buf) [Double free here]

Fix this by removing nand_cleanup() on failure of
nand_scan().
Signed-off-by: default avatarDinghao Liu <dinghao.liu@zju.edu.cn>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20231214072946.10285-1-dinghao.liu@zju.edu.cn
parent b6c985dd
...@@ -1491,10 +1491,12 @@ static int __init doc_probe(unsigned long physadr) ...@@ -1491,10 +1491,12 @@ static int __init doc_probe(unsigned long physadr)
else else
numchips = doc2001_init(mtd); numchips = doc2001_init(mtd);
if ((ret = nand_scan(nand, numchips)) || (ret = doc->late_init(mtd))) { ret = nand_scan(nand, numchips);
/* DBB note: i believe nand_cleanup is necessary here, as if (ret)
buffers may have been allocated in nand_base. Check with goto fail;
Thomas. FIX ME! */
ret = doc->late_init(mtd);
if (ret) {
nand_cleanup(nand); nand_cleanup(nand);
goto fail; goto fail;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment