Skip to contentSkip to conversation

xfs: check for possible overflow in xfs_ioc_trim

PATCH In review Tomas Racek 3 participants 4 messages Aug 14, 2012 – Aug 15, 2012 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH v4 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..69cf4fc 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, XFS_ALLOC_AG_MAX_USABLE(mp)))
+		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
Reviewed-by on v4 1/1
#1 lore raw
Quoted 5 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.

looks ok to me.

Signature · 7 lines
Dave Chinner
[email protected]

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

Forwarding to maintainers.

----- Original Message -----

Quoted 7 lines · Tomas Racek
Quoted 6 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.

Quoted 9 lines
Quoted 1 line

looks ok to me.

--
Dave Chinner
[email protected]

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

#3 lore raw
Quoted 1 line · Tomas Racek

Forwarding to maintainers.

Thanks Tomas. We'll get this sorted.

Regards,
Ben

Quoted 18 lines

----- Original Message -----

Quoted 16 lines · Tomas Racek
Quoted 7 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.

looks ok to me.

--
Dave Chinner
[email protected]

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