Skip to content

Commit d94d1a5

Browse files
markjdbtonyhutter
authored andcommitted
Fix potential use-after-frees in FreeBSD getpages and setattr VOPs
The objset object is reallocated during certain dataset operations, such as rollbacks, so the objset pointer must be loaded after acquiring the teardown lock. Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Reviewed-by: Ryan Moeller <ryan@ixsystems.com> Signed-off-by: Mark Johnston <markj@FreeBSD.org> Closes openzfs#12704
1 parent 4bbffa2 commit d94d1a5

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

module/os/freebsd/zfs/zfs_vnops_os.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,7 +2222,7 @@ zfs_setattr(znode_t *zp, vattr_t *vap, int flags, cred_t *cr)
22222222
{
22232223
vnode_t *vp = ZTOV(zp);
22242224
zfsvfs_t *zfsvfs = zp->z_zfsvfs;
2225-
objset_t *os = zfsvfs->z_os;
2225+
objset_t *os;
22262226
zilog_t *zilog;
22272227
dmu_tx_t *tx;
22282228
vattr_t oldva;
@@ -2257,6 +2257,7 @@ zfs_setattr(znode_t *zp, vattr_t *vap, int flags, cred_t *cr)
22572257
ZFS_ENTER(zfsvfs);
22582258
ZFS_VERIFY_ZP(zp);
22592259

2260+
os = zfsvfs->z_os;
22602261
zilog = zfsvfs->z_log;
22612262

22622263
/*
@@ -4058,7 +4059,6 @@ zfs_getpages(struct vnode *vp, vm_page_t *ma, int count, int *rbehind,
40584059
{
40594060
znode_t *zp = VTOZ(vp);
40604061
zfsvfs_t *zfsvfs = zp->z_zfsvfs;
4061-
objset_t *os = zp->z_zfsvfs->z_os;
40624062
zfs_locked_range_t *lr;
40634063
vm_object_t object;
40644064
off_t start, end, obj_size;
@@ -4128,8 +4128,8 @@ zfs_getpages(struct vnode *vp, vm_page_t *ma, int count, int *rbehind,
41284128
* ZFS will panic if we request DMU to read beyond the end of the last
41294129
* allocated block.
41304130
*/
4131-
error = dmu_read_pages(os, zp->z_id, ma, count, &pgsin_b, &pgsin_a,
4132-
MIN(end, obj_size) - (end - PAGE_SIZE));
4131+
error = dmu_read_pages(zfsvfs->z_os, zp->z_id, ma, count, &pgsin_b,
4132+
&pgsin_a, MIN(end, obj_size) - (end - PAGE_SIZE));
41334133

41344134
if (lr != NULL)
41354135
zfs_rangelock_exit(lr);

0 commit comments

Comments
 (0)