638 Commits

Author SHA1 Message Date
Andrew G. Morgan
4f96e6788d Up the release version to 2.66
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
sig-libcap-2.66 v1.2.66 cap/v1.2.66 libcap-korg-2.66 psx/v1.2.66 libcap-2.66
2022-09-24 13:37:39 -07:00
Andrew G. Morgan
60ff008d95 Fix typos in the cap_from_text.3 man page.
This addresses this bug reported by Paulo Andrade (thanks!):

  https://bugzilla.kernel.org/show_bug.cgi?id=216514

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-09-22 06:54:37 -07:00
Andrew G. Morgan
281b6e47e1 Add captrace to .gitignore file
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-09-22 06:45:32 -07:00
Andrew G. Morgan
09a2c1dbb8 Add an example of using BPF kprobing to trace capability use.
$ make
$ sudo go/captrace your-program

will attempt to explore what capabilities are needed to run
your program by observing when cap_capable() inside the kernel
is associated with your-program.

Other ways to invoke this are

$ sudo go/captrace --pid=<pid>
$ sudo go/captrace

The last of these traces everything running on a system.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-09-18 16:56:40 -07:00
Andrew G. Morgan
26e3a096a4 Clean up getpcaps code.
Address some corner cases and trim down the size of the code a bit.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-09-04 14:36:52 -07:00
Jakub Wilk
fc804acc07 getpcaps: catch PID parsing errors.
Signed-off-by: Jakub Wilk <jwilk@jwilk.net>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-09-04 14:10:11 -07:00
Andrew G. Morgan
fc437fd830 Fix an issue with bash displaying an error.
Also down size the default capabilities needed by the 'sucap' su program.

This is aimed at addressing:

   https://bugzilla.kernel.org/show_bug.cgi?id=215926

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-08-05 20:43:05 -07:00
Andrew G. Morgan
7db9589038 Some more simplifications for building
I'm not 100% sure this is needed, but I'm not yet convinced
'make distclean && make -j48 test' works reliably, but I find this
easier to reason about.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-07-22 07:22:57 -07:00
Andrew G. Morgan
27e801bcbc Fix for "make clean ; make -j48 test"
Missed a vendor dependency for the ok.go file. More recent go releases
seem more picky about module or vendoring being used, and for the in-tree
builds we consistently use vendoring. So make sure the vendoring
directory set up has completed before trying to build ok.go.

The failure was reported by Tomasz Kłoczko.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-07-21 11:52:47 -07:00
Andrew G. Morgan
a47d86dfb9 Up the release version to 2.65
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
sig-libcap-2.65 cap/v1.2.65 libcap-korg-2.65 psx/v1.2.65 v1.2.65 libcap-2.65
2022-07-17 15:33:06 -07:00
Andrew G. Morgan
fc99e56150 Include more signatures in pgp.keys.asc.
These updates should also be available on keyservers.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-07-09 13:48:48 -07:00
Andrew G. Morgan
52288ccc0b Close out this comment in the go/Makefile
The deadlock issue is fixed in go1.18.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-05-17 07:10:19 -07:00
Andrew G. Morgan
eb0f1df722 Prevent 'capsh --user=xxx --' from generating a bash error.
This change adds support to capsh for the --noenv argument, which
will restore pre-libcap-2.65 behavior to capsh. The change we're
making here, however, is that capsh will now set the USER and HOME
environment variables when the command line contains --user=xxx.

The issue this addresses is described here:

  https://bugzilla.kernel.org/show_bug.cgi?id=215926

This has been annoying me for long enough, and I want to clean up
the article:

  https://sites.google.com/site/fullycapable/inheriting-privilege

to not pepper "--norc" in distracting places.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-04-30 16:04:47 -07:00
Andrew G. Morgan
9a95791818 Improve documentation for cap_get_pid and cap_reset_ambient.
- cap_get_pid() add detail about the function argument and return
  value when used across namespaces. Thanks to nemonemo for reporting:

    https://bugzilla.kernel.org/show_bug.cgi?id=215812

- cap_reset_ambient() had some factually incorrect content. Thanks to
  Tinker One for reporting:

    https://bugzilla.kernel.org/show_bug.cgi?id=215910

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-04-28 21:27:57 -07:00
Andrew G. Morgan
21d08b03c2 Fix syntax error in DEBUG protected setcap.c code.
Bug reported with fix from yixiangzhike.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-04-17 06:41:23 -07:00
Andrew G. Morgan
94250487ed More useful captree usage string and man page.
Include more detail about command line expectations
and exit status values.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-04-11 10:23:18 -07:00
Andrew G. Morgan
38cfa2e958 Up the release version to 2.64
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
sig-libcap-2.64 cap/v1.2.64 psx/v1.2.64 v1.2.64 libcap-korg-2.64 libcap-2.64
2022-04-10 15:39:39 -07:00
Andrew G. Morgan
7617af6b07 Avoid a deadlock in forked psx thread exit.
go/captree was seeing lots of libcap_psx_test processes hanging around.
It turns out that the newly added _psx_cleanup() function was deadlocking
because inside a forked processes the psx_tracker.state was _PSX_INFORK
and never _PSX_IDLE.

This completes the fix for:

  https://bugzilla.kernel.org/show_bug.cgi?id=215551

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-04-10 15:39:14 -07:00
Andrew G. Morgan
fc029cb517 Include LIBCAP_{MAJOR,MINOR} #define's in sys/capability.h
It looks like various distributions are fairly far behind HEAD for
their version of libcap. This way folk can work around a lack of
features in their code.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-04-10 14:49:26 -07:00
Andrew G. Morgan
ceaa591b01 Clarify how the cap_get_pid() argument is interpreted.
Addresses:

  https://bugzilla.kernel.org/show_bug.cgi?id=215812

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-04-09 17:02:13 -07:00
Andrew G. Morgan
15cacf2070 Fix prctl return code/errno handling in libcap.
Bug reported by Anderson Toshiyuki Sasaki:

   https://bugzilla.kernel.org/show_bug.cgi?id=215772

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-03-29 18:10:10 -07:00
Andrew G. Morgan
aae937481a Be explicit about CGO_ENABLED=1 for compare-cap build.
It looks like go1.18 is going to default to CGO_ENABLED=0, so force
CGO_ENABLED=1 when building this cap-libcap comparison program.

Fixes:

  https://bugzilla.kernel.org/show_bug.cgi?id=215603

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-02-13 19:58:05 -08:00
Andrew G. Morgan
66a8a1421e psx: free allocated memory at exit.
Kalen Hall reported that Valgrind detected a memory leak associated
with a multi-threaded program linked against libcap and libpsx.

  https://bugzilla.kernel.org/show_bug.cgi?id=215551

I've been unable to validate this myself with valgrind (likely holding
it wrong), but did explore psx for allocated memory and via fprintf's
convinced myself that this change should pair all calloc()s with a
corresponding free().

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-02-05 17:26:05 -08:00
Andrew G. Morgan
1d88048c31 Up the release version to 2.63
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
sig-libcap-2.63 psx/v1.2.63 cap/v1.2.63 libcap-korg-2.63 v1.2.63 libcap-2.63
2022-01-23 16:36:22 -08:00
Andrew G. Morgan
e1bd9ac089 Trim includes.
I've upgraded one of my systems to Fedora 35 and I found trimming
the headers in this way made the three compilations of libcap, used
by `make distcheck`, work with standard Fedora 35 compiler packages.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-01-23 16:36:06 -08:00
Andrew G. Morgan
bbabfb4cf4 Add a test case for a deadlock.
The CGO_ENABLED=0 failure mode is discussed in:

  https://github.com/golang/go/issues/50113

At the present time, this only passes when the psx package is compiled
CGO_ENABLED=1. The problem being that a blocking read cannot be
interrupted by the CGO_ENABLED=0 build of package "psx". It does not
deadlock when compiled CGO_ENABLED=1 because the psx signal wakes the
reading thread up back into user space.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-01-23 16:35:23 -08:00
Andrew G. Morgan
f25a1b7e69 Reset the value of errno for main()
Since libcap does some error testing with a pre-main() constructor,
reset errno to zero as that constructor returns.

Problem reported by Yang Xu.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-01-19 06:44:58 -08:00
Andrew G. Morgan
cbdd2b14e0 Fix argument crash dump order in psx text dumper.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-12-13 07:30:09 -08:00
Andrew G. Morgan
af2bf057ed Make cgo psx_syscall variant crash like runtime.AllThreadsSyscall
When a syscall that yields different return values is called from
the Go psx.Syscall*() API, we want to mirror the behavior of the
native golang runtime.AllThreadsSyscall() function.

The previous inconsistency was pointed out by Lorenz Bauer in:

  https://bugzilla.kernel.org/show_bug.cgi?id=215283#c8

[I decided to defer this change until 2.63, and not include this
in the bug-fix for 215283, on the grounds it is a slight
incompatibility in runtime behavior, and wanted to give folk an
opportunity to plan for it. This new behavior enforcement will
crash an unprepared go program.]

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-12-12 11:52:16 -08:00
Andrew G. Morgan
cc91f55960 Up the release version to 2.62
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
sig-libcap-2.62 cap/v1.2.62 libcap-korg-2.62 psx/v1.2.62 v1.2.62 libcap-2.62
2021-12-11 18:06:34 -08:00
Andrew G. Morgan
89b4b8021d Clean up cap package documentation for Launch.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-12-11 18:01:14 -08:00
Andrew G. Morgan
e458889fbd Complete launch thread exit sequence.
This should complete the fix for:

  https://bugzilla.kernel.org/show_bug.cgi?id=215283

Simplify the code, and add a test that the kernel has confirmed that
the thread is no longer running.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-12-11 14:56:07 -08:00
Andrew G. Morgan
806b53d13a Take more care post launch
Lorenz Bauer found a race condition in the cap.Launcher teardown
process and reported it here:

   https://bugzilla.kernel.org/show_bug.cgi?id=215283

This seems to significantly improve the situation. I'm going to
study the test case some more, but this is definitely part of the
solution.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-12-10 20:59:19 -08:00
Andrew G. Morgan
1fe7dbe984 Drop perl from the build requirements.
David Seifert at Gentoo made a request to not require perl for
the libcap build since their distribution wants to build it prior
to building perl and so requiring it requires they maintain some
extra patches.

We previously introduced the need for perl in response to some
apparent incompatibilities between various versions of sed:

https://git.kernel.org/pub/scm/libs/libcap/libcap.git/commit/?id=9494a1fab59ac0b6e4f0bfc536fa482c6d6490b6

However, it has been 13 years since that time so we're optimistic
those problems are no longer present for anyone and we've also
added a make variable abstraction in case some builder wants to
override their system default 'sed' as make BUILD_SED=... etc.

We've also done something similar with make uses of grep, egrep
and fgrep.

Finally, for make variable naming consistency, we've replaced use
of BUILD_GPERF with USE_GPERF. Since folk may be using BUILD_GPERF
in their package building scripts, we error out if it is set.
The expectation is that people will update their package defs.
(Eventually, we plan to reuse BUILD_GPERF as an alias for 'gperf'.)

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-12-04 10:18:50 -08:00
David Seifert
9d3c758181 Fix -Wformat on 32-bit platforms
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-28 08:40:18 -08:00
Andrew G. Morgan
2ec5fdcdd5 Include link for cap_max_bits.3 man page.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-21 10:18:55 -08:00
Andrew G. Morgan
42555598bf Recognize default secbits of 0 as "HYBRID" mode.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-21 09:39:02 -08:00
Andrew G. Morgan
d63835d491 Up the release version to 2.61
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
sig-libcap-2.61 psx/v1.2.61 cap/v1.2.61 v1.2.61 libcap-korg-2.61 libcap-2.61
2021-11-20 22:20:04 -08:00
Andrew G. Morgan
1e9320e48e Clean up libpsx.so execable mode.
The previous commit crossed the beams on libpsx.so and libcap.so
executable build. This commit decouples them.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-20 22:16:08 -08:00
Andrew G. Morgan
4c7dde9f51 Add some more info to the libcap.so as an executable.
Mostly cause we can, but this gives a little more diagnostic
value to the libcap.so executable mode of operation.

usage: libcap.so [--help|--usage|--summary]

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-20 16:55:58 -08:00
Andrew G. Morgan
f7deb5ad45 Add some information about cap_max_bits().
This function has been defined for a while (since libcap-2.30),
but I just found it wasn't documented.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-20 16:36:44 -08:00
Andrew G. Morgan
e0582d0aee Prune the the.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-17 09:21:31 -08:00
Andrew G. Morgan
9fa2fe739c Force libcap.so to initialize itself when run directly.
Not sure where this will go, but libcap.so uses _libcap_initialize()
to set itself up at start up. So, run it when invoking libcap.so
directly as a binary.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-14 21:11:23 -08:00
Andrew G. Morgan
e9414f540a Work around musl not hard-coding the ABI for Linux x86_64.
There seems to be a subtle difference between glibc and musl over
whether or not a runnable *.so needs to start out with its stack
aligned to 16 bytes or not. Since Linux ABIs for x86 (both 32 and
64 bit varieties) require 16 byte alignment, just force it on both
these architectures.

This addresses:

  https://bugzilla.kernel.org/show_bug.cgi?id=215009

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-14 20:38:30 -08:00
Andrew G. Morgan
c234bf9083 Work around a __i386__ compilation issue for runnable .so files.
This was reported by Sam James and debugged with respect to:

  https://bugs.gentoo.org/show_bug.cgi?id=820071

Modern versions of glibc employ SSE instructions that require the
stack to be aligned to 16 bytes in order to execute movaps and
friends to stack stored memory. The ABI for x86_64 requires this
alignment so we'd not seen this issue before being cc:d into the
bug.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-13 20:44:13 -08:00
Andrew G. Morgan
0c463bf38d Pick the correct topdir in our sucap example.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-10 23:29:12 -08:00
Andrew G. Morgan
2e4335523e Include some helpful debugging for capso.so
This makes explaining how the program works more straightforward.

That is:

  make CAPSO_DEBUG=-DCAPSO_DEBUG clean all

builds a version that prints out some helpful info and pauses so
the user can observe the capability state of the process tree at
different stages of execution.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-09 07:28:59 -08:00
Andrew G. Morgan
9508559876 Use calloc'd memory for unix domain socket exchange.
This seems more stable for passing file descriptor from privileged
child to unprivileged parent.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-07 15:09:13 -08:00
Andrew G. Morgan
2b763ab706 An example of a shared library object with its own file capability.
I've been exploring the idea of how to create limited use privileged
binaries that can be linked into otherwise unprivileged binaries.
This is a worked example of the bootstrapping process for a webserver.

I intend to provide a more complete writeup of what is going on with this
example here:

  https://sites.google.com/site/fullycapable/capable-shared-objects

For this present example to work you have to be using a libcap that
includes cap_launch support (ie., libcap 2.33+, but this code will be
included with libcap-2.61 and might inadvertently actually require
something that new to work robustly).

This code appears to be very fragile at present. It works on my
Chromebook's linux container, but not under Fedora 34 - segfaulting.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-07 09:59:35 -08:00
Andrew G. Morgan
9c4997d659 capsh: better error handling for integer parsing.
Bug reported by meitingli:

   https://bugzilla.kernel.org/show_bug.cgi?id=214911

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-11-06 08:45:06 -07:00