Update inode under range lock

After a successful write the inode must be updated under the range
lock.  If it is updated after dropping the lock there exists a race
where the znode and inode wile disagree about the file size.  This
could result in narrow window of time where read(2) is able to access
data beyond what fstat(2) reports as the file size.

Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Ned Bass <bass6@llnl.gov>
Closes #3601
This commit is contained in:
Brian Behlendorf 2015-07-16 13:35:04 -07:00
parent bd29109f1a
commit 2a53e2dacc

View File

@ -897,6 +897,7 @@ zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr)
uio_prefaultpages(MIN(n, max_blksz), uio); uio_prefaultpages(MIN(n, max_blksz), uio);
} }
zfs_inode_update(zp);
zfs_range_unlock(rl); zfs_range_unlock(rl);
/* /*
@ -912,7 +913,6 @@ zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr)
zsb->z_os->os_sync == ZFS_SYNC_ALWAYS) zsb->z_os->os_sync == ZFS_SYNC_ALWAYS)
zil_commit(zilog, zp->z_id); zil_commit(zilog, zp->z_id);
zfs_inode_update(zp);
ZFS_EXIT(zsb); ZFS_EXIT(zsb);
return (0); return (0);
} }