224 Commits

Author SHA1 Message Date
Andrew G. Morgan
1a02e34cc4 Up the release version to 2.72
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-11-10 15:26:15 -08:00
Andrew G. Morgan
b017fcff26 Eliminating -wrap use.
This addresses the following bug:

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

insofar as it eliminates the need for -wrap=pthread_create
linkage. Mostly, code that uses -lpsx functions can simply
link with -lpsx now. However, for legacy reasons the library
still works when linked wrapped or with the new content of
the libpsx.pc file:

   -Wl,--no-as-needed -Wl,--whole-archive -lpsx -Wl,--no-whole-archive -Wl,--as-needed -lpthread

These last options are required for getting -lcap to act at a
consistent process level and not a thread level.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-11-09 23:19:18 -08:00
Andrew G. Morgan
31ed2fef38 Factor out the ((weak)) psx_load_syscalls() function.
Trying to find a path for not needing linker wrapping.
This feels like a step in the right direction, but doesn't
allow removal of the -wrap linkage yet.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-11-08 19:33:25 -08:00
Andrew G. Morgan
c5a06aea03 First step in eliminating libpsx "--wrap"ing linkage.
The refactored libpsx code does not operate at the pthread
abstraction. We still need the --wrap linkage to force
libpsx to be linked into the binary if the binary makes
no explicit calls to libpsx functions. But we should no
longer need it in cases where the code calls psx_syscall[36]().

This is a step towards addressing:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-11-05 06:45:29 -08:00
Andrew G. Morgan
c7dbcf0bc9 Up the release version to 2.71
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-10-25 22:17:54 -07:00
Andrew G. Morgan
c73ae0df31 c89 compilation test fix.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-10-24 21:28:22 -07:00
Andrew G. Morgan
676971a20a Document current behavior of cap_iab_set_proc()
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-09-22 11:11:44 -07:00
Andrew G. Morgan
7d571d1336 Suppress use of -Bsymbolic-functions which otherwise breaks libpsx
Credit to Stas Sergeev for unraveling this and reporting it:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-08-17 09:36:33 -07:00
Pierre-Clément Tosi
651d99fdf0 libcap: Use all $(xFLAGS) when building 'empty'
Pass the flags as they might be needed by $(CC) to properly compile or
link an executable (e.g. --sysroot).

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-08-17 08:50:55 -07:00
Andrew G. Morgan
bbcfccdcc4 Setting ambient bits does not require CAP_SETPCAP.
Limit the conditions where we raise CAP_SETPCAP to set an IAB value.
There are some situations where that capability is needed, but they
are by no means a requirement for all IAB value setting.

Credit for discovering this goes to Christopher Head and reporting
it in:

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

Update the man pages to better reflect use of Amibient bit setting.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-08-16 20:20:12 -07:00
Andrew G. Morgan
8fe536b53f Up the release version to 2.70
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-05-18 21:43:17 -07:00
Andrew G. Morgan
8bed80f9b5 Up the release version to 2.69
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-05-14 19:10:04 -07:00
Andrew G. Morgan
422bec25ae Large strings can confuse libcap's internal strdup code.
Avoid something subtle with really long strings: 1073741823 should
be enough for anybody. This is an improved fix over something attempted
in libcap-2.55 to address some static analysis findings.

Reviewing the library, cap_proc_root() and cap_launcher_set_chroot()
are the only two calls where the library is potentially exposed to a
user controlled string input.

Credit for finding this bug in libcap goes to Richard Weinberger of
X41 D-Sec GmbH (https://x41-dsec.de/) who performed a security audit
of the libcap source code in April of 2023. The audit was sponsored
by the Open Source Technology Improvement Fund (https://ostif.org/).

Audit ref: LCAP-CR-23-02 (CVE-2023-2603)

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-05-09 18:49:46 -07:00
Andrew G. Morgan
3c7dda330b Up the release version to 2.68
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2023-03-25 17:03:17 -07: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
34b0329dc7 Up the release version to 2.67
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
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
4f96e6788d Up the release version to 2.66
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-09-24 13:37:39 -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
a47d86dfb9 Up the release version to 2.65
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-07-17 15:33:06 -07:00
Andrew G. Morgan
38cfa2e958 Up the release version to 2.64
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2022-04-10 15:39:39 -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
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
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
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
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
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
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
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
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
aca0764435 Make cap_t operations thread safe.
If two threads operate on the same cap_t value, ensure that the
operations occur atomically. (Not, however, reentrantly.)

Also added some sanity checking to cap_set_nsowner() and cap_get_nsowner().

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-10-22 09:58:59 -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
6c0e37a5dc Lower the start up memory allocation overhead.
In the vast majority of cases, code will not need to
override the "/proc" root directory, so treat NULL
as equivalent to "/proc".

Signed-off-by: Andrew G. Morgan <agm@google.com>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-10-01 19:13:36 -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
a3446b5c6e Free _cap_proc_dir on exit.
Credit to yan12125 for finding this bug:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-09-12 19:27:21 -07:00
Andrew G. Morgan
8b3ffc23b6 Fixed parallel make issues
Tried make -j12 and these fixes were needed.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-09-05 20:07:48 -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
David Seifert
2762c2c1a8 Canonicalize build system
* Respect user's CFLAGS/CPPFLAGS/LDFLAGS
* Respect $(MAKE)
* Remove CPPFLAGS from link rules

Note: for in-tree built test binaries, where we build --static,
  we do not apply LDFLAGS: we want to limit external
  dependencies in general; and users' LDFLAGS have a strong
  tendency to conflict with --static for linking.

Work in collaboration with David Seifert (ie, he wrote most of it).

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-09-01 19:17:05 -07:00
Andrew G. Morgan
f5ae31ebd3 Be more consistent with make variables.
Noticed that we weren't applying the same amount of flag discipline
to local BUILD_* tool rules. Fixing that, I see we've been carrying
a source code issue in libcap/_makenames.c for a while. (FIXED).

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-30 20:02:22 -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
6c38eb78d9 Avoid the build server failure.
I figured out that the key ingredient to reproducing this issue
was:

   make COPTS="-D_FORTIFY_SOURCE=2 -O1 -g" clean test

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-28 09:43:51 -07:00
Andrew G. Morgan
43365cf01c Still unclear where cap_test is crashing.
Add more debug logging.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-27 21:01:46 -07:00
Andrew G. Morgan
de1130dbfe Speculative fix for build failure.
Not sure exactly what is causing the build server to fail (can't
reproduce yet), but add some extra padding to a calloc and also
some test debugging printf()s.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-27 13:55:11 -07:00
Andrew G. Morgan
b56400f81d Implement libcap:cap_proc_root() function.
This is needed to locally configure libcap to find the pid data
if the proc filesystem is not mounted at "/proc" (rare). Currently
libcap only uses this info to implement cap_iab_get_pid().

This brings libcap back to parity with the Go "cap" package.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-27 10:27:04 -07:00