Commit Graph

151 Commits

Author SHA1 Message Date
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
db1cdf2fab libcasper.3: document cap_init's single-threaded program requirement
Because it internally forks.

[skip ci]
MFC after:	1 week
Sponsored by:	Axcient
Reviewed by	emaste, imp
Differential Revision: https://reviews.freebsd.org/D38020
2023-01-10 20:53:30 -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
facd6b58d5 libcapser: Add reference to cap_netdb
MFC after:	1 week
2022-09-29 19:51:04 +02:00
Jens Schweikhardt
0f6a767c02 Replace a dead cross reference with the proper (I think) macro. 2022-08-13 22:55:10 +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
06a8ffd4cd Fix two more nits from 0mp 2021-11-10 13:09:19 -05: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
Mariusz Zaborski
aa310ebfba libcasper: fix descriptors numbers
Casper services expect that the first 3 descriptors (stdin/stdout/stderr)
will point to /dev/null. Which Casper will ensure later. The Casper
services are forked from the original process. If the initial process
closes one of those descriptors, Casper may reuse one of them for it on
purpose. If this is the case, then renumarate the descriptors used by
Casper to higher numbers. This is done already after the fork, so it
doesn't break the parent process.

PR:		225343
Reported by:	Borja Marcos <borjam (at) sarenet.es>
Tested by:	jkim@
2021-06-10 12:41:29 +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
d2ceee38ca 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.

I omitted this file in: 8c121177f0
2021-01-12 19:40:45 +01: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
Mariusz Zaborski
4084669d18 capser: add cap_net to the list of services 2021-01-03 16:55:35 +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
Mateusz Piotrowski
f4b792fa67 Fix trailing-comma-related typos in the tree when the Xr macro is used
MFC after:	1 week
2020-06-27 11:13:45 +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
Kyle Evans
e735aa5a74 libcasper/services: include <src.opts.mk> to hook tests to build
Note that the cap_sysctl tests are currently failing and need some
attention.
2019-10-23 01:50:41 +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
Mariusz Zaborski
9509775394 cap_filergs: limit size of the file name
The limit of the name in fileargs is twice the size of the MAXPATH.
The nvlist will not add an element with the longer name.
We can detect at this point that the path is too big, and simple return
the same error as open(2) would.

PR:		239700
Reported by:	markj
Tested by:	markj
MFC after:	2 weeks
2019-08-07 19:30:33 +00:00
Mariusz Zaborski
64b3a6b3b3 fileargs: fix formating in EXAMPLES
PR:		239523
Submitted by:	mikael.urankar@gmail.com
2019-07-30 08:53:03 +00:00
Mariusz Zaborski
8cf7941693 libcasper: remove reference to deprecated system.random 2019-07-29 21:26:26 +00:00
Mark Johnston
a76f78dc3f Remove cap_random(3).
Now that we have a way to obtain entropy in capability mode
(getrandom(2)), libcap_random is obsolete.  Remove it.

Bump __FreeBSD_version in case anything happens to use it, though I've
found no consumers.

Reviewed by:	delphij, emaste, oshogbo
Relnotes:	yes
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D21033
2019-07-24 22:50:43 +00:00
Mark Johnston
89e9665b8d Link fileargs_lstat.3.
Sponsored by:	The FreeBSD Foundation
2019-07-21 16:35:49 +00:00