On Tue, Dec 03, 2019 at 04:27:15PM +0800, quanyang.wang wrote:
> From: Quanyang Wang <quanyang.w...@windriver.com>
> 
> When kernel booting, mount_block_root will be called to judge
> the filesystem type of root device. Then .mount function in file_system_type
> structure will do the check operation. But yaffs filesystem has a
> relaxed examination because as a filesystem for NAND Flash, it doesn't
> examinate whether the root device is the MTD NAND device. This results
> that yaffs filesystem will do mount operation even though the root device
> is a MMC card with a btrfs filesystem, and will crash kernel after
> mounting failed.
> 
> Use yaffs_get_mtd_device to add strict check.
> 
> Signed-off-by: Quanyang Wang <quanyang.w...@windriver.com>
> ---
>  fs/yaffs2/yaffs_mtdif.c | 12 ++++++++++--
>  fs/yaffs2/yaffs_vfs.c   |  7 ++-----
>  2 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/fs/yaffs2/yaffs_mtdif.c b/fs/yaffs2/yaffs_mtdif.c
> index 4ff5741f3983..054e251a2c18 100644
> --- a/fs/yaffs2/yaffs_mtdif.c
> +++ b/fs/yaffs2/yaffs_mtdif.c
> @@ -242,17 +242,25 @@ struct mtd_info * yaffs_get_mtd_device(dev_t sdev)
>  {
>       struct mtd_info *mtd;
>  
> -     mtd = yaffs_get_mtd_device(sdev);
> -

It seems that you have fixed two issues in this patch. One issue is the
buggy yaffs_get_mtd_device(), and the other is the issue you described in
the commit log. So it would be better to separate this into two patches.

Thanks,
Kevin

>       /* Check it's an mtd device..... */
>       if (MAJOR(sdev) != MTD_BLOCK_MAJOR)
>               return NULL;    /* This isn't an mtd device */
>  
> +     /* Get the device */
> +     mtd = get_mtd_device(NULL, MINOR(sdev));
> +     if (IS_ERR_OR_NULL(mtd)) {
> +             yaffs_trace(YAFFS_TRACE_ALWAYS,
> +                     "yaffs: MTD device %u either not valid or unavailable",
> +                     MINOR(sdev));
> +             return NULL;
> +     }
> +
>       /* Check it's NAND */
>       if (mtd->type != MTD_NANDFLASH) {
>               yaffs_trace(YAFFS_TRACE_ALWAYS,
>                       "yaffs: MTD device is not NAND it's type %d",
>                       mtd->type);
> +             put_mtd_device(mtd);
>               return NULL;
>       }
>  
> diff --git a/fs/yaffs2/yaffs_vfs.c b/fs/yaffs2/yaffs_vfs.c
> index 61ac4e4c45d1..db77316a0f95 100644
> --- a/fs/yaffs2/yaffs_vfs.c
> +++ b/fs/yaffs2/yaffs_vfs.c
> @@ -2881,12 +2881,9 @@ static struct super_block 
> *yaffs_internal_read_super(int yaffs_version,
>               MAJOR(sb->s_dev), MINOR(sb->s_dev),
>               yaffs_devname(sb, devname_buf));
>  
> -     /* Get the device */
> -     mtd = get_mtd_device(NULL, MINOR(sb->s_dev));
> +
> +     mtd = yaffs_get_mtd_device(sb->s_dev);
>       if (!mtd) {
> -             yaffs_trace(YAFFS_TRACE_ALWAYS,
> -                     "yaffs: MTD device %u either not valid or unavailable",
> -                     MINOR(sb->s_dev));
>               return NULL;
>       }
>  
> -- 
> 2.17.1
> 

> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> 
> View/Reply Online (#8146): 
> https://lists.yoctoproject.org/g/linux-yocto/message/8146
> Mute This Topic: https://lists.yoctoproject.org/mt/65654980/3616907
> Group Owner: linux-yocto+ow...@lists.yoctoproject.org
> Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub  
> [haoke...@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-

Attachment: signature.asc
Description: PGP signature

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#8148): 
https://lists.yoctoproject.org/g/linux-yocto/message/8148
Mute This Topic: https://lists.yoctoproject.org/mt/65654980/21656
Group Owner: linux-yocto+ow...@lists.yoctoproject.org
Unsubscribe: https://lists.yoctoproject.org/g/linux-yocto/unsub  
[arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to