[FreeBSD-Announce] FreeBSD Errata Notice FreeBSD-EN-22:02.xsave

From: FreeBSD Errata Notices <errata-notices_at_freebsd.org>
Date: Tue, 11 Jan 2022 19:38:52 UTC
Hash: SHA512

FreeBSD-EN-22:02.xsave                                          Errata Notice
                                                          The FreeBSD Project

Topic:          Incorrect XSAVE state size

Category:       core
Module:         kernel
Announced:      2022-01-11
Affects:        All supported versions of FreeBSD.
Corrected:      2021-12-12 02:49:50 UTC (stable/13, 13.0-STABLE)
                2022-01-11 18:14:58 UTC (releng/13.0, 13.0-RELEASE-p6)
                2021-12-12 02:49:50 UTC (stable/12, 12.3-STABLE)
                2022-01-11 18:19:21 UTC (releng/12.3, 12.3-RELEASE-p1)
                2022-01-11 18:33:11 UTC (releng/12.2, 12.2-RELEASE-p12)

For general information regarding FreeBSD Errata Notices and Security
Advisories, including descriptions of the fields above, security
branches, and the following sections, please visit

I.   Background

Contemporary x86 CPUs support the XSAVE instruction, "Save Processor Extended
tates."  Some but not all CPUs support the so-called init optimization for
XSAVE.  The optimization means that the CPU may not write all of the state on
XSAVE, and indicates that it did not in xstate_bv.  Whether or not this
happens depends on "complex internal microarchitectural conditions."

On signal delivery, the OS provides the saved context interrupted by the
signal to the signal handler.  The context includes all CPU state available to
userspace, including FPU registers (XSAVE area).  Also, upon return from the
signal handler, the saved context is restored, which allows the handler to
modify the main program flow.  When the init optimization kicks in, the OS
tries to hide the effects of the init state optimization from the signal
handler by filling in parts of the XSAVE area.

The CPU reports sizes of some of the XSAVE state regions, but two of them
are fixed and must be hard-coded by the kernel.

II.  Problem Description

The hard-coded size for state region 1 (SSE/XMM) was incorrect, effectively
filling the xmm8 through xmm15 registers with arbitrary values on signal
return when the init optimization occurred.

III. Impact

On amd64 and i386 systems, application memory may become corrupted, leading to
incorrect behaviour.  Other platforms are not affected.

IV.  Workaround

Use of XSAVEOPT may be disabled by adding the following line to loader.conf:


V.   Solution

Upgrade your system to a supported FreeBSD stable or release / security
branch (releng) dated after the correction date, and 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 +10min "Rebooting for an errata update"

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:02/xsave.patch
# fetch https://security.FreeBSD.org/patches/EN-22:02/xsave.patch.asc
# gpg --verify xsave.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

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/                              1d6ebddb62bc    stable/13-n248578
releng/13.0/                            f2caded7f590  releng/13.0-n244769
stable/12/                                                        r371242
releng/12.3/                                                      r371483
releng/12.2/                                                      r371488
- -------------------------------------------------------------------------

For FreeBSD 13 and later:

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:


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

For FreeBSD 12 and earlier:

Run the following command to see which files were modified by a particular
revision, replacing NNNNNN with the revision number:

# svn diff -cNNNNNN --summarize svn://svn.freebsd.org/base

Or visit the following URL, replacing NNNNNN with the revision number:


VII. References


The latest revision of this advisory is available at