Skip to contentSkip to conversation

xfs: avoid underflow in xfs_ioc_trim()

PATCH In review Lukas Czerner 2 participants 4 messages Oct 11, 2012 – Oct 12, 2012 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xfs: avoid underflow in xfs_ioc_trim()

Currently if len argument in xfs_ioc_trim() is smaller than one FSB the 'end' variable underflow. Avoid that by returning EINVAL when range is smaller than FSB.

---
v2: reworked, return EINVAL if len < FSB

 fs/xfs/xfs_discard.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
fs/xfs/xfs_discard.c +2 -1
index 69cf4fc..04ddbbb 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.7.7.6

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#1 lore raw
Quoted 5 lines · Lukas Czerner

Currently if len argument in xfs_ioc_trim() is smaller than one FSB the 'end' variable underflow. Avoid that by returning EINVAL when range is smaller than FSB.

Just a thought - wouldn't this be better done at the VFS so it is consistent across all filesystems? i.e. using inode->i_blkbits?

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 11 lines · Dave Chinner

Date: Fri, 12 Oct 2012 08:35:33 +1100
From: Dave Chinner <[email protected]>
To: Lukas Czerner <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v2] xfs: avoid underflow in xfs_ioc_trim()

Quoted 4 lines · Lukas Czerner

Currently if len argument in xfs_ioc_trim() is smaller than one FSB the 'end' variable underflow. Avoid that by returning EINVAL when range is smaller than FSB.

Quoted 8 lines
Quoted 1 line

Just a thought - wouldn't this be better done at the VFS so it is consistent across all filesystems? i.e. using inode->i_blkbits?

Cheers,

Dave.

Currently I am working on patches for other file system, so we'll get it fix. Having the check in VFS would require to make FITRIM file system (inode?) operation, or adding cmd specific sections to the vfs_ioctl(). All of this just for one check and file system implementation would have to do other check anyway because we can hardly do all of that in VFS. So I think it's not worth it.

Thanks!
-Lukas

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

#3 lore raw
Quoted 18 lines · Lukáš Czerner
Quoted 16 lines · Dave Chinner

Date: Fri, 12 Oct 2012 08:35:33 +1100
From: Dave Chinner <[email protected]>
To: Lukas Czerner <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v2] xfs: avoid underflow in xfs_ioc_trim()

Quoted 5 lines · Lukas Czerner

Currently if len argument in xfs_ioc_trim() is smaller than one FSB the 'end' variable underflow. Avoid that by returning EINVAL when range is smaller than FSB.

Just a thought - wouldn't this be better done at the VFS so it is consistent across all filesystems? i.e. using inode->i_blkbits?

Quoted 7 lines
Quoted 3 lines

Cheers,

Dave.

Currently I am working on patches for other file system, so we'll get it fix. Having the check in VFS would require to make FITRIM file system (inode?) operation

Not at all - filp->mapping->host gets you the inode....

Quoted 3 lines

, or adding cmd specific sections to
the vfs_ioctl().

But that's a fair reason not to....

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

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