26 Commits

Author SHA1 Message Date
Andrew G. Morgan
766527f2b9 Make make run_b219174 dependencies work.
Omitted a dependency before. Now, this works:

$ make distclean
$ cd tests
$ make run_b219174

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-10-26 09:03:40 -07:00
Andrew G. Morgan
12e163ac21 Rewrite libpsx to work with native linux threads.
This is more general than just working with -lpthread threads,
and addresses the following bug reports:

  https://bugzilla.kernel.org/show_bug.cgi?id=219174
  https://bugzilla.kernel.org/show_bug.cgi?id=218607
  https://bugzilla.kernel.org/show_bug.cgi?id=217476

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-10-25 22:58:46 -07:00
Andrew G. Morgan
99799844ad Don't build the tests/binaries until we want to run them
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-09-04 13:26:56 -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
15a3d49bf1 Move $(LDFLAGS) earlier in build command lines.
As explained (thanks David Seifert) there are some LDFLAGS that
need to precede actual linked libraries. For example, -Wl,--as-needed.
Given this, I've tried it and it appears to work for the default
build cases as captured in 'make distcheck'.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-31 19:05:59 -07:00
Andrew G. Morgan
935ab8f7cd Support overriding choice of 'sudo'.
Use something like:

  make SUDO=my_sudo sudotest

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-25 19:48:12 -07:00
Andrew G. Morgan
5647374b33 Revert most of the LDFLAGS -> LDSTATIC change.
The intention was to force --static linking in only one corner case,
so be more explicit about that one, and revert the build behavior
in the others.

Reason for doing this was feedback from Arnout Vandecappelle in:

  https://bugzilla.kernel.org/show_bug.cgi?id=214023#c16

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-23 19:47:38 -07:00
Andrew G. Morgan
d21a561ddb Drop non-standard IPATH in favor of CPPFLAGS.
This also required locally augmenting CFLAGS with -fPIC in the
Makefile's that required it.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-19 20:49:39 -07:00
Andrew G. Morgan
d5daba542a Support distributions that build libcap with aggressive link options.
Discussion of one such setup in this bug (reported by David Runge):

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

Work around the failure to run ./pam_cap.so in these cases with
some more Makefile magic, and adjust test building with these
flags so it works in DYNAMIC=yes|no and SHARED=yes|no cases.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2021-08-13 20:43:14 -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
9b1c003748 Migrate building progs/tcapsh-static to sudotest
This addresses:

  https://bugzilla.kernel.org/show_bug.cgi?id=210135
  https://bugs.busybox.net/show_bug.cgi?id=13296

Some notes on expectations:

When building DYNAMIC=yes folk want to avoid depending on a
static libc.a file in their build tree. The best we can do is
to move building static test tool objects to sudotest.

  make DYNAMIC=yes clean all test

will build the progs binaries and run the tests with all dynamic
linking. It will, however, build the libcap.a etc libraries too
even though they are not used for linking.

  make DYNAMIC=no clean all test

will build the progs binaries and run the tests with all static
linking. It will, however, build the libcap.so etc libraries too
even though they are not used for linking.

  make SHARED=no clean all test

will build and link progs and test binaries statically against
libcap.a. No shared libraries (libcap.so etc) will be built.

In all cases, whether linked against or not, libcap.a is built.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-11-10 20:47:45 -08:00
Andrew G. Morgan
24375fb114 Support systems with no available pthreads support.
This change addresses:

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

Howto:

  make PTHREADS=no ...

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-10-27 20:20:47 -07:00
Andrew G. Morgan
1d03d73625 Lessen the system requirements for running make sudotest
I have one old distribution system that couldn't handle [[ ... ]]
conditions in Makefiles.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-10-25 08:00:24 -07:00
Andrew G. Morgan
481ca7b508 Demonstrate why libpsx is important for multithreaded C code.
I've heard a number of folk ask why one might need libpsx for anything
other than Go program linking, so this demonstrates the class of exploit
that is possible when libcap is linked with -lpthread and not -lpsx.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-10-24 21:00:59 -07:00
Andrew G. Morgan
a614aa669d Fix tests:sudotest for DYNAMIC=yes testing
Actually, fix the libcap_launch_test.c itself since it wasn't correctly
failing with an error exit code before.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-10-18 13:48:09 -07:00
Andrew G. Morgan
6b1d98b7d6 Support shared library build and linkage of -lpsx
For now, the dynamic linkage of libpsx.so* is considered alpha.
The build tree supports it and can successfully run tests but
I'm hopeful I can get some feedback from third parties that it
works as expected.

Feature request:
  https://bugzilla.kernel.org/show_bug.cgi?id=206093

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-10-13 21:35:55 -07:00
Andrew G. Morgan
3e43abc9c7 Be slightly more selective in what to build.
The static build of progs and tests, only needs the .a
libraries to be built.

Bug report from Thomas Petazzoni (trying to get capsh
etc to build against uClibc statically).

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-09-12 08:54:06 -07:00
Andrew G. Morgan
307e7f5744 Support dynamic test compilation and execution.
make DYNAMIC=yes test sudotest

works now. Thomas Petazzoni provided a patch that built
the tests this way, but I've restructured things to
make the above command line work against the uninstalled
library builds.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-09-07 12:53:04 -07:00
Petr Ovtchenkov
40c452c877 no more psx_test_wrap
psx_test_wrap removed in

  commit dca9b22261f4837b0c81640ca3aa5133b95e0999
  Author: Andrew G. Morgan <morgan@kernel.org>
  Date:   Thu Jul 9 19:58:26 2020 -0700

      Rewrite libpsx thread shutdown path to support musl.

      Addresses:

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

      Removed the non-wrapping libpsx macro hacks. The API surface as such
      becomes a little smaller and I now have confidence that wrapping
      pthread_create using the linker options works with Go, gcc and musl
      compilers. I feel it is stable enough to call good to delete the
      workarounds.

Signed-off-by: Petr Ovtchenkov <ptr@void-ptr.info>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-08-05 19:26:42 -07:00
Andrew G. Morgan
dca9b22261 Rewrite libpsx thread shutdown path to support musl.
Addresses:

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

Removed the non-wrapping libpsx macro hacks. The API surface as such
becomes a little smaller and I now have confidence that wrapping
pthread_create using the linker options works with Go, gcc and musl
compilers. I feel it is stable enough to call good to delete the
workarounds.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-07-09 22:33:54 -07:00
Andrew G. Morgan
ef485973d5 Implement cap_launch.
In threaded programs, it's a bit tricky to fork/execve a child with
capabilities different from the parent. Implement cap_launch and
friends to accomplish this.

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-02-23 16:12:12 -08:00
Andrew G. Morgan
51ed0ec9b7 Add support for fork() in libpsx.
When we fork() we disable thread-shared semantics for
the psx_syscall()s of the child, but retain them in the
parent. This change also enhances support for unexpectedly
exiting threads (which seems to be the way Go likes to
terminate pthreads when using cgo linkage).

Enhanced licap_psx_test to fork() from created threads and
exit that thread after the forked child dies. (Ran this
10,000 times to generate confidence no races in libpsx.)

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2020-02-17 13:08:42 -08:00
Andrew G. Morgan
dada271ca4 Break out test into two parts: test or sudotest.
The latter will invoke tests with sudo. Not all builds
can support this, but we do need a convenient way
to test this stuff...

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2019-12-15 10:52:55 -08:00
Andrew G. Morgan
2b5f5635be Restructure the make files into build vs. test
Also install the Go packages if built.

Remove a default behavior of installing an inheritable bit on setcap.
I'm getting alarmed that some distributions are setting the inheritable
set to full for all users. So, I don't want to provide a vector for
a trivial exploit, and hope they are not reinventing this:

https://sites.google.com/site/fullycapable/Home/thesendmailcapabilitiesissue

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2019-12-13 17:30:23 -08:00
Andrew G. Morgan
b2b267ef1c Add support to libcap for overriding system call functions.
Note, this override only supports the system calls that
libcap uses to change kernel state associated with the
current process. This is primarily intended to permit the
user to use libpsx to force all pthreads to mirror capability
and other security relevant state.

Use a weak function definition feature of libpsx share_psx_syscall()
to transparently arrange for libcap to so force itself to use the
psx_syscall() abstraction when linked against -lpsx. This has the
effect of using linker magic to make libcap transparently observe
POSIX semantics for security state setting operations. That is, when
linked as follows:

   gcc .... -lcap -lpsx -lpthread -Wl,-wrap,pthread_create

all pthreads maintain a common security state with respect to the
libcap API.

This also adds full capability setting support to the Go package
libcap/cap via a libcap/psx package which uses cgo+libpsx syscalls
that share capabilities over all pthreads including those of the
Go runtime.

Finally, if Go supports syscall.PosixSyscall() etc. then provide
a non-psx mechanism for libcap/cap to "just work" in all Go code.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2019-12-06 23:06:47 -08:00
Andrew G. Morgan
e9f55d90e4 Implement a helper library for POSIX semantics syscalls.
Since Linux kernel supported threads are not POSIX threads
and the glibc pthread library only supports POSIX semantics
for 9 system calls, to fully support the POSIX semantics for
a process sharing its security state across all of its
threads, we've created libpsx.

This commit also includes a threading test in tests/ for
this new psx_syscall() abstraction - one that transparently
mirrors calling POSIX-needing semantics syscalls over
all running threads.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2019-12-05 21:14:47 -08:00