[PATCH] xfs: prevent range.len underflow in xfs_ioc_trim()

Lukas Czerner lczerner at redhat.com
Wed Dec 11 06:05:25 CST 2013


Currently when range.len is set to 0 it will underflow. Fix it by
checking for this scenario and return EINVAL in case range.len is
smaller than block size.

This was discovered by the xfstests generic/288 and with this patch
the problem goes away.

Signed-off-by: Lukas Czerner <lczerner at redhat.com>
---
 fs/xfs/xfs_discard.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
index 8367d6d..9029082 100644
--- a/fs/xfs/xfs_discard.c
+++ b/fs/xfs/xfs_discard.c
@@ -180,7 +180,8 @@ xfs_ioc_trim(
 	 * 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, XFS_ALLOC_AG_MAX_USABLE(mp)))
+	    range.minlen > XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp)) ||
+	    range.len < XFS_FSB_TO_B(mp, 1))
 		return -XFS_ERROR(EINVAL);
 
 	start = BTOBB(range.start);
-- 
1.8.3.1



More information about the xfs mailing list