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

=============================================================================
FreeBSD-SA-23:15.libc                                       Security Advisory
                                                          The FreeBSD Project

Topic:		libc stdio buffer overflow

Category:       core
Module:         libc
Announced:      2023-11-07
Credits:	inooo
                All supported versions of FreeBSD.
Corrected:      2023-11-07 17:31:34 UTC (stable/14, 14.0-STABLE)
                2023-11-08 00:45:25 UTC (releng/14.0, 14.0-RC4-p1)
                2023-11-07 18:41:55 UTC (stable/13, 13.2-STABLE)
                2023-11-08 00:48:03 UTC (releng/13.2, 13.2-RELEASE-p5)
                2023-11-08 14:30:51 UTC (stable/12, 12.4-STABLE)
                2023-11-08 01:09:31 UTC (releng/12.4, 12.4-RELEASE-p7)
CVE Name:       CVE-2023-5941

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

0.   Revision History

v1.0  2023-11-07 -- Initial release
v1.1  2023-11-29 -- Corrected stable/14 and stable/13 Correction details

I.   Background

The FreeBSD C library (libc) Standard I/O (stdio) component provides
essential functionality for input and output operations including file
handling and buffering.  It includes functions like "fopen", "printf", and
"fflush".  Streams may be unbuffered, line buffered, or fully buffered.
The library writes buffered data when the buffer is full or when the
application explicitly requests so by calling the fflush(3) function.

II.  Problem Description

For line-buffered streams the __sflush() function did not correctly update
the FILE object's write space member when the write(2) system call returns
an error.

III. Impact

Depending on the nature of an application that calls libc's stdio functions
and the presence of errors returned from the write(2) system call (or an
overridden stdio write routine) a heap buffer overflow may occur.  Such
overflows may lead to data corruption or the execution of arbitrary code at
the privilege level of the calling program.

IV.  Workaround

No workaround is available.

V.   Solution

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

Perform one of the following:

1) To update your vulnerable 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 a security update"

2) To update your vulnerable 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.

[FreeBSD 14.0]
# fetch https://security.FreeBSD.org/patches/SA-23:15/stdio.14.patch
# fetch https://security.FreeBSD.org/patches/SA-23:15/stdio.14.patch.asc
# gpg --verify stdio.14.patch.asc

[FreeBSD 13.2]
# fetch https://security.FreeBSD.org/patches/SA-23:15/stdio.13.patch
# fetch https://security.FreeBSD.org/patches/SA-23:15/stdio.13.patch.asc
# gpg --verify stdio.13.patch.asc

[FreeBSD 12.4]
# fetch https://security.FreeBSD.org/patches/SA-23:15/stdio.12.patch
# fetch https://security.FreeBSD.org/patches/SA-23:15/stdio.12.patch.asc
# gpg --verify stdio.12.patch.asc

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

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

c) Recompile the operating system using buildworld and installworld as
described in <URL:https://www.FreeBSD.org/handbook/makeworld.html>.

Restart all daemons that use the library, or 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/14/                              d2c65a1c9486    stable/14-n265707
releng/14.0/                            1f9c4610dde5  releng/14.0-n265376
stable/13/                              0b7939d725ba    stable/13-n256681
releng/13.2/                            d51a39b13ee4  releng/13.2-n254639
stable/12/                                                        r373263
releng/12.4/                                                      r373265
- -------------------------------------------------------------------------

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:

<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

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:

<URL:https://svnweb.freebsd.org/base?view=revision&revision=NNNNNN>

VII. References

<URL:https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-5941>

The latest revision of this advisory is available at
<URL:https://security.FreeBSD.org/advisories/FreeBSD-SA-23:15.stdio.asc>
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEthUnfoEIffdcgYM7bljekB8AGu8FAmVnmQkACgkQbljekB8A
Gu/QUA/+L3iTtXqyMYWT/uI8JHbc+cFjS89GOd14jV2MKUT9ajkUcmkEDC2atzXT
rUswGxo1sPWZtuVaKdDQrhT12bTKJzV2C0NK0Doj+f9EDEmphvf9kpleMAwkeloR
g5idsHgEN+gmQHR4Ki5oofvk6FlvGacan407rTvmRdEdTobO4ZM2zOTeTgcCMwzA
dyA+CeRSIRluVdzu56PLVLYimgs0Xni/JmEatFXXXjGb25lIb4YDq32uO9Xvdhhi
7cRX6MiFsh702Tt6mo7ajo5B85khOEH/vlJkvgBQ8dcfaGIwpM00SoZFbL1SHk4y
XSM92YK42XY8ME0gJDndM7gcEy9aODFJTtUuga57Og676/LRlJBVS8xh3kReT6p1
QY1fmnYXzCmIalumvcY1DjFWBPLDddLLuGIQoBtTHFPd3DDEg7ZpLSUUUqZGmQ+3
oJSLxBz5Ig+D50MlgD/R8Zmzn4bMCCjZjYahJtK/cjZzC0u5jlDfiF6lofETAypH
oU9LM9M1lEOxuPS8a+1oCtJn3HZaYNgPp+8NajJlDeDzXpOo8+9cpm+9M5yjxIOF
mARYZDD42diF3S8Z4ax6Z3H13CxcwHjTZSqVFf3JYpuZehz5aFgZ0xK7AVBWm5We
4JZ+vwZqdmvSDL00aEdaVJQ4bGxKREwq2cF2grtXWf5nS4ApB0s=
=koz0
-----END PGP SIGNATURE-----
