Skip to contentSkip to conversation

xfs: check for possible overflow in xfs_ioc_trim

PATCH Superseded Tomas Racek 2 participants 3 messages Aug 9, 2012 – Aug 13, 2012 XFS filesystem

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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
index f9c3fe3..4e07a56 100644
@@ -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
#1 lore raw

[ 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.

---
 fs/xfs/xfs_discard.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
fs/xfs/xfs_discard.c +0 -0
index f9c3fe3..4e07a56 100644

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
#2 lore raw
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 nearly ULLONG_MAX.

---
 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
index f9c3fe3..4e07a56 100644
@@ -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