[PATCH] mtd: core: check partition before dereference

Christian Marangi ansuelsmth at gmail.com
Mon Jul 25 07:36:35 PDT 2022


On Mon, Jul 25, 2022 at 10:49:25PM +0900, Tetsuo Handa wrote:
> syzbot is reporting NULL pointer dereference at mtd_check_of_node() [1],
> for mtdram test device (CONFIG_MTD_MTDRAM) is not partition.
> 
> Link: https://syzkaller.appspot.com/bug?extid=fe013f55a2814a9e8cfd [1]
> Reported-by: syzbot <syzbot+fe013f55a2814a9e8cfd at syzkaller.appspotmail.com>
> Reported-by: kernel test robot <oliver.sang at intel.com>
> Fixes: ad9b10d1eaada169 ("mtd: core: introduce of support for dynamic partitions")
> Signed-off-by: Tetsuo Handa <penguin-kernel at I-love.SAKURA.ne.jp>
> ---
>  drivers/mtd/mtdcore.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
> index 6fafea80fd98..a9b8be9f40dc 100644
> --- a/drivers/mtd/mtdcore.c
> +++ b/drivers/mtd/mtdcore.c
> @@ -559,6 +559,8 @@ static void mtd_check_of_node(struct mtd_info *mtd)
>  		return;
>  
>  	/* Check if a partitions node exist */
> +	if (!mtd_is_partition(mtd))
> +		return;
>  	parent = mtd->parent;
>  	parent_dn = dev_of_node(&parent->dev);
>  	if (!parent_dn)
> --

Thanks for sorting this out. LGTM.

-- 
	Ansuel



More information about the linux-mtd mailing list