767 Commits

Author SHA1 Message Date
Andrew G. Morgan
542d7d86ec Revert "libcap: Add build ldflags to _makenames rule"
This reverts commit c3ddf45d9afaab85d3b7db0dc7bfd1aafb8fde50.

The details of what this broke are here:

  https://bugzilla.kernel.org/show_bug.cgi?id=220691#c2

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-11-10 18:26:34 -08:00
Will Fancher
d628b3bfe4 Do not cross compile mknames.go
`GOOS` and `GOARCH` can be set to cross compile the Go code. But
`good-names.go` is generated at build time using `mknames.go`, which
must be built for the build platform. `GOOS` and `GOARCH` can be unset
to do this. In many circumstances, Go will use its own internal linker
to build the binary, which means it won't need to use `$CC`. But in
some scenarios, e.g. when building PIE binaries, it will use `$CC` as
the linker, so this needs to be set to the build platform's compiler
for `go run`.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-11-10 18:21:52 -08:00
Andrew G. Morgan
3b2513a1ba Up the release version to 2.77
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
cap/v1.2.77 psx/v1.2.77 libcap-2.77 libcap-korg-2.77 v1.2.77 sig-libcap-2.77
2025-10-26 11:29:03 -07:00
Khem Raj
c3ddf45d9a libcap: Add build ldflags to _makenames rule
its calling compiler and linker in single step
ensure that build ldflags are respected as it
might have important information like which runtime
to use.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-10-21 19:20:31 -07:00
Chris Hofer
2d744fbaa4 libcap: Improve raw container calculation
On architectures with pointer alignment constraints larger than 8
bytes, e.g. CHERI RISC-V, a raw container calculation in libcap
results in invalid read accesses to members or memory corruption.
Fix this by taking the alignment constraints into account as well
as asserting the memory layout of the container struct.

For capability allocation, libcap uses the struct:
	struct _cap_alloc_s {
	    __u32 magic;
	    __u32 size;
	    union {
		...
    	    } u;
	};

where the union abstracts several capability types that can be
identified by _cap_alloc_s' magic member. To obtain a pointer to the
allocation struct from a pointer to the union, the following
expression is used:
	struct _cap_alloc_s *p = (void *) (-2 + (__u32 *) union_ptr);

This calculation relies on the assumption that the union is placed at an
offset of 8 bytes in the allocation struct. However, some struct types
that are in the union may have pionters and thus, these structs may have
larger alignment constraints on architectures with fat pointers, e.g.
16-byte alignment on CHERI RISC-V. In these cases, the offset may be
larger than 8 bytes and the raw container calculation results in an
invalid pointer that is dereferenced.

Fix the caluculation by using the alignment constraint of the union if
it exceeds the size of the two preceeding 32-bit uints magic and size.
Statically assert that the so calculated offset matches the actual
offset of u in _cap_alloc_s.

Signed-off-by: Chris Hofer <christian.hofer@codasip.com>

Added compilation fix for -std=c99 compilation, and suppressed
newly introduced warnings from clang.

Resolves:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-08-10 13:14:34 -07:00
Garret Kelly
da06dc98d2 Fix bug in IABGetPID
Using NewIAB ensures that common startup initialization happens before trying
to use `words`. Also switch to using IAB.good to determine if the parsed IAB
is valid.

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

Signed-off-by: Garret Kelly <gkelly@gkel.ly>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-08-06 06:22:35 -07:00
Ariel Otilibili
a37b302883 Make.Rules: Fix broken link to the sendmail issue
The link points to a dead resource.

Replace it with the correct link.

Signed-off-by: Ariel Otilibili <ariel.otilibili-anieli@eurecom.fr>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-07-07 07:09:18 -07:00
Andrew G. Morgan
a5753d0291 Fix bugs in setcap.c error strings.
Multi-year bug displaying the wrong filename when failing
to set a capability on a file.

Thanks to Nikolas for reporting this:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-06-18 06:18:32 -07:00
Andrew G. Morgan
53b369b8ea Make the kdebug test use the terminal output.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-05-06 23:17:09 -07:00
Andrew G. Morgan
9a84906efe Add some C++ protection to the libcap/execable.* code.
These ideas were what I shared in this answer:

  https://stackoverflow.com/a/68339111/14760867

so I figure I might as well capture them here. Credit goes to the stackoverflow user, "Haydentech", for running
into the issue and prompting me to figure out the issue.

All that being said, within the libcap build sources, is not completely
clear when the __cplusplus support would be invoked.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-05-05 19:46:47 -07:00
Andrew G. Morgan
6cdd8cd72e Support for __xtensa__ architecture.
It looks like __xtensa__ defines SA_RESTORER, but my read of the
kernel code suggests that signal handling does not require it be
set. Specifically, if the SA_RESTORER flag is not set, the kernel
inserts a sys_rt_sigreturn call into the stack frame.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-04-19 08:00:23 -07:00
Andrew G. Morgan
7a2eee5660 First attempt at PSX support for microblaze, arc and openrisc.
I found some confusing macrology for openrisc. I'm optimistic that
this is recognized with the __or1k__ gcc macro.

See for details:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-04-17 20:20:09 -07:00
Andrew G. Morgan
5f3e12ca39 Up the release version to 2.76
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
libcap-korg-2.76 psx/v1.2.76 v1.2.76 cap/v1.2.76 libcap-2.76 sig-libcap-2.76
2025-04-13 09:47:12 -07:00
Andrew G. Morgan
8ff33c7ffd Drop example workaround for go.dev execution.
The go.dev website was previously overzealous in rejecting source
code when preparing examples. This has now been fixed. See

  https://github.com/golang/go/issues/70611
  https://github.com/golang/go/issues/70630

for prior behavior.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
cap/v1.2.76-rc4
2025-04-13 08:48:40 -07:00
Andrew G. Morgan
07d8ce731d Be more systematic using the kernel signal handler APIs.
Each architecture seems to have its own nuance. Found a way
to get the kernel header compilation to confirm what sigaction
structure is expected by the kernel. This made a few differences
and I am hoping it addresses why the alpha build fails with
debian's sid compile. It makes some changes to memory reservation
for other architectures, arm64 (aka aarch64) in particular.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
psx/v1.2.76-rc1
2025-03-29 08:01:03 -07:00
Andrew G. Morgan
f0e4f395e0 Make example more friendly with a Makefile.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-28 20:42:10 -07:00
Andrew G. Morgan
bbd88328b2 Extend support further to __m68k__ and possibly __sparc__.
This may include a needed fix for __sh__ too.

I don't have any test machines for this, so this code change
is untested, and based solely on reading kernel etc. sources.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-23 07:54:48 -07:00
Andrew G. Morgan
89b0e7a69a Add support for some less mainstream architectures.
These (__alpha__, __hppa__, __sh__) don't have the SA_RESTORER
complication, so hopefully can "just work". I'm relying on Debian's
build servers to confirm.

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-23 06:30:29 -07:00
Andrew G. Morgan
04b285680b Glibc needs a constant to be defined for puts() to work.
See https://bugzilla.kernel.org/show_bug.cgi?id=219880

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-22 09:49:50 -07:00
Andrew G. Morgan
cedefd8e93 Delete a debugging printf in setcap.
Oops.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-22 09:37:42 -07:00
Andrew G. Morgan
91e3124a29 More useful cross linking for man pages.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-19 20:17:01 -07:00
Andrew G. Morgan
087afa007d Break out description of text formats to a separate man page.
See cap_text_formats(7). This is the 2nd time this breakout has been
requested. This time by way of Carlos Rodriguez-Fernandez.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-19 20:01:48 -07:00
Andrew G. Morgan
4425764d96 Nothing references the SYSTEM_HEADERS make variable.
It was introduced between libcap-1.97 and libcap-2.00 but never
actually referenced in the build tree. Thanks to Ross Burton for
pointing this out!

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-17 19:25:46 -07:00
Andrew G. Morgan
824333d997 Some more runnable documentation examples.
All examples so far:

https://pkg.go.dev/kernel.org/pub/linux/libs/security/libcap/cap@v1.2.76-rc3#pkg-examples

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
cap/v1.2.76-rc3
2025-03-08 15:44:04 -08:00
Andrew G. Morgan
fc8a50743b Delete one cap package example that fails and add two more.
The cap.GetMode() example causes an exception on go.dev, likely because of some
system call blocking, on the website.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
cap/v1.2.76-rc2
2025-03-06 09:29:39 -08:00
Andrew G. Morgan
1b436ee55e Add more live examples to the cap package documentation.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
cap/v1.2.76-rc1
2025-03-05 18:55:04 -08:00
Andrew G. Morgan
f02e46a44a Up the release version to 2.75
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
cap/v1.2.75 v1.2.75 psx/v1.2.75 libcap-korg-2.75 libcap-2.75 sig-libcap-2.75
2025-03-04 08:56:39 -08:00
Andrew G. Morgan
fb2dede6e7 Fix psx module build.
Thanks to Frank for promptly reporting this:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
psx/v1.2.75-rc1
2025-03-03 19:08:28 -08:00
Andrew G. Morgan
def8fab2a3 Up the release version to 2.74
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
cap/v1.2.74 psx/v1.2.74 libcap-2.74 libcap-korg-2.74 v1.2.74 sig-libcap-2.74
2025-03-02 16:09:34 -08:00
Andrew G. Morgan
805a6d3b3f Trim the examples for the cap package.
Added a couple of examples for lesser used functions: cap.Import()
and (*cap.Set) Export().

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-02 15:59:14 -08:00
Andrew G. Morgan
7be690ed8c Improve weaver test to count zeros vs '-1' values.
This isn't fixing a known issue, but more preparing for a potential
PSX mechanism error.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-02 14:24:25 -08:00
Andrew G. Morgan
4b1d6d6332 Compile with -std=c89 option.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-02 11:46:52 -08:00
Andrew G. Morgan
20c22e64bf Be consistent about using SA_RESTORER.
Found this omission via CC=musl-gcc build test (in make distcheck).

Last(?) fix for:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-02 10:46:34 -08:00
Andrew G. Morgan
b5b2e011a7 Drop linux/ headers for standard ones.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-02 10:25:00 -08:00
Andrew G. Morgan
7a7982067e Churn test should work with or without cgo.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
psx/v1.2.74-rc6 cap/v1.2.74-rc6
2025-03-02 10:10:47 -08:00
Andrew G. Morgan
d510712a27 Clean up go documentation.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-03-02 10:02:45 -08:00
Andrew G. Morgan
dfb0fc263b Add riscv support for the psx mechanism.
This adds `__riscv` (curiously, gcc does not define `__riscv__`) psx
compilation support.

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

Also, add explicit __x86_64__ compilation support. It was working
implicitly, but change to be consistent.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
cap/v1.2.74-rc5 psx/v1.2.74-rc5
2025-02-22 11:36:48 -08:00
Leo
cf8d9ad3ec Fix reliance on transitive include.
kill(2) is declared in signal.h, however previously this header was not
included. It happened to work on glibc, where sys/wait.h includes
signal.h, this is however not required behavior in the POSIX standard:

> Inclusion of the <sys/wait.h> header may also make visible all symbols
> from <signal.h> and <sys/resource.h>.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-02-19 19:19:59 -08:00
Andrew G. Morgan
47f119fff3 Fix error when expanding hash map.
The code was using `hval` when it should have used `mix`. I've removed
`hval` from the code now. This fixes this bug:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
cap/v1.2.74-rc4 psx/v1.2.74-rc4
2025-02-17 21:43:26 -08:00
Andrew G. Morgan
c32a4d372f Add s390x support for new PSX mechanism.
As per this bug report:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-02-17 21:42:20 -08:00
Andrew G. Morgan
fc336e9794 Add a test for bad group prefix.
The previous commit fixed a bug with the config parsing in pam_cap.
This is a test that we don't regress against that fix.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-02-16 20:17:08 -08:00
Tianjia Zhang
1ad42b66c3 pam_cap: Fix potential configuration parsing error
The current configuration parsing does not actually skip user names
that do not start with @, but instead treats the name as a group
name for further parsing, which can result in matching unexpected
capability sets and may trigger potential security issues.  Only
names starting with @ should be parsed as group names.

Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-02-16 20:12:47 -08:00
Andrew G. Morgan
9c46e11a46 Add PowerPC support for latest PSX implementation.
See:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
cap/v1.2.74-rc3 psx/v1.2.74-rc3
2025-02-16 16:20:55 -08:00
Andrew G. Morgan
aabdd103bb Mention CAP_MODE_HYBRID in man page.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
psx/v1.2.74-rc2 cap/v1.2.74-rc2
2025-02-16 10:26:58 -08:00
Tianjia Zhang
d7b41e480d doc: Fix typo of cap_cap_proc
Signed-off-by: Tianjia Zhang <tianjia.zhang@linux.alibaba.com>
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-02-16 10:21:31 -08:00
Andrew G. Morgan
5a9f9dde6c Add mips support for refactor of psx.
Mips bugfix:

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

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2025-02-15 15:00:28 -08:00
Andrew G. Morgan
025f28ca4f Avoid thread churn deadlock with PSX rewrite.
This bug, reported by David Runge, identifies another regression
vs. libpsx-2.71:

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

A regression of the LWP threading support reintroduced an old bug
in the libpsx-2.72 rewrite, specifically this bug:

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

This present change includes x86_64, i386 and arm* (32-bit and 64-bit)
support. I've tested each of these with debian OSes, some running via QEMU.
Before releasing 2.74, I plan to extend the testing to all of the targets
supported by Debian (see https://wiki.debian.org/DebianInstaller/Qemu).

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
psx/v1.2.74-rc1
2025-02-01 08:49:27 -08:00
Andrew G. Morgan
2dda39e0e3 The go.dev site is unable to render this example.
As a workaround for the golang bug: 70630, specifically comment
70630#issuecomment-2513491664 provide an alias for the package.
Perhaps, at some point, that bug or the one it is duped into will
be fixed, and we can remove this workaround.

Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-12-26 19:26:54 -08:00
Andrew G. Morgan
6ef6a9d1e4 Up the release version to 2.73
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
cap/v1.2.73 libcap-2.73 v1.2.73 psx/v1.2.73 libcap-korg-2.73 sig-libcap-2.73
2024-12-01 20:18:58 -08:00
Andrew G. Morgan
f6d4cb050c _GNU_SOURCE #define needed in psx.c to build -std=c99.
Signed-off-by: Andrew G. Morgan <morgan@kernel.org>
2024-11-28 09:36:27 -08:00