libcap: adding ptests
cover libcap: adding ptests
This patch series adds ptest support for the libcap package and addresses a bug in one of the upstream tests.
The changes enable running a subset of the upstream libcap test suite as ptests, and address a bug in libcap_psx_test related to exit handling that causes the ptests to hang.
Kris Gavvala (2):
libcap: add ptest support
libcap: fix hang in libcap psx_test
.../distro/include/ptest-packagelists.inc | 1 + ...1-libcap-fix-hang-in-libcap_psx_test.patch | 47 +++++++++++++++++++ meta/recipes-support/libcap/files/run-ptest | 25 ++++++++++ meta/recipes-support/libcap/libcap_2.78.bb | 44 ++++++++++++++++- 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 meta/recipes-support/libcap/files/0001-libcap-fix-hang-in-libcap_psx_test.patch create mode 100644 meta/recipes-support/libcap/files/run-ptest
Signature · 1 line
2.49.0
PATCH 1/2 libcap: add ptest support
This ptest implementation includes a subset of upstream tests that provide functional coverage of core libcap and libpsx behavior across target systems.
This approach is preferred instead of using libcap's quicktest.sh script because the later assumes the upstream build-tree layout and has too many dependencies not available after installation. Quicktest exercises a wide range of kernel capability features and environment-specific functionality that is too comprehensive for ptests.
The ptests include the following libcap/tests executables:uns_test, psx_test, libcap_psx_test, libcap_launch_test, and exploit/noexploit. cap_test from libcap/libcap is also included.
These provide coverage for capability manipulation, libpsx integration, launch handling, and basic security validation.
--- .../distro/include/ptest-packagelists.inc | 1 + meta/recipes-support/libcap/files/run-ptest | 25 +++++++++++ meta/recipes-support/libcap/libcap_2.78.bb | 43 ++++++++++++++++++- 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 meta/recipes-support/libcap/files/run-ptest
meta/conf/distro/include/ptest-packagelists.inc +1 -0
@@ -31,6 +31,7 @@ PTESTS_FAST = "\ libarchive \ libassuan \ libatomic-ops \ + libcap \ libcheck \ libconfig \ libconvert-asn1-perl \
meta/recipes-support/libcap/files/run-ptest new file +25 -0
@@ -0,0 +1,25 @@ +#!/bin/sh + +EXPECT_FAIL=1 +EXPECT_PASS=0 + +cd tests || exit + +for t in uns_test psx_test libcap_psx_test libcap_launch_test cap_test exploit noexploit; do + output=$("./$t" 2>&1 ) + status=$? + + expected="$EXPECT_PASS" + + if [ $t = 'exploit' ]; then + expected="$EXPECT_FAIL" + fi + + if [ "$status" -eq "$expected" ]; then + echo "PASS: $t" + else + echo "FAIL: $t" + echo "$output" + fi +done +
meta/recipes-support/libcap/libcap_2.78.bb +42 -1
59 lines not on this page · raw message
Signature · 1 line
2.49.0
PATCH 2/2 libcap: fix hang in libcap psx_test
In reply to Kris GavvalaThis adresses a bug in libcap_psx_test, one of the ptests. libcap_psx_test checks that capability state remains consistent when concurrent changes to process capability state are made across multiple threads that each perform a fork().
libcap_psx_test outputs that it passed, but leaves
a child process in an S state after executing. A fix was found by changing the exit() in a child process to _exit, avoiding the exit handlers that were causing the deadlock.
--- ...1-libcap-fix-hang-in-libcap_psx_test.patch | 47 +++++++++++++++++++ meta/recipes-support/libcap/libcap_2.78.bb | 1 + 2 files changed, 48 insertions(+) create mode 100644 meta/recipes-support/libcap/files/0001-libcap-fix-hang-in-libcap_psx_test.patch
meta/recipes-support/libcap/files/0001-libcap-fix-hang-in-libcap_psx_test.patch new file +47 -0
@@ -0,0 +1,47 @@ +From a51273125b90157de70ae2615a91f82c1775615b Mon Sep 17 00:00:00 2001 +From: Kris Gavvala <[email protected]> +Date: Fri, 12 Jun 2026 14:55:11 -0700 +Subject: [PATCH] libcap: fix hang in libcap_psx_test + +When running libcap_psx_test on some non-x86-64 targets, a hang occurs. +In thread_fork_exit(), the forked child calls exit(0), which invokes exit +handlers and blocks waiting for an internal lock. + +Use of exit() is unsafe in a forked child of a multithreaded process because +of the internal handlers that can causing blocking. + +This commit replaces exit() with _exit() in the child to bypass +exit handling and prevent a deadlock from occuring. + +Signed-off-by: Kris Gavvala <[email protected]> +Upstream-Status: Submitted [[email protected]] +Upstream tracking: [https://github.com/AndrewGMorgan/libcap_mirror/issues/12#issue-4652587116] + +--- + tests/libcap_psx_test.c | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +diff --git a/tests/libcap_psx_test.c b/tests/libcap_psx_test.c +index 58a13ec..693aeb5 100644 +--- a/tests/libcap_psx_test.c ++++ b/tests/libcap_psx_test.c +@@ -24,13 +24,13 @@ static void *thread_fork_exit(void *data) { + if (pid == 0) { + if (cap_prctlw(PR_SET_KEEPCAPS, !start, 0, 0, 0, 0) != 0) { + perror("failed to set proc"); +- exit(1); ++ _exit(1); + } + if (cap_prctlw(PR_GET_KEEPCAPS, 0, 0, 0, 0, 0) == start) { + perror("failed to have set forked proc"); +- exit(1); ++ _exit(1); + } +- exit(0); ++ _exit(0); + } + int res; + if (waitpid(pid, &res, 0) != pid || res != 0) { +-- +2.49.0 +
meta/recipes-support/libcap/libcap_2.78.bb +1 -0
@@ -18,6 +18,7 @@ SRC_URI:append:class-nativesdk = " \ " SRC_URI:append = " \ file://run-ptest \ + file://0001-libcap-fix-hang-in-libcap_psx_test.patch \ " SRC_URI[sha256sum] = "0d621e562fd932ccf67b9660fb018e468a683d7b827541df27813228c996bb11"
Signature · 1 line
2.49.0
Quoted 11 lines · Kris via lists.openembedded.org Gavvala
This patch series adds ptest support for the libcap package and addresses a bug in one of the upstream tests.
The changes enable running a subset of the upstream libcap test suite as ptests, and address a bug in
libcap_psx_testrelated to exit handling that causes the ptests to hang.Kris Gavvala (2):
libcap: add ptest support
libcap: fix hang in libcappsx_test
Hi Kris,
Thanks for your patch.
It looks like some ptest is failing:
AssertionError:
Failed ptests:
{'libcap': ['libcap_launch_test']}
https://autobuilder.yoctoproject.org/valkyrie/#/builders/61/builds/3820
https://autobuilder.yoctoproject.org/valkyrie/#/builders/73/builds/3838
https://autobuilder.yoctoproject.org/valkyrie/#/builders/110/builds/542
Can you have a look at the issue?
Thanks,
Mathieu
Signature · 3 lines
Mathieu Dubois-Briand, Bootlin Embedded Linux and Kernel engineering https://bootlin.com