xfs
[Top] [All Lists]

Re: [PATCH] xfs: avoid underflow in xfs_ioc_trim()

To: xfs@xxxxxxxxxxx
Subject: Re: [PATCH] xfs: avoid underflow in xfs_ioc_trim()
From: Carlos Maiolino <cmaiolino@xxxxxxxxxx>
Date: Tue, 9 Oct 2012 10:42:10 -0300
In-reply-to: <1349784945-28399-1-git-send-email-lczerner@xxxxxxxxxx>
Mail-followup-to: xfs@xxxxxxxxxxx
References: <1349784945-28399-1-git-send-email-lczerner@xxxxxxxxxx>
User-agent: Mutt/1.5.21 (2010-09-15)
On Tue, Oct 09, 2012 at 02:15:45PM +0200, Lukas Czerner wrote:
> Currently if len argument in xfs_ioc_trim() is smaller than one BB
> (basic block) the 'end' variable underflow. Avoid that by bailing out if
> len is smaller than BB.
> 
> Signed-off-by: Lukas Czerner <lczerner@xxxxxxxxxx>
> ---
>  fs/xfs/xfs_discard.c |    7 ++++++-
>  1 files changed, 6 insertions(+), 1 deletions(-)
> 
> diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
> index 69cf4fc..54dc58a 100644
> --- a/fs/xfs/xfs_discard.c
> +++ b/fs/xfs/xfs_discard.c
> @@ -183,8 +183,12 @@ xfs_ioc_trim(
>           range.minlen > XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp)))
>               return -XFS_ERROR(EINVAL);
>  
> +     end = BTOBBT(range.len);
> +     if (0 == end)
> +             goto out;
> +
>       start = BTOBB(range.start);
> -     end = start + BTOBBT(range.len) - 1;
> +     end += start - 1;
>       minlen = BTOBB(max_t(u64, granularity, range.minlen));
>  
>       if (end > XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks) - 1)
> @@ -203,6 +207,7 @@ xfs_ioc_trim(
>       if (last_error)
>               return last_error;
>  
> +out:
>       range.len = XFS_FSB_TO_B(mp, blocks_trimmed);
>       if (copy_to_user(urange, &range, sizeof(range)))
>               return -XFS_ERROR(EFAULT);
> -- 
> 1.7.7.6
> 
> _______________________________________________
> xfs mailing list
> xfs@xxxxxxxxxxx
> http://oss.sgi.com/mailman/listinfo/xfs

Looks good,

Reviewed-by: Carlos Maiolino <cmaiolino@xxxxxxxxxx>
-- 
--Carlos

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