Skip to contentSkip to conversation

fs/ntfs3: Fix integer overflow in ni_fiemap with fiemap_prep()

PATCH In review Kari Argillander 2 participants 2 messages Aug 25, 2021 – Sep 2, 2021 NTFS3 filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fs/ntfs3: Fix integer overflow in ni_fiemap with fiemap_prep()

Use fiemap_prep() to check valid flags. It also shrink request scope (@len) to what the fs can actually handle.

This address following Smatch static checker warning:

	fs/ntfs3/frecord.c:1894 ni_fiemap()
	warn: potential integer overflow from user 'vbo + len'

Because fiemap_prep() shrinks @len this cannot happened anymore.

Reported-by Dan Carpenter <[email protected]>
Link: lore.kernel.org/ntfs3/20210825080440.GA17407@kili/

Fixes 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
---
 fs/ntfs3/file.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ntfs3/file.c +3 -2
index 59344985c2e8..cb736701f2cc 100644
@@ -1210,8 +1210,9 @@ int ntfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 	int err;
 	struct ntfs_inode *ni = ntfs_i(inode);
 
-	if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR)
-		return -EOPNOTSUPP;
+	err = fiemap_prep(inode, fieinfo, start, &len, ~FIEMAP_FLAG_XATTR);
+	if (err)
+		return err;
 
 	ni_lock(ni);
 
Signature · 1 line
2.30.2
#1 lore raw
Quoted 25 lines · Kari Argillander

Use fiemap_prep() to check valid flags. It also shrink request scope (@len) to what the fs can actually handle.

This address following Smatch static checker warning:

	fs/ntfs3/frecord.c:1894 ni_fiemap()
	warn: potential integer overflow from user 'vbo + len'

Because fiemap_prep() shrinks @len this cannot happened anymore.

Reported-by Dan Carpenter <[email protected]>
Link: lore.kernel.org/ntfs3/20210825080440.GA17407@kili/

Fixes 4342306f0f0d ("fs/ntfs3: Add file operations and implementation")
---
 fs/ntfs3/file.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
fs/ntfs3/file.c +0 -0
index 59344985c2e8..cb736701f2cc 100644
@@ -1210,8 +1210,9 @@ int ntfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 	int err;

fs/ntfs3/file.c int ntfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, · line 1218

Quoted 10 lines
fs/ntfs3/file.c +3 -2
 	struct ntfs_inode *ni = ntfs_i(inode);
 
-	if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR)
-		return -EOPNOTSUPP;
+	err = fiemap_prep(inode, fieinfo, start, &len, ~FIEMAP_FLAG_XATTR);
+	if (err)
+		return err;
 
 	ni_lock(ni);
 

Hello, Dan, Kari!

Thanks for finding and fixing this issue. Applied patch.