Skip to content

Commit ba08030

Browse files
dhowellsSteve French
authored andcommitted
smb3: missing inode locks in punch hole
smb3 fallocate punch hole was not grabbing the inode or filemap_invalidate locks so could have race with pagemap reinstantiating the page. Cc: stable@vger.kernel.org Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent c919c16 commit ba08030

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

fs/cifs/smb2ops.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3384,7 +3384,7 @@ static long smb3_zero_range(struct file *file, struct cifs_tcon *tcon,
33843384
static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
33853385
loff_t offset, loff_t len)
33863386
{
3387-
struct inode *inode;
3387+
struct inode *inode = file_inode(file);
33883388
struct cifsFileInfo *cfile = file->private_data;
33893389
struct file_zero_data_information fsctl_buf;
33903390
long rc;
@@ -3393,14 +3393,12 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
33933393

33943394
xid = get_xid();
33953395

3396-
inode = d_inode(cfile->dentry);
3397-
3396+
inode_lock(inode);
33983397
/* Need to make file sparse, if not already, before freeing range. */
33993398
/* Consider adding equivalent for compressed since it could also work */
34003399
if (!smb2_set_sparse(xid, tcon, cfile, inode, set_sparse)) {
34013400
rc = -EOPNOTSUPP;
3402-
free_xid(xid);
3403-
return rc;
3401+
goto out;
34043402
}
34053403

34063404
filemap_invalidate_lock(inode->i_mapping);
@@ -3420,8 +3418,10 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon,
34203418
(char *)&fsctl_buf,
34213419
sizeof(struct file_zero_data_information),
34223420
CIFSMaxBufSize, NULL, NULL);
3423-
free_xid(xid);
34243421
filemap_invalidate_unlock(inode->i_mapping);
3422+
out:
3423+
inode_unlock(inode);
3424+
free_xid(xid);
34253425
return rc;
34263426
}
34273427

0 commit comments

Comments
 (0)