FreeBSD Security Advisory FreeBSD-SA-23:13.capsicum

From: FreeBSD Security Advisories <security-advisories_at_freebsd.org>
Date: Tue, 03 Oct 2023 23:04:05 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

=============================================================================
FreeBSD-SA-23:13.capsicum                                   Security Advisory
                                                          The FreeBSD Project

Topic:          copy_file_range insufficient capability rights check

Category:       core
Module:         capsicum
Announced:      2023-10-03
Credits:	David Chisnall
Affects:        FreeBSD 13.2
Corrected:      2023-10-02 16:00:27 UTC (stable/13, 13.2-STABLE)
                2023-10-03 21:24:41 UTC (releng/13.2, 13.2-RELEASE-p4)
CVE Name:       CVE-2023-5369

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/>.

I.   Background

Capsicum is a lightweight OS capability and sandbox framework.  It provides
two kernel primatives, capability mode and capabilities.  Capabilities limit
operations that can be performed on file descriptors.

copy_file_range is a system call that performs a kernel copy of a byte range
from one file to another or within one file.  copy_file_range accepts
optional pointers to offsets for the input and output file descriptors.

II.  Problem Description

The syscall checked only for the CAP_READ and CAP_WRITE capabilities on the
input and output file descriptors, respectively.  Using an offset is
logically equivalent to seeking, and the syscall must additionally require
the CAP_SEEK capability.

III. Impact

A sandboxed process with only read or write but no seek capability on a file
descriptor may be able to read data from or write data to an arbitrary
location within the file corresponding to that file descriptor.

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,
and reboot.

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.

# fetch https://security.FreeBSD.org/patches/SA-23:13/capsicum.patch
# fetch https://security.FreeBSD.org/patches/SA-23:13/capsicum.patch.asc
# gpg --verify capsicum.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/                              3f0ce63828dc    stable/13-n256458
releng/13.2/                            2d23f6c33431  releng/13.2-n254636
- -------------------------------------------------------------------------

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://reviews.freebsd.org/D41967>

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

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

iQIzBAEBCgAdFiEEthUnfoEIffdcgYM7bljekB8AGu8FAmUclU0ACgkQbljekB8A
Gu/a3Q//aXO1+HdImFnqAzKEto8E97DEv6vB2HUZAoxrmwSX9VNjkrIo9Z9+LRyL
q7WXMcok1OPQCCE3ad+g05eqXwnmJ55CpToP/jEXrOOZRDInK0Z5owZbwVpmyAmW
zF/+xoEjcw90H7ReIQQ3+TNGDf025tCoXlTQKdzWtNN6BcY3px4zuDYHPUKgMwSv
XJDrjYWBzBede00CnlolwmsBorjvZvRMfllTIpiVTlmtD73s+sRDI7rc768MY0RZ
gCplCL9S9EkIGL8XJhDWB2+TsG7nvwrUII5M2u0Db252IK7nmgty4l03PtYotx4p
jH/a3oXWKeqExGHJaqNcaUwS6xdu+pvMRuJgY4mH6rd+uvOMbC5jvac3FopSlmXq
aVIctA2LCRomyYmVDsWXIGLcBT5cAOhsqkrw+JE0kA/k2Pl6NDNK7HNgo6Fj01TR
lVf91A1mTsDJxfymU4SWB/KGgImAnR9e7gHUo4gLZCNyYXvcnFa/ntHoswNZ+12L
e/b4+PnHts2X4/+I4K6qdF522yzF/vpyF6UjfwAGtT6qmbmGyW9VbDcn6TIL9I3p
IDKJCWeHPBfyspWua2hCUIi3/EwpSFvIECPad3hFT6cej1pZ6hfJt8XT0ma82QGp
ocbh3tb3E1phSGvgZitk8J0oyWDehuck3YfZ+6nHMwzPBgmr6Lo=
=lS69
-----END PGP SIGNATURE-----