xfs: check for possible overflow in xfs_ioc_trim
PATCH v3 1/1 xfs: check for possible overflow in xfs_ioc_trim
If range.start or range.minlen is bigger than filesystem size, return invalid value error. This fixes possible overflow in BTOBB macro when passed value was nearly ULLONG_MAX.
--- fs/xfs/xfs_discard.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
fs/xfs/xfs_discard.c +4 -2
@@ -179,12 +179,14 @@ xfs_ioc_trim(* used by the fstrim application. In the end it really doesn't * matter as trimming blocks is an advisory interface. */ +if (range.start >=XFS_FSB_TO_B (mp, mp->m_sb.sb_dblocks) || + range.minlen >XFS_FSB_TO_B (mp, mp->m_sb.sb_dblocks)) +return -XFS_ERROR (EINVAL ); + start =BTOBB (range.start); end = start +BTOBBT (range.len) -1 ; minlen =BTOBB (max_t (u64, granularity, range.minlen)); -if (XFS_BB_TO_FSB (mp, start) >= mp->m_sb.sb_dblocks) -return -XFS_ERROR (EINVAL );if (end >XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks) -1 ) end =XFS_FSB_TO_BB (mp, mp->m_sb.sb_dblocks)-1 ;
Signature · 6 lines
1.7.7.6 _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
[ Trimmed lkml from cc list. There's no need to cc lkml on XFS specific stuff. ]
[ Trimmed [email protected] as that is not a list any XFS developer is subscribed to. ]
Quoted 14 lines · Tomas Racek
If range.start or range.minlen is bigger than filesystem size, return invalid value error. This fixes possible overflow in BTOBB macro when passed value was nearly
ULLONG_MAX.Signed-off-by Tomas Racek <[email protected]>--- fs/xfs/xfs_discard.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)fs/xfs/xfs_discard.c +0
-0
fs/xfs/xfs_discard.c xfs_ioc_trim( · line 184
Quoted 6 lines
fs/xfs/xfs_discard.c +3
-0@@ -179,12 +179,14 @@ xfs_ioc_trim(* used by the fstrim application. In the end it really doesn't * matter as trimming blocks is an advisory interface. */ +if (range.start >=XFS_FSB_TO_B (mp, mp->m_sb.sb_dblocks) || + range.minlen >XFS_FSB_TO_B (mp, mp->m_sb.sb_dblocks)) +return -XFS_ERROR (EINVAL );
That's not correct for minlen. The maximum minlen we can support is the length of the largest freespace extent in the filesystem, and that is limited to the size of an AG. i.e. XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp))
Cheers,
Dave.
Signature · 7 lines
Dave Chinner [email protected] _______________________________________________ xfs mailing list [email protected] http://oss.sgi.com/mailman/listinfo/xfs
Quoted 6 lines
[ Trimmed lkml from cc list. There's no need to cc lkml on XFS specific stuff. ]
[ Trimmed [email protected] as that is not a list any XFS developer is subscribed to. ]
Oh, it's good to know (I used get_maintainer script before).
Quoted 13 lines · Tomas Racek
Quoted 11 lines
If range.start or range.minlen is bigger than filesystem size, return
invalid value error. This fixes possible overflow in BTOBB macro when
passed value was nearlyULLONG_MAX.Signed-off-by Tomas Racek <[email protected]>--- fs/xfs/xfs_discard.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
Quoted 16 lines
fs/xfs/xfs_discard.c xfs_ioc_trim( · line 184
Quoted 11 lines
fs/xfs/xfs_discard.c +3
-0@@ -179,12 +179,14 @@ xfs_ioc_trim(* used by the fstrim application. In the end it really doesn't * matter as trimming blocks is an advisory interface. */ +if (range.start >=XFS_FSB_TO_B (mp, mp->m_sb.sb_dblocks) || + range.minlen >XFS_FSB_TO_B (mp, mp->m_sb.sb_dblocks)) +return -XFS_ERROR (EINVAL );That's not correct for minlen. The maximum minlen we can support is the length of the largest freespace extent in the filesystem, and that is limited to the size of an AG. i.e.
XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp))
Will do, thank you!
Tomas
Quoted 8 lines
Cheers,
Dave.
--
Dave Chinner
[email protected]
_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs