Find a file
Olivier Certner eb07a26af1
sys_procctl(): Make it clear that negative commands are invalid
An initial reading of the preamble of sys_procctl() gives the impression
that no test prevents a malicious user from passing a negative commands
index (in 'uap->com'), which is soon used as an index into the static
array procctl_cmds_info[].

However, a closer examination leads to the conclusion that the existing
code is technically correct.  Indeed, the comparison of 'uap->com' to
the nitems() expression, which expands to a ratio of sizeof(), leads to
a conversion of 'uap->com' to an 'unsigned int' as per Usual Arithmetic
Conversions/Integer Promotions applied by '<=', because sizeof() returns
'size_t' values, and we define 'size_t' as an equivalent of 'unsigned
int' (which is not mandated by the standard, the latter allowing, e.g.,
integers of lower ranks).

With this conversion, negative values of 'uap->com' are automatically
ruled-out since they are converted to very big unsigned integers which
are caught by the test.  An analysis of assembly code produced by LLVM
16 on amd64 and practical tests confirm that no exploitation is possible.

However, the guard code as written is misleading to readers and might
trip up static analysis tools.  Make sure that negative values are
explicitly excluded so that it is immediately clear that EINVAL will be
returned in this case.

Build tested with clang 16 and GCC 12.

Approved by:    markj (mentor)
MFC after:      1 week
Sponsored by:   The FreeBSD Foundation

(cherry picked from commit afc10f8bba)

Approved by:    emaste (mentor)
2024-04-29 14:33:30 +09:00
.cirrus-ci
.github/workflows .github: Switch to v4 of actions/checkout 2024-04-08 11:03:08 -07:00
bin sync.8: Document that the "sync dance" is not a thing 2024-04-28 20:29:36 +02:00
cddl zfs: merge openzfs/zfs@fb6d53206 (zfs-2.1-release) into stable/13 2024-03-01 15:16:06 +01:00
contrib Merge commit 0f329e0246d1 from llvm-project (by Dimitry Andric): 2024-04-28 10:04:33 +02:00
crypto heimdal: asn1: Use unsigned bitfields for named bitsets 2024-04-24 23:27:27 +02:00
etc Merge llvm-project main llvmorg-18-init-15088-gd14ee76181fb 2024-04-19 23:23:40 +02:00
gnu
include posix_spawn(3): add POSIX_SPAWN_DISABLE_ASLR_NP 2024-03-11 02:29:51 +02:00
kerberos5
lib libpmc: Import AMD Zen 4 PMU events 2024-04-26 23:02:51 -04:00
libexec rtld(1): minor clarification for LD_STATIC_TLS_EXTRA 2024-04-23 03:32:54 +03:00
release release: Use the ABI of the target release to fetch packages 2024-04-23 22:04:44 -07:00
rescue rescue: include ping iff at least one of INET & INET6 is enabled 2023-09-24 11:48:33 -04:00
sbin ifconfig(8): Fix two typos in source code comments 2024-04-23 07:26:30 +02:00
secure caroot: routine update 2024-02-13 13:15:13 -06:00
share share/mk/bsd.cpu.mk: add F16C feature for i386 and amd64 architectures 2024-04-21 21:02:09 +02:00
stand loader: For EFI, if we don't have ConOut, try ConIn 2024-02-06 17:12:40 -07:00
sys sys_procctl(): Make it clear that negative commands are invalid 2024-04-29 14:33:30 +09:00
targets Merge llvm-project main llvmorg-17-init-19304-gd0b54bb50e51 2024-01-08 00:04:38 +01:00
tests path_test: fix cap_rights_init usage 2024-03-22 09:35:44 -04:00
tools mwlstats: Fix a typo in an error message 2024-04-25 08:17:38 +02:00
usr.bin script: handle terminal resize on SIGWINCH 2024-04-29 00:28:45 -05:00
usr.sbin binmiscctl.8: Remove a double word 2024-04-23 07:25:10 +02:00
.arcconfig
.arclint
.cirrus.yml Cirrus-CI: bump Clang versions to 16 and 17 2024-04-24 10:06:09 -04:00
.clang-format
.gitattributes
.gitignore
COPYRIGHT
LOCKS
MAINTAINERS
Makefile
Makefile.inc1 Merge llvm-project main llvmorg-17-init-19304-gd0b54bb50e51 2024-01-08 00:04:38 +01:00
Makefile.libcompat
Makefile.sys.inc
ObsoleteFiles.inc Add a few missed libclang_rt files to ObsoleteFiles.inc 2024-04-24 23:26:28 +02:00
README.md
RELNOTES
UPDATING net80211: deal with lost state transitions 2024-02-19 08:02:01 +00:00

FreeBSD Source:

This is the top level of the FreeBSD source directory.

FreeBSD is an operating system used to power modern servers, desktops, and embedded platforms. A large community has continually developed it for more than thirty years. Its advanced networking, security, and storage features have made FreeBSD the platform of choice for many of the busiest web sites and most pervasive embedded networking and storage devices.

For copyright information, please see the file COPYRIGHT in this directory. Additional copyright information also exists for some sources in this tree - please see the specific source directories for more information.

The Makefile in this directory supports a number of targets for building components (or all) of the FreeBSD source tree. See build(7), config(8), FreeBSD handbook on building userland, and Handbook for kernels for more information, including setting make(1) variables.

For information on the CPU architectures and platforms supported by FreeBSD, see the FreeBSD website's Platforms page.

Source Roadmap:

Directory Description
bin System/user commands.
cddl Various commands and libraries under the Common Development and Distribution License.
contrib Packages contributed by 3rd parties.
crypto Cryptography stuff (see crypto/README).
etc Template files for /etc.
gnu Commands and libraries under the GNU General Public License (GPL) or Lesser General Public License (LGPL). Please see gnu/COPYING* for more information.
include System include files.
kerberos5 Kerberos5 (Heimdal) package.
lib System libraries.
libexec System daemons.
release Release building Makefile & associated tools.
rescue Build system for statically linked /rescue utilities.
sbin System commands.
secure Cryptographic libraries and commands.
share Shared resources.
stand Boot loader sources.
sys Kernel sources (see sys/README.md).
targets Support for experimental DIRDEPS_BUILD
tests Regression tests which can be run by Kyua. See tests/README for additional information.
tools Utilities for regression testing and miscellaneous tasks.
usr.bin User commands.
usr.sbin System administration commands.

For information on synchronizing your source tree with one or more of the FreeBSD Project's development branches, please see FreeBSD Handbook.