665 Commits

Author SHA1 Message Date
Andrew G. Morgan
3c7dda330b Up the release version to 2.68
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
sig-libcap-2.68 cap/v1.2.68 libcap-korg-2.68 psx/v1.2.68 v1.2.68 libcap-2.68
2023-03-25 17:03:17 -07:00
Andrew G. Morgan
3a93d8edcf Undo hiding the wrapped function call in libpsx.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-03-25 16:55:20 -07:00
Andrew G. Morgan
5496a0e385 Tidy up some text explaining cap.NamedCaps.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-03-19 20:18:44 -07:00
Andrew G. Morgan
8c435a6fec Some formatting fixes for the libpsx man page.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-03-18 18:02:44 -07:00
Andrew G. Morgan
9c084eceb2 Replace the README with a README.md
Also include the `go mod tidy` detail.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-03-11 18:11:47 -08:00
Andrew G. Morgan
e32563557b Recognize the new man page links.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-02-19 19:57:41 -08:00
Andrew G. Morgan
44ab72a6f9 Update documentation for all API functions.
There were a few straggler API functions in libcap and libpsx.
Also some functions that should be hidden from references outside
the library.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-02-19 19:43:13 -08:00
Andrew G. Morgan
5c6c1fbebc Drop vendor directory and clean up extra gcc...sh file
These three files were left over, they should have been
removed in the last commit.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-02-11 21:15:03 -08:00
Andrew G. Morgan
7e41da1050 Simplify and refactor the bug215510 code.
This code is investigating the issue:

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

This present commit extends x86_64 (aka amd64) support to 32-bit
arm build support. It is now possible cross compile the program
for the Raspberry Pi. To do this, the code needs 'docker' to work.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-02-11 19:02:11 -08:00
Andrew G. Morgan
ddbaa98412 Make the compare-cap binary clean up after itself.
When run via sudo, compare-cap exits with some file capabilities
left on its binary file. This is a test binary, so that's not a
big problem, however, it does mean that a 2nd run of the program
is started with, potentially, a different initial state.

This commit fixes that exit condition and addresses:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-02-09 20:13:25 -08:00
Andrew G. Morgan
329b69ea64 Be more strict about what symbols are externally visible.
Increase the enforcement of the documented libcap API by marking
internal library utility functions as "hidden". This also goes
for the .so executable entry points.

This addresses this bug:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-02-08 19:13:45 -08:00
Andrew G. Morgan
dbb9617e6f Sigh. Fix some copy-pasta errors with psx_test.go changes.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-02-06 19:06:27 -08:00
Andrew G. Morgan
b6d210ee03 Add some more explicit testing to the psx_test.go code.
While we test this in many other places, we didn't test this
explicitly in the psx.go local testing before. Now we do.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-02-06 18:55:40 -08:00
Andrew G. Morgan
27954dde34 Provide a method to import preamble and postscript for md man pages
If you have local files:

   .../libcap/doc/local-md.preamble
   .../libcap/doc/local-md.postscript

when you run .../libcap/doc/mkmd.sh these two files will be inlined
into the generated index.md file.

This addresses:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-02-06 18:01:43 -08:00
Andrew G. Morgan
cf91d35d62 Drop an unnecessary use of ", _" from captree.go
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-02-06 07:50:02 -08:00
Andrew G. Morgan
34b0329dc7 Up the release version to 2.67
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
sig-libcap-2.67 psx/v1.2.67 cap/v1.2.67 libcap-korg-2.67 v1.2.67 libcap-2.67
2023-02-02 20:10:27 -08:00
Andrew G. Morgan
3f483219d5 Resolve a couple of compiler warnings.
Explicitly add (void) as argument lists for two function definitions:

   cap_reset_ambient(void)
   _libcap_initialize(void)

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-02-02 20:10:06 -08:00
Andrew G. Morgan
9bdfc8609a Clean up some of the markdown text.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-10-30 13:52:38 -07:00
Andrew G. Morgan
6521defb40 Minor clean ups of the contrib/bug216610 code/docs
I generated  mirror on github to conveniently see the .md docs and
found a few typos.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-10-29 21:30:08 -07:00
Andrew G. Morgan
0d528688fe Add support for optimized C compilation to .syso objects.
It took me a while to figure out why optimized C compilation seemed
to generate miscomputation of the Fibonacci number sequence. It appears
to be an unresolved issue with Go's internal linking which is discussed
here:

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

For a compute kernel, it seems important to be able to accommodate
compiler optimization. This adds some refinement for the strategy
I'm exploring to address:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-10-29 20:24:17 -07:00
Andrew G. Morgan
08d48b659a Add an example of combining Go, C code and "psx" without cgo.
This example was developed while investigating the issues discussed in:

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

At this time, it is not possible to build CGO_ENABLED=1 and include
the "psx" package without using its "cgo"-tagged build variant.

This example provides a worked example of doing the opposite: link a
CGO_ENABLED=0 binary with "psx", including some compiled C code.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-10-23 15:28:58 -07:00
Andrew G. Morgan
70998415a8 Reviewed license information and adde SPDX ids.
Günther Noack reported some issues with automated dependency checking in

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

Perhaps these additional lines will help assist those things.

I did find a typo in pam_cap/execable.c so I've fixed that.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-10-19 19:05:11 -07:00
Andrew G. Morgan
10041371f4 Reviewed man pages, adding overlooked references.
This started out as addressing this bug:

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

But I then made crosslink.sh to figure out what I had missed, and
fixed those bits too.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-10-16 17:09:11 -07:00
Andrew G. Morgan
f30f85c637 Modify DYNAMIC=no linking to only refer to libcap.a
There is a longstanding WONT_FIX bug:

https://sourceware.org/bugzilla/show_bug.cgi?id=12491

that has been causing capsh, when linked fully statically,
to segfault. So, for non-dynamic linking of capsh etc utilities
only link statically to libcap. This way, in tree builds can be
guaranteed to get to execute with in tree API changes. For
normal installations, DYNAMIC=yes works as before.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-10-15 08:29:42 -07:00
Andrew G. Morgan
911da84bf4 Add some exploit demonstration code to capso.so
This exploit code requires a make variable to activate, but
is used in the companion article discussing this code to compare
and contrast setuid-root to file capable privilege. Tl;dr don't
use setuid-root for shared libraries in this way!

Follow along here:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-10-09 14:41:45 -07:00
Andrew G. Morgan
b643699aa6 Address bad-whatis-entry issue noticed by Debian build tests
Details:

https://www.mit.edu/afs.new/sipb/project/debathena/lintian/www/tags/manpage-has-bad-whatis-entry.html

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-10-04 21:48:36 -07:00
David Seifert
45bf9259a0 Use POSIX grep
* GNU grep 3.8 considers `egrep` and `fgrep` obsolescent and throws warnings:

    ./mkcapshdoc.sh > capshdoc.c.cf
    fgrep: warning: fgrep is obsolescent; using /bin/grep -F
    fgrep: warning: fgrep is obsolescent; using /bin/grep -F
    fgrep: warning: fgrep is obsolescent; using /bin/grep -F
    fgrep: warning: fgrep is obsolescent; using /bin/grep -F
    [...]

  https://lists.gnu.org/archive/html/info-gnu/2022-09/msg00001.html

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-09-29 06:54:24 -07:00
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