Commit graph

123 commits

Author SHA1 Message Date
Ed Maste 3733d82c4d libcasper: fix cap_rights_init usage
Capability rights passed to cap_rights_* are not simple bitmaks and
cannot be ORed together in general (although it will work for certain
subsets of rights).

PR:		277057
Fixes:		faaf43b2a7 ("fileargs: add tests")
Sponsored by:	The FreeBSD Foundation
2024-02-14 22:33:24 -05:00
Jose Luis Duran b9bb04c167 libcasper: Fix typo (triple T)
Reviewed by: imp
Pull Request: https://github.com/freebsd/freebsd-src/pull/954
2023-12-27 20:24:30 -07:00
Alan Somers cf037972ea libcasper: document that most libcasper functions are not thread-safe
And neither are most libcasper services' functions, because internally
they all use cap_xfer_nvlist.  cap_xfer_nvlist sends and then receives
data over a unix domain socket and associated with the cap_channel_t
argument.  So absent synchronization, two threads may not use the same
cap_channel_t argument or they risk receiving the other's reply.

MFC after:	2 weeks
Sponsored by:	Axcient
Reviewed by:	oshogbo
Differential Revision: https://reviews.freebsd.org/D42928
2023-12-08 09:22:39 -07:00
Alan Somers 6b96125afd cap_net.3: remove a copypasta
This line appears to have been copied from cap_sysctl.3.  While I'm
here, reorder and reword the description of cap_net_limit a bit.

[skip ci]

MFC after:	2 weeks
Sponsored by:	Axcient
Reviewed by:	oshogbo
Differential Revision: https://reviews.freebsd.org/D42919
2023-12-06 09:51:37 -07:00
Warner Losh a2f733abcf lib: Automated cleanup of cdefs and other formatting
Apply the following automated changes to try to eliminate
no-longer-needed sys/cdefs.h includes as well as now-empty
blank lines in a row.

Remove /^#if.*\n#endif.*\n#include\s+<sys/cdefs.h>.*\n/
Remove /\n+#include\s+<sys/cdefs.h>.*\n+#if.*\n#endif.*\n+/
Remove /\n+#if.*\n#endif.*\n+/
Remove /^#if.*\n#endif.*\n/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/types.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/param.h>/
Remove /\n+#include\s+<sys/cdefs.h>\n#include\s+<sys/capsicum.h>/

Sponsored by:		Netflix
2023-11-26 22:23:59 -07:00
John Baldwin b7f7cc25c0 libcasper: Neuter false positive -Wuse-after-free warnings from GCC 13
GCC 13 incorrectly thinks a call to free after a failed realloc is a
use after free.

lib/libcasper/services/cap_grp/cap_grp.c: In function 'group_resize':
lib/libcasper/services/cap_grp/cap_grp.c:65:17: error: pointer 'buf' may be used after 'realloc' [-Werror=use-after-free]
   65 |                 free(buf);
      |                 ^~~~~~~~~
lib/libcasper/services/cap_grp/cap_grp.c:63:19: note: call to 'realloc' here
   63 |         gbuffer = realloc(buf, gbufsize);
      |                   ^~~~~~~~~~~~~~~~~~~~~~

Reviewed by:	imp, emaste
Differential Revision:	https://reviews.freebsd.org/D42576
2023-11-14 18:34:01 -08:00
Stephen J. Kiernan 5e3190f700 dirdeps: Update Makefile.depend* files with empty contents
Some Makefile.depend* files were committed with no contents or empty
DIRDEPS list, but they should have DIRDEPS with some contents.
2023-10-29 17:01:04 -04:00
Mariusz Zaborski afd74c4000 cap_net: correct capability name from addr2name to name2addr
Previously, while checking name2addr capabilities, we mistakenly used
the addr2name set. This error could cause a process to inadvertently
reset its limitations.

Reported by:	Shawn Webb <shawn.webb@hardenedbsd.org>
2023-10-23 23:11:23 +02:00
Warner Losh fa9896e082 Remove $FreeBSD$: two-line nroff pattern
Remove /^\.\\"\n\.\\"\s*\$FreeBSD\$$\n/
2023-08-16 11:55:10 -06:00
Warner Losh d0b2dbfa0e Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:55:03 -06:00
Warner Losh 1d386b48a5 Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:42 -06:00
Warner Losh b3e7694832 Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:16 -06:00
Shawn Webb 1723e7f33a cap_net.3: fix typo
Signed-off-by:	Shawn Webb <shawn.webb@hardenedbsd.org>
2023-06-21 11:26:34 -04:00
Warner Losh 4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Mark Johnston 7ee4066db1 cap_net tests: Skip tests if there is no connectivity
When testing cap_connect() and name/addr lookup functions, skip tests if
we fail and the error is not ENOTCAPABLE.  This makes the tests amenable
to running in CI without Internet connectivity.

Reviewed by:	oshogbo
MFC after:	2 weeks
Differential Revision:	https://reviews.freebsd.org/D39242
2023-04-27 09:42:36 -04:00
Simon J. Gerraty d9a4274795 Update/fix Makefile.depend for userland 2023-04-18 17:14:23 -07:00
Eric van Gyzen 179bffddf5 cap_dns, cap_net: fix host and service buffer handling
If a malicious casper process sent a host or service string that was
too long, cap_getnameinfo would overrun the caller's buffer by one byte.

The backends for this function needlessly allocated one extra byte
for these buffers.  This was harmless, but could be confusing to readers.

Reported by:	Coverity (an internal run at Dell)
Reviewed by:	oshogbo, emaste
MFC after:	1 week
Sponsored by:	Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D39347
2023-04-04 15:26:12 -05:00
Mark Johnston 615bf03e33 cap_dns tests: Convert to ATF, avoid failing when lookups don't resolve
The cap_dns tests require Internet access.  Currently they fail when
that's not available, which for CI purposes is undesirable.  Let's
instead skip the tests if none of the non-casper name/addr lookups
succeed.

To that end:
- Convert the tests to ATF so that skipping is easier to implement.
- Break up the tests into separate test cases.
- If one of the system (i.e., non-casper) lookup functions fails, skip
  the test if all of them failed, otherwise fail the tests, since
  partial failure indicates something is flaky and deserves a closer
  look.

Reviewed by:	oshogbo
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D39241
2023-03-30 19:36:00 -04:00
Mark Johnston 5d96ca7a30 cap_sysctl tests: Serialize
These tests fail spuriously when run in parallel, since some of them
write a value to a global sysctl, read it back, and expect to see the
written value.  These tests complete quite quickly in any case.

MFC after:	1 week
2023-03-30 19:35:59 -04:00
John Baldwin 7d8e1e8dd9 libcasper: Move helper libraries from /lib/casper to /lib.
These libraries are linked to directly by applications rather than
opened at runtime via dlopen().

Discussed with:	oshogbo
Reviewed by:	markj, emaste
Differential Revision:	https://reviews.freebsd.org/D39245
2023-03-29 15:04:28 -07:00
Alan Somers 6c93a2d0bc [skip ci] improvements to cap_sysctl.3
* Correct some function prototypes which were documented with the wrong
  pointer type.
* Clarify return values and requirements for freeing the limit handle.

MFC after:	1 week
Sponsored by:	Axcient
Reviewed by:	oshogbo
Differential Revision: https://reviews.freebsd.org/D37586
2022-12-08 12:45:47 -07:00
Mariusz Zaborski 26573e2c7f cap_netdb: Fix description style
MFC after:	1 week
2022-09-29 19:51:42 +02:00
Mariusz Zaborski 1e9ce60a6d cap_fileargs: silence warnings of unused variable
We still want to fetch the variable just to verify that the interface
is right.

Reported by:	pstef
2022-03-20 11:22:55 +01:00
Mariusz Zaborski f45ca435bd cap_net: fix verification of bind permission
MFC after:	5 days
2021-12-14 12:02:40 +01:00
Mariusz Zaborski 88910b8b7b cap_net: plug memory leak
MFC after:	5 days
2021-12-14 12:02:40 +01:00
George V. Neville-Neil 409d1bf7d6 Address review comments from 0mp, debdrup and oshogbo 2021-11-10 13:09:18 -05:00
George V. Neville-Neil 406feaa862 Initial clean up the language in the manual pages.
Summary: The manual pages need a bit of editing for language and clarity.

Reviewers: oshogbo, #manpages

Subscribers: imp

Differential Revision: https://reviews.freebsd.org/D32976
2021-11-10 13:09:18 -05:00
Gordon Bergling 3251ad29f4 libcasper(3): Correct some warnings found by mandoc
- inserting missing end of block: Sh breaks Bl
- moving content out of list: Pp
- missing comma before name: Nm cap_*
- comma in function argument: cap_*
- skipping paragraph macro: Pp after Sh
- sections out of conventional order: Sh AUTHORS

Reviewed by:	bcr
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D31144
2021-07-12 06:16:55 +02:00
Ryan Moeller 94dc571595 libcasper: Create a minimal cap_netdb service
Create a casper service for netdb functions.
Initially only cap_getprotobyname is implemented.

This is needed for capsicumizing sockstat.

Reviewed by:	oshogbo, bcr (manpages)
Relnotes:	yes
Differential Revision:	https://reviews.freebsd.org/D24832
2021-06-05 08:36:53 -04:00
Mark Johnston 44bbda649d cap_sysctl.3: Fix bugs in the example
- Correct the type of the sysctl value.
- Initialize the oldsize parameter to cap_sysctlbyname()

MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2021-04-28 10:38:52 -04:00
Mariusz Zaborski 2b1d0c0087 fileargs: fix double caching of the same file
In situations when the current file name wasn't the first element on
the list we were cleaning the current name too early.
This might cause us to pre-cache the same file twice.
2021-04-07 21:16:37 +02:00
Olivier Cochard f1c010d9f9 tests: Skip cap_fileargs if build without capsicum capabilities
Approved by:    oshogbo
Sponsored by:   Netflix
Differential Revision: https://reviews.freebsd.org/D2834
2021-01-26 22:19:36 +01:00
Mark Johnston 1a05d9519d libcasper/cap_grp tests: Reset the group database handle
Some tests verify that the capgrp capability does not permit calls to
setgrent(3), but all tests need to ensure that they reset the
capability's group database handle, otherwise the local process and
casper process will be out of sync.

The cap_pwd tests already handle this.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 month
2021-01-21 14:30:19 -05:00
Mariusz Zaborski dcdad29947 fileargs: add support for realpath 2021-01-10 12:44:06 +01:00
Mariusz Zaborski faaf43b2a7 fileargs: add tests 2021-01-09 21:56:09 +01:00
Mariusz Zaborski 459511895e cap_sysctl: expose structures and variables
Expose structures and variables that may be used on systems
build without Casper support.
2021-01-04 20:56:07 +01:00
Mariusz Zaborski 8c121177f0 casper: convert macros to inline functions
In libcasper, the first argument to the function is a structure that
represents a connection to Casper. On systems without Casper, macros
are used to interpose the Casper functions to standard libc ones.
This may cause errors/warnings that the variable is not used.
With the inline function, there is no such problem.
2021-01-04 20:55:35 +01:00
Mariusz Zaborski 34535dace9 cap_net: CAPNET_CONNECT and CAPNET_CONNECTDNS are not mutually exclusive
Fix the for the CAPNET_CONNECT and CAPNET_CONNECTDNS.
Add test to ensure that this is possible.
2021-01-03 17:10:35 +01:00
Mariusz Zaborski b7876aec95 cap_net: allow to use the service without setting the limits
Add test to ensure that this is possible.
2021-01-03 17:09:20 +01:00
Adrian Chadd 388197f414 [libcasper] Update cap_dns API to not trigger unused variable warnings when disabled
When compiling without casper these API calls result in unused variable warnings.
Using #defines was lovely in the past but unfortunately it triggers warnings
which can cascade into errors.

Instead, just inline with some fallthrough functions and keep things happy.

Tested:

* gcc-6 targeting mips32, with casper disabled

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D26762
2020-10-13 22:49:43 +00:00
Kyle Evans fe815331bb build: provide a default WARNS for all in-tree builds
The current default is provided in various Makefile.inc in some top-level
directories and covers a good portion of the tree, but doesn't cover parts
of the build a little deeper (e.g. libcasper).

Provide a default in src.sys.mk and set WARNS to it in bsd.sys.mk if that
variable is defined. This lets us relatively cleanly provide a default WARNS
no matter where you're building in the src tree without breaking things
outside of the tree.

Crunchgen has been updated as a bootstrap tool to work on this change
because it needs r365605 at a minimum to succeed. The cleanup necessary to
successfully walk over this change on WITHOUT_CLEAN builds has been added.

There is a supplemental project to this to list all of the warnings that are
encountered when the environment has WARNS=6 NO_WERROR=yes:
https://warns.kevans.dev -- this project will hopefully eventually go away
in favor of CI doing a much better job than it.

Reviewed by:	emaste, brooks, ngie (all earlier version)
Reviewed by:	emaste, arichardson (depend-cleanup.sh change)
Differential Revision:	https://reviews.freebsd.org/D26455
2020-09-18 17:17:46 +00:00
Mariusz Zaborski 832dc76b63 libcasper: Introduce cap_net a network service for Casper.
Reviewed by:	emaste, markj (previous version), bcr (man page)
Differential Revision:	https://reviews.freebsd.org/D24688
2020-08-16 18:12:21 +00:00
Gordon Bergling 421f325efc libcasper(3): Document HISTORY within the manpages
Reviewed by:	bcr (mentor)
Approved by:	bcr (mentor)
MFC after:		7 days
Differential Revision:	https://reviews.freebsd.org/D24695
2020-06-16 16:48:52 +00:00
Mark Johnston c78e42e207 cap_fileargs: Fix a descriptor leak in the service process.
The service handler for fileargs_open() tries to pre-open multiple files
and pass descriptors for each back to the sandboxed process in a single
message.  This is to amortize the cost of round-trips between the two
processes.

The service process adds a "cache" nvlist to the reply to "open",
containing file descriptors for pre-opened files.  However, when adding
that nvlist to the reply, it was making a copy, effectively leaking the
cached descriptors.

While here, fix spelling in a local variable name.

PR:		241226
Reviewed by:	oshogbo
MFC after:	3 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D25095
2020-06-01 15:32:13 +00:00
Alan Somers 133b8ab5bb cap_dns.3: fix some orphan .Xr links
Reported by:	phk
MFC after:	2 weeks
2020-04-18 20:13:43 +00:00
Conrad Meyer b30c6ac9f9 libcasper(3): Export functions to C++
We must wrap C declarations in __BEGIN / __END_DECLS to avoid C++ name-mangling
of the declaration when including the C header; name-mangling causes the linker
to attempt to locate the wrong (C++ ABI) symbol name.

Reviewed by:	markj, oshogbo (earlier version both)
Differential Revision:	https://reviews.freebsd.org/D24323
2020-04-07 16:40:41 +00:00
Conrad Meyer 2750f1b954 libcasper: Constify cap_sysctl_limit_mib() mib parameter
No functional change. Minor API change that is nicer for consumers. ABI is
identical; the routine never needed to modify the pointed to value.

Reviewed by:	emaste, markj
Differential Revision:	https://reviews.freebsd.org/D24319
2020-04-06 23:07:56 +00:00
Simon J. Gerraty 2c9a9dfc18 Update Makefile.depend files
Update a bunch of Makefile.depend files as
a result of adding Makefile.depend.options files

Reviewed by:	 bdrewery
MFC after:	1 week
Sponsored by:   Juniper Networks
Differential Revision:  https://reviews.freebsd.org/D22494
2019-12-11 17:37:53 +00:00
Kyle Evans b3bec79d36 cap_sysctl: correct typo from r347534-ish
operation & ~limit where limit is a bool is clearly not what was intended,
given the line prior. Correct it to use the calculated mask for validation.

The cap_sysctl tests should now be functional again.
2019-10-23 03:23:14 +00:00
Emmanuel Vadot 724fad3ad0 pkgbase: Move libcap_ to FreeBSD-runtime
A lot of binaries present in FreeBSD-runtime depend on it so move
the libs there.

Reviewed by:	bapt, gjb
Differential Revision:	https://reviews.freebsd.org/D21501
2019-09-05 14:10:26 +00:00