140 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
e4725c1a9e Add --quiet and cap_launch() support to capsh.
The flag --quiet causes capsh to suppress its startup check that
the linked libcap has support for all of the named capabilities
of the hosting kernel.

The cap_launch() support is via "-+" and "=+" arguments. These use
cap_launch() to fork() before exec*()ing the corresponding command
but are otherwise equivalent to "--" and "==" respectively.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-10-22 20:51:02 -07:00
Andrew G. Morgan
73194f5369 Make cap_launcher_t operations atomic.
Modify the cap_launch() behavior when chroot is set. Now, the
launcher code will force the post chroot() environment to
chdir("/").

Modify the API for many of the cap_launch_*() functions that
previously were void, to returning int (0=OK, -1=see errno).
I'm confident that this should be code backwardly compatible,
since the return values are new and prior code would have been
assuming success.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-10-22 12:10:40 -07:00
Andrew G. Morgan
5b16d336d0 Add a cap_iab_dup() function and make IAB access atomic.
Embed mutex locked operation into the IAB API. The idea being that
while libcap operates on an IAB tuple, it cannot be operated on by
a thread running in parallel. This makes IAB access thread safe (but
not reentrant).

The only potential API behavioral change is that the IAB tuple
associated with a cap_launcher_t is now locked for the duration of
its association with that launcher. This prevents a race condition
with launching and another thread changing that IAB tuple.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-10-22 11:34:53 -07:00
Andrew G. Morgan
2ffbc9d248 Implement cap_fill_flag() and cap.FillFlag() APIs.
This API avoids a complex use case that requires substantially
more code outside of libcap.

Signed-off-by: Andrew G. Morgan <agm@google.com>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-10-01 19:18:48 -07:00
Andrew G. Morgan
d07df10aaa Fix miscellaneous build and lint warnings.
Addresses the issues listed here:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-09-29 21:42:33 -07:00
Andrew G. Morgan
6643c636e8 Recognize that NULL is an invalid cap_t and cap_iab_t.
This was a regresssion introduced in libcap-2.55. Fixed in libcap-2.59.
Added a cap_launch NULL test too. Comparing against NULL would cause a
SIGSEGV against these library revisions.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-09-24 10:46:24 -07:00
Andrew G. Morgan
b35370f7f6 Implement --strict capsh argument.
Up to this point, capsh hides some complexity concerning raising
the CAP_SETPCAP in order to raise inheritable and drop bounding
set values. This made it harder to explain some aspects of
inheritance, and I ran into that detail writing this:

https://sites.google.com/site/fullycapable/why-didnt-that-work#h.z7rwbcazhr4r

Refactored capsh.c to clean up some buggy code, and also fix some
documentation, including reference to the --strict argument.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-09-07 13:14:54 -07:00
Andrew G. Morgan
8434c10a69 Be more systematic about POSIX.1e value group names
cap.Set's have Flag component Values
cap.IAB's have Vector component Values

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-09-07 10:47:45 -07:00
Andrew G. Morgan
967b3a0a95 Add --mode query support to capsh
This addresses the feature request:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-09-05 11:42:28 -07:00
Andrew G. Morgan
5ef14d0742 Refactor top level Makefile to reduce redundant building
Make build a bit quicker for folk that don't want to run tests.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-09-04 14:05:11 -07:00
Andrew G. Morgan
c54a087429 Document latest option for captree in its man page.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-09-02 20:03:09 -07:00
Andrew G. Morgan
41f065cdc9 cap_iab.3 doc fixes and cleanup
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-09-01 07:25:18 -07:00
Andrew G. Morgan
b9d56654de Update man pages.
Some fixes, some more efficient URLs, some more coherrent cross-references.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-29 15:43:17 -07:00
Andrew G. Morgan
b972c50c09 Add captree command line options and support process by name.
Add some features to captree. I plan to post a companion article
here:

   https://sites.google.com/site/fullycapable/captree

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-29 15:42:17 -07:00
Andrew G. Morgan
61b2fcc451 Make sudotest more robust against untestable environments
I'm setting up some testing environments and they are not all
created equal.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-28 16:50:35 -07:00
Andrew G. Morgan
4f45bcc835 Add cap_iab_{compare,get_pid} functions to libcap; --iab to getpcaps.
This brings libcap back to parity with the Go 'cap' package. We
provide a CAP_IAB_DIFFERS(result, vector) macro to evaluate the result
of cap_iab_compare().

Extend the getpcaps arguments to include --iab. This causes the utility
to explore the IAB tuple for the specified process. When used, this
outputs a text representation in a similar format to that of the
'captree' (Go) utility.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-22 21:13:56 -07:00
Samanta Navarro
e721aff543 Fix typos.
Typos found with codespell

Signed-off-by: Samanta Navarro <ferivoz@riseup.net>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-14 11:03:27 -07:00
Andrew G. Morgan
e1af96aa58 Add a note about cap_launch callback function return values.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-01 16:59:33 -07:00
Andrew G. Morgan
c523294a0c Clarify some cap_launch documentation.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-07-12 21:23:47 -07:00
Andrew G. Morgan
69f7ddbb12 Provide a '--current' command line argument for capsh.
This is equivalent to 'capsh --print|fgrep Current'. I've been using
that combination a lot in the write-ups on the libcap website
(https://sites.google.com/site/fullycapable/) and so it struck me
that capsh probably should support it natively.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-07-02 19:51:51 -07:00
Andrew G. Morgan
c89405455d Add fill support for the 1e capabilities
We previously added a cap_iab_fill() etc, functions. Bring the
regular capability flag manipulation API into alignment by
adding libcap.cap_fill() and (*cap.Set).Fill().

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-06-19 13:58:36 -07:00
Andrew G. Morgan
2f9b7f484c Shorten the URLs for bug reports and mention release notes.
In an effort to help folk contribute to the discussion around
existing bugs, and benefit from recently closed ones, update the
main library man pages with better direction towards recent info.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-05-17 09:33:40 -07:00
Andrew G. Morgan
578b4cd7bf Add support for --suggest=phrase to capsh.
Ever wondered something like which capability allows a process
to do privileged things with a tty? Try this:

  capsh --suggest="tty"

cap_sys_tty_config (26) [/proc/self/status:CapXXX: 0x0000000004000000]

    Allows a process to manipulate tty devices:
      - configure tty devices
      - perform vhangup() of a tty

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-05-16 18:36:24 -07:00
Andrew G. Morgan
572b1f8099 Validate that user namespaces require CAP_SETFCAP to map UID=0.
I found this corner case privilege escalation in December 2020.
Now that it is fixed upstream and widely deployed, add a test
so we don't regress.

[If you find 'make sutotest' fails for you, you should upgrade
your kernel.]

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-05-16 16:15:28 -07:00
Andrew G. Morgan
fe4c27de24 Add a module argument to pam_cap.so to assist with ambient support
Some PAM applications drop privilege when they change UID, which has
the side effect of dropping ambient capabilities. We add support for
the "keepcaps" argument which can be used in an attempt by the module
to not drop permitted capabilities when performing a setuid() call.
Some experimentation may be needed to see if this works for any given
application. To not be a security bug vector, it requires the application
so configured perform an exec() to launch a user-specific operation.

This is an attempt to provide some Adminstrator support for working
around the issue observed in this bug (report by Zoltan Fridrich):

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-05-07 20:06:36 -07:00
Andrew G. Morgan
e3b0094c0d Add some man page documentation for the capsh "--iab" argument
This inheritable tuple of capability vectors is another abstraction
managed by libcap.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-04-21 20:35:35 -07:00
Andrew G. Morgan
b48c649ef0 Minor fixes for man pages.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-04-18 15:15:54 -07:00
Andrew G. Morgan
13b97f953c Add some documentation for capsh --explain=cap_foo
This is a convenience parameter to describe in text the meaning of
a specific capability.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-04-17 16:46:46 -07:00
Andrew G. Morgan
cf6ddafe1d Add --explain=cap_foo support to capsh.
A convenience feature, so you don't have to grep the
system header, and/or wade through a man page.

This addresses:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-03-27 14:07:50 -07:00
Andrew G. Morgan
9ff6454107 A man page for the IAB set functions.
This addresses:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-03-10 22:18:40 -08:00
Andrew G. Morgan
fd5271195d Make the cap_launch.3 documentation and code use common conventions
The cap_launch() 2nd argument should be consistently named. So, we
choose "detail".

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-03-07 15:39:51 -08:00
Andrew G. Morgan
03433213de Update the man pages with a page for cap_launch.3
Provide links to the various functions used with libcap launching.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-03-07 14:59:21 -08:00
Andrew G. Morgan
b3c2cd00f3 Make documentation more consistently formatted
This is easier to edit and also seems to work with pandoc.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-03-06 18:19:04 -08:00
Andrew G. Morgan
df5a199108 Update the libpsx man page.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-02-02 18:18:25 -08:00
Andrew G. Morgan
68240b124c If needed search PATH for capsh (==) self-execution.
This addresses the following bug:

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

Namely, the following didn't previously work:

  PATH=/sbin capsh == --print

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-10-27 14:56:34 -07:00
Andrew G. Morgan
2a3beeb7a9 Clean up the libpsx.3 man page.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-10-13 08:09:07 -07:00
Andrew G. Morgan
1b99022113 Add new value CAP_CHECKPOINT_RESTORE = 40.
Linus' kernel has defined this one now.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-08-13 20:45:43 -07:00
Andrew G. Morgan
23a264ae6d Reflect a minor improvement in cap_to_text() output in man page.
Also, improve the "cap" package documentation to give an overview
of its text representation support.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-07-23 20:18:07 -07:00
Michael Kerrisk (man-pages)
349cd0a8ee Manual pages: cap_from_text.3: Clarify a detail of cap_from_text() action list
The fact that the action list of a cap_from_text() clause can include
multiple operator-flag pairs is a little hidden in this page. Make it
clearer by separating this information out into a separate paragraph and
showing an example of the equivalence to multple clauses.

Signed-off-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-07-23 19:07:11 -07:00
Michael Kerrisk (man-pages)
108acc4407 Manual pages: use "root user ID" rather than "rootid"
The capabilities(7) page has for quite some time used the term "root user ID",
which is, I think, a little more precise and expressive than "rootid".
I think it would be good if libcap used the same terminology,

Signed-off-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-07-23 18:58:39 -07:00
Michael Kerrisk (man-pages)
71e5108586 Manual pages: capsh.1: Change .TP indent to the default
Currently, the long list of options in this page is formatted as a
hanging list with a very deep indent (22), which causes the rendered
text to be rather narrow. That's uncomfortable when viewing on
something other than an 80 column display, and also causes some
ugliness in line breaks and line filling. Change to the more
traditional default indentation for .TP.

Signed-off-by: Michael Kerrisk (man-pages) <mtk.manpages@gmail.com>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-07-20 08:08:18 -07:00