BSDSec

deadsimple BSD Security Advisories and Announcements

FreeBSD Errata Notice FreeBSD-EN-22:21.zfs

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

=============================================================================
FreeBSD-EN-22:21.zfs                                            Errata Notice
                                                          The FreeBSD Project
Topic:          ZFS B-Tree use-after-free
Category:       contrib
Module:         zfs
Announced:      2022-11-01
Credits:        Richard Yao and Coverty Static Analysis
Affects:        FreeBSD 13.1
Corrected:      2022-10-04 15:52:45 UTC (stable/13, 13.1-STABLE)
                2022-11-01 18:03:25 UTC (releng/13.1, 13.1-RELEASE-p3)

For general information regarding FreeBSD Errata Notices and Security
Advisories, including descriptions of the fields above, security
branches, and the following sections, please visit
<URL:https://security.FreeBSD.org/>.

I.   Background

ZFS is one of several filesystems available on FreeBSD.  ZFS supports
many advanced features, including checksumming, transparent compression,
and snapshots.

II.  Problem Description

The B-Tree implementation in ZFS contains a heap use-after-free bug. When
removing entries, the node memory is freed before it is removed from the tree,
and the remove operation itself requires modifying the memory containing the
node. This creates a race window when one thread is removing data from the
B-Tree and another is performing an allocation.  In the case the removing
thread loses the race, it will corrupt the B-Tree.

III. Impact

The use-after-free can cause system instability or data corruption.

Systems with debug kernels may sometimes detect this issue after a kernel
memory corruption has happened. When they do, they will trigger a kernel
panic to protect the system from further damage. The following is printed
to dmesg at the time of the panic:

panic: VERIFY3(zfs_btree_find(tree, value, &where) != NULL) failed...

IV.  Workaround

No workaround is available.

V.   Solution

Upgrade your system to a supported FreeBSD stable or release / security
branch (releng) dated after the correction date, and then reboot.

Perform one of the following:

1) To update your system via a binary patch:

Systems running a RELEASE version of FreeBSD on the amd64, i386, or
(on FreeBSD 13 and later) arm64 platforms can be updated via the
freebsd-update(8) utility:

# freebsd-update fetch
# freebsd-update install
# shutdown -r now

2) To update your system via a source code patch:

The following patches have been verified to apply to the applicable
FreeBSD release branches.

a) Download the relevant patch from the location below, and verify the
detached PGP signature using your PGP utility.

# fetch https://security.FreeBSD.org/patches/EN-22:21/zfs.patch
# fetch https://security.FreeBSD.org/patches/EN-22:21/zfs.patch.asc
# gpg --verify zfs.patch.asc

b) Apply the patch.  Execute the following commands as root:

# cd /usr/src
# patch < /path/to/patch

c) Recompile your kernel as described in
<URL:https://www.FreeBSD.org/handbook/kernelconfig.html> and reboot the
system.

VI.  Correction details

This issue is corrected by the corresponding Git commit hash or Subversion
revision number in the following stable and release branches:

Branch/path                             Hash                     Revision
- -------------------------------------------------------------------------
stable/13/                              f193a24ec570    stable/13-n252634
releng/13.1/                            8838c650cb59  releng/13.1-n250167
- -------------------------------------------------------------------------

Run the following command to see which files were modified by a
particular commit:

# git show --stat <commit hash>

Or visit the following URL, replacing NNNNNN with the hash:

<URL:https://cgit.freebsd.org/src/commit/?id=NNNNNN>

To determine the commit count in a working tree (for comparison against
nNNNNNN in the table above), run:

# git rev-list --count --first-parent HEAD

VII. References

<URL:https://github.com/openzfs/zfs/pull/13861>

The latest revision of this advisory is available at
<URL:https://security.FreeBSD.org/advisories/FreeBSD-EN-22:21.zfs.asc>
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEE/A6HiuWv54gCjWNV05eS9J6n5cIFAmNhlpgACgkQ05eS9J6n
5cJtMQ//aZXPrFWqJxVIn87FtHClwKykAaWWcN+iuT4wTVss0OTbaFc1k+UBPf+9
wdjmt6Io9xUK4FT5TcMIyzF6I7XaxG/up8572NPUQp+eOa4AI8862QLLF7pi26RT
Fyb+Ywjsw1d30NXcTE4+K5UMUgISFVFkor9d07wWd7sQwU/o4bzHBWFSFSI18l70
zsjyN3wrLQaSHmBb6kZ7OrycBc52Rw00segXCJGxLEpiViPSC5HY6DJYdWyn0bNM
1xvG3DkYQDBWGNQgWB6ldOM5nmOqY6zSPFTK9byqOwz6CHmfRYqmLpx3czuAO3U6
PpsTYG7PKpFBviP99jg6XsEYigoMHaHIcBzUSP+DYYO9JlyrzRmbQ6MIkRN+YD59
1CK0n7+WuQpjBXgFmIEKtM2xJ4sh+aQxdV4SwIEmMTAaNs4PFivNzEgwpj4Txh+q
aUbY6l9O2H8ERvFokF94/ea5ahOhVaTgaipN2O92rvldiy3zTqv5DP3hX4tU1oaG
n0s57pn/uF+aYVMtzk1opNpZdqH8AkKX1Q7Opha/IEvnk48Njgbwtf9HVEeo65Ec
njvc63PZel0cbzk6ZA4BS7BX3UtSHURmFOjiRUV1DI9yUsLXuEbM0LtH3Zpgyzr0
7U+YHLB4z3LxdK9ZuWo2uSCF/5iVyyjGSdOGuu2ISJis+vp9PCg/T
-----END PGP SIGNATURE-----