Skip to content
/ linux Public

Commit 2e121c5

Browse files
Andreas GruenbacherSasha Levin
authored andcommitted
gfs2: fiemap page fault fix
[ Upstream commit e411d74 ] In gfs2_fiemap(), we are calling iomap_fiemap() while holding the inode glock. This can lead to recursive glock taking if the fiemap buffer is memory mapped to the same inode and accessing it triggers a page fault. Fix by disabling page faults for iomap_fiemap() and faulting in the buffer by hand if necessary. Fixes xfstest generic/742. Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 327de5b commit 2e121c5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

fs/gfs2/inode.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,14 @@ static int gfs2_getattr(struct mnt_idmap *idmap,
21922192
return 0;
21932193
}
21942194

2195+
static bool fault_in_fiemap(struct fiemap_extent_info *fi)
2196+
{
2197+
struct fiemap_extent __user *dest = fi->fi_extents_start;
2198+
size_t size = sizeof(*dest) * fi->fi_extents_max;
2199+
2200+
return fault_in_safe_writeable((char __user *)dest, size) == 0;
2201+
}
2202+
21952203
static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
21962204
u64 start, u64 len)
21972205
{
@@ -2201,14 +2209,22 @@ static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
22012209

22022210
inode_lock_shared(inode);
22032211

2212+
retry:
22042213
ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &gh);
22052214
if (ret)
22062215
goto out;
22072216

2217+
pagefault_disable();
22082218
ret = iomap_fiemap(inode, fieinfo, start, len, &gfs2_iomap_ops);
2219+
pagefault_enable();
22092220

22102221
gfs2_glock_dq_uninit(&gh);
22112222

2223+
if (ret == -EFAULT && fault_in_fiemap(fieinfo)) {
2224+
fieinfo->fi_extents_mapped = 0;
2225+
goto retry;
2226+
}
2227+
22122228
out:
22132229
inode_unlock_shared(inode);
22142230
return ret;

0 commit comments

Comments
 (0)