Skip to content

Commit

Permalink
Fix potential use-after-frees in FreeBSD getpages and setattr VOPs
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Ryan Moeller <[email protected]>
Signed-off-by: Mark Johnston <[email protected]>
Closes openzfs#12704
  • Loading branch information
markjdb authored and tonyhutter committed Dec 13, 2021
1 parent 4bbffa2 commit d94d1a5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions module/os/freebsd/zfs/zfs_vnops_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,7 @@ zfs_setattr(znode_t *zp, vattr_t *vap, int flags, cred_t *cr)
{
vnode_t *vp = ZTOV(zp);
zfsvfs_t *zfsvfs = zp->z_zfsvfs;
objset_t *os = zfsvfs->z_os;
objset_t *os;
zilog_t *zilog;
dmu_tx_t *tx;
vattr_t oldva;
Expand Down Expand Up @@ -2257,6 +2257,7 @@ zfs_setattr(znode_t *zp, vattr_t *vap, int flags, cred_t *cr)
ZFS_ENTER(zfsvfs);
ZFS_VERIFY_ZP(zp);

os = zfsvfs->z_os;
zilog = zfsvfs->z_log;

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

if (lr != NULL)
zfs_rangelock_exit(lr);
Expand Down

0 comments on commit d94d1a5

Please sign in to comment.