404-v6.0-mtd-core-check-partition-before-dereference.patch 1.1 KB

123456789101112131415161718192021222324252627282930
  1. From 7ec4cdb321738d44ae5d405e7b6ac73dfbf99caa Mon Sep 17 00:00:00 2001
  2. From: Tetsuo Handa <[email protected]>
  3. Date: Mon, 25 Jul 2022 22:49:25 +0900
  4. Subject: [PATCH] mtd: core: check partition before dereference
  5. syzbot is reporting NULL pointer dereference at mtd_check_of_node() [1],
  6. for mtdram test device (CONFIG_MTD_MTDRAM) is not partition.
  7. Link: https://syzkaller.appspot.com/bug?extid=fe013f55a2814a9e8cfd [1]
  8. Reported-by: syzbot <[email protected]>
  9. Reported-by: kernel test robot <[email protected]>
  10. Fixes: ad9b10d1eaada169 ("mtd: core: introduce of support for dynamic partitions")
  11. Signed-off-by: Tetsuo Handa <[email protected]>
  12. CC: [email protected]
  13. Signed-off-by: Richard Weinberger <[email protected]>
  14. ---
  15. drivers/mtd/mtdcore.c | 2 ++
  16. 1 file changed, 2 insertions(+)
  17. --- a/drivers/mtd/mtdcore.c
  18. +++ b/drivers/mtd/mtdcore.c
  19. @@ -577,6 +577,8 @@ static void mtd_check_of_node(struct mtd
  20. return;
  21. /* Check if a partitions node exist */
  22. + if (!mtd_is_partition(mtd))
  23. + return;
  24. parent = mtd->parent;
  25. parent_dn = dev_of_node(&parent->dev);
  26. if (!parent_dn)