Skip to contentSkip to conversation

xfs: prevent range.len underflow in xfs_ioc_trim()

PATCH In review Lukas Czerner 2 participants 4 messages Dec 11, 2013 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: prevent range.len underflow in xfs_ioc_trim()

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.

---
 fs/xfs/xfs_discard.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/xfs_discard.c +2 -1
index 8367d6d..9029082 100644
@@ -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);
Signature · 6 lines
1.8.3.1

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw

Hi Lukas,

Thanks for the fix. We have corrected this problem with the blow patch which got merged intwo weeks ago. :)
[ commit f9fd013561 ]
xfs: don't perform discard if the given range length is less than block size

That is also discovered by generic/288 you contributed.

Thanks,
-Jeff

Quoted 18 lines · Lukas Czerner

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.

---
 fs/xfs/xfs_discard.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/xfs_discard.c +0 -0
index 8367d6d..9029082 100644

fs/xfs/xfs_discard.c xfs_ioc_trim( · line 187

Quoted 9 lines
fs/xfs/xfs_discard.c +2 -1
@@ -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);

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
Quoted 10 lines · Jeff Liu

Date: Wed, 11 Dec 2013 21:10:48 +0800
From: Jeff Liu <[email protected]>
To: Lukas Czerner <[email protected]>, [email protected]
Subject: Re: [PATCH] xfs: prevent range.len underflow in xfs_ioc_trim()

Hi Lukas,

Thanks for the fix. We have corrected this problem with the blow patch which got merged intwo weeks ago. :)
[ commit f9fd013561 ]

Not sure where it got merged, I do not see this upstream in linus tree.

Quoted 3 lines

xfs: don't perform discard if the given range length is less than block size

That is also discovered by generic/288 you contributed.

Right, I mentioned that in the description.

-Lukas

Quoted 30 lines

Thanks,
-Jeff

Quoted 25 lines · Lukas Czerner

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.

---
 fs/xfs/xfs_discard.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/xfs_discard.c +2 -1
index 8367d6d..9029082 100644
@@ -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);
 
Quoted 3 lines

fs/xfs/xfs_discard.c xfs_ioc_trim( · line 187

Quoted 2 lines
fs/xfs/xfs_discard.c +0 -0
 	start = BTOBB(range.start);

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw
Quoted 7 lines · Lukáš Czerner
Quoted 5 lines · Jeff Liu

Date: Wed, 11 Dec 2013 21:10:48 +0800
From: Jeff Liu <[email protected]>
To: Lukas Czerner <[email protected]>, [email protected]
Subject: Re: [PATCH] xfs: prevent range.len underflow in xfs_ioc_trim()

Quoted 8 lines
Quoted 5 lines

Hi Lukas,

Thanks for the fix. We have corrected this problem with the blow patch which got merged intwo weeks ago. :)
[ commit f9fd013561 ]

Not sure where it got merged, I do not see this upstream in linus tree.

Now it resides in xfs-next tree, but I remember Ben have sent out the pull request "[GIT PULL] XFS bugfixes for 3.13-rc4" to Linus yesterday.

Thanks,
-Jeff

Quoted 39 lines
Quoted 4 lines

xfs: don't perform discard if the given range length is less than block size

That is also discovered by generic/288 you contributed.

Right, I mentioned that in the description.

-Lukas

Quoted 30 lines

Thanks,
-Jeff

Quoted 25 lines · Lukas Czerner

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.

---
 fs/xfs/xfs_discard.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/xfs/xfs_discard.c +2 -1
index 8367d6d..9029082 100644
@@ -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);
 
Quoted 9 lines
Quoted 3 lines

fs/xfs/xfs_discard.c xfs_ioc_trim( · line 187

Quoted 2 lines
fs/xfs/xfs_discard.c +0 -0
 	start = BTOBB(range.start);

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs