xfs
[Top] [All Lists]

Re: [PATCH] xfs: sanitize sb_inopblock in xfs_mount_validate_sb

To: Eric Sandeen <sandeen@xxxxxxxxxx>, xfs-oss <xfs@xxxxxxxxxxx>
Subject: Re: [PATCH] xfs: sanitize sb_inopblock in xfs_mount_validate_sb
From: Jeff Liu <jeff.liu@xxxxxxxxxx>
Date: Wed, 29 Jan 2014 22:58:47 +0800
Delivered-to: xfs@xxxxxxxxxxx
In-reply-to: <52E88357.6090104@xxxxxxxxxx>
References: <52E88357.6090104@xxxxxxxxxx>
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0
On 01/29 2014 12:28 AM, Eric Sandeen wrote:
> xfs_mount_validate_sb doesn't check sb_inopblock for sanity
> (as does its xfs_repair counterpart, FWIW).
> 
> If it's out of bounds, we can go off the rails in i.e.
> xfs_inode_buf_verify(), which uses sb_inopblock as a loop
> limit when stepping through a metadata buffer.
> 
> The problem can be demonstrated easily by corrupting
> sb_inopblock with xfs_db and trying to mount the result:
> 
> # mkfs.xfs -dfile,name=fsfile,size=1g
> # xfs_db -x fsfile 
> xfs_db> sb 0
> xfs_db> write inopblock 512
> inopblock = 512
> xfs_db> quit
> 
> # mount -o loop fsfile  mnt
> and we blow up in xfs_inode_buf_verify().
> 
> With this patch, we get a (very noisy) corruption error,
> and fail the mount as we should.
> 
> Signed-off-by: Eric Sandeen <sandeen@xxxxxxxxxx>
> ---
> 
> diff --git a/fs/xfs/xfs_sb.c b/fs/xfs/xfs_sb.c
> index b7c9aea..511cce9 100644
> --- a/fs/xfs/xfs_sb.c
> +++ b/fs/xfs/xfs_sb.c
> @@ -288,6 +288,7 @@ xfs_mount_validate_sb(
>           sbp->sb_inodelog < XFS_DINODE_MIN_LOG                       ||
>           sbp->sb_inodelog > XFS_DINODE_MAX_LOG                       ||
>           sbp->sb_inodesize != (1 << sbp->sb_inodelog)                ||
> +         sbp->sb_inopblock != howmany(sbp->sb_blocksize,sbp->sb_inodesize) ||
>           (sbp->sb_blocklog - sbp->sb_inodelog != sbp->sb_inopblog)   ||
>           (sbp->sb_rextsize * sbp->sb_blocksize > XFS_MAX_RTEXTSIZE)  ||
>           (sbp->sb_rextsize * sbp->sb_blocksize < XFS_MIN_RTEXTSIZE)  ||

Looks good to me.

Reviewed-by: Jie Liu <jeff.liu@xxxxxxxxxx>


Thanks,
-Jeff

<Prev in Thread] Current Thread [Next in Thread>