Skip to content

Commit b75dfde

Browse files
riteshharjanidjwong
authored andcommitted
fibmap: Warn and return an error in case of block > INT_MAX
We better warn the fibmap user and not return a truncated and therefore an incorrect block map address if the bmap() returned block address is greater than INT_MAX (since user supplied integer pointer). It's better to pr_warn() all user of ioctl_fibmap() and return a proper error code rather than silently letting a FS corruption happen if the user tries to fiddle around with the returned block map address. We fix this by returning an error code of -ERANGE and returning 0 as the block mapping address in case if it is > INT_MAX. Now iomap_bmap() could be called from either of these two paths. Either when a user is calling an ioctl_fibmap() interface to get the block mapping address or by some filesystem via use of bmap() internal kernel API. bmap() kernel API is well equipped with handling of u64 addresses. WARN condition in iomap_bmap_actor() was mainly added to warn all the fibmap users. But now that we have directly added this warning for all fibmap users and also made sure to return 0 as block map address in case if addr > INT_MAX. So we can now remove this logic from iomap_bmap_actor(). Signed-off-by: Ritesh Harjani <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Darrick J. Wong <[email protected]> Signed-off-by: Darrick J. Wong <[email protected]>
1 parent 6a8b55e commit b75dfde

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

fs/ioctl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ EXPORT_SYMBOL(vfs_ioctl);
5555
static int ioctl_fibmap(struct file *filp, int __user *p)
5656
{
5757
struct inode *inode = file_inode(filp);
58+
struct super_block *sb = inode->i_sb;
5859
int error, ur_block;
5960
sector_t block;
6061

@@ -71,6 +72,13 @@ static int ioctl_fibmap(struct file *filp, int __user *p)
7172
block = ur_block;
7273
error = bmap(inode, &block);
7374

75+
if (block > INT_MAX) {
76+
error = -ERANGE;
77+
pr_warn_ratelimited("[%s/%d] FS: %s File: %pD4 would truncate fibmap result\n",
78+
current->comm, task_pid_nr(current),
79+
sb->s_id, filp);
80+
}
81+
7482
if (error)
7583
ur_block = 0;
7684
else

fs/iomap/fiemap.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,7 @@ iomap_bmap_actor(struct inode *inode, loff_t pos, loff_t length,
117117

118118
if (iomap->type == IOMAP_MAPPED) {
119119
addr = (pos - iomap->offset + iomap->addr) >> inode->i_blkbits;
120-
if (addr > INT_MAX)
121-
WARN(1, "would truncate bmap result\n");
122-
else
123-
*bno = addr;
120+
*bno = addr;
124121
}
125122
return 0;
126123
}

0 commit comments

Comments
 (0)