Skip to content

Commit 2d82d5e

Browse files
rossburtonrpurdie
authored andcommitted
acl: improve ptest packaging
As there's a small number of test binaries in acl, instead of installing large chunks of the build tree we can install just those and use a boilerplate test runner. Drop 0001-tests-do-not-hardcode-the-build-path-into-a-helper-l.patch and replace with an explicit -DBASEDIR= flag passed at build time. Drop 0001-test-patch-out-failing-bits.patch and delete the tests that fail entirely as they won't work without a specific user/group setup. Backport a patch from upstream so that some tests don't use excessive amounts of memory. Backport a patch from upstream to cater for both glibc and musl's behaviour with interleaved stdout/stderr, fixing the tests on musl. Clean up dependencies now that we're not shipping the build system. Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
1 parent bf5c880 commit 2d82d5e

6 files changed

+135
-137
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
From 56abe432b65801f31277fb9a3bca0f9e31502315 Mon Sep 17 00:00:00 2001
2+
From: Matthias Gerstner <matthias.gerstner@suse.de>
3+
Date: Thu, 25 Apr 2024 12:43:49 +0200
4+
Subject: [PATCH] libmisc: __acl_get_uid(): fix memory wasting loop if user
5+
does not exist
6+
7+
I noticed that `acl_from_text()` unexpectedly returns ENOMEM for invalid
8+
user names. The reason for this is a missing break statement in the for
9+
loop in `__acl_get_uid()`, which causes the loop to act as if ERANGE was
10+
returned from `getpwnam_r()`, thereby exponentially increasing the
11+
buffer size to (in my case) multiple gigabytes, until `grow_buffer()`
12+
reports ENOMEM, which terminates the `__acl_get_uid()` function.
13+
14+
This is a pretty costly "no such user" lookup that can disturb a
15+
process's heap memory management, but can also cause a process to fail
16+
e.g. if it is multithreaded and other threads encounter an ENOMEM,
17+
before `__acl_get_uid()` frees the gigantic heap buffer and returns.
18+
The allocated memory isn't actually used. Therefore on Linux it should
19+
not affect other processes by default, due to its overcommit memory
20+
and lazy memory allocation strategy.
21+
22+
Fix this by properly terminating the for loop on any conditions except
23+
an ERANGE error being reported. The same break statement correctly
24+
exists in `__acl_get_gid()` already.
25+
26+
Fixes: 3737f00 ("use thread-safe getpwnam_r and getgrnam_r")
27+
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
28+
29+
Upstream-Status: Backport
30+
Signed-off-by: Ross Burton <ross.burton@arm.com>
31+
---
32+
libmisc/uid_gid_lookup.c | 1 +
33+
1 file changed, 1 insertion(+)
34+
35+
diff --git a/libmisc/uid_gid_lookup.c b/libmisc/uid_gid_lookup.c
36+
index a4f21f6..74baab4 100644
37+
--- a/libmisc/uid_gid_lookup.c
38+
+++ b/libmisc/uid_gid_lookup.c
39+
@@ -91,6 +91,7 @@ __acl_get_uid(const char *token, uid_t *uid_p)
40+
if (err == ERANGE)
41+
continue;
42+
errno = err ? err : EINVAL;
43+
+ break;
44+
}
45+
free(buffer);
46+
return result ? 0 : -1;
47+
--
48+
2.43.0
49+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
From 47f8039ec9bd08b629775c8e788d11e41fa95f14 Mon Sep 17 00:00:00 2001
2+
From: Andreas Gruenbacher <agruenba@redhat.com>
3+
Date: Mon, 24 Mar 2025 21:14:09 +0100
4+
Subject: [PATCH] test/misc.test: Don't mix stdout and stderr
5+
6+
In different environments, we may not get the stdout and stderr output
7+
in the order the run script expects, so check both separately.
8+
9+
Fixes: https://savannah.nongnu.org/bugs/?66944
10+
Signed-off-by: Andreas Gruenbacher <agruenba@redhat.com>
11+
12+
Upstream-Status: Backport
13+
Signed-off-by: Ross Burton <ross.burton@arm.com>
14+
---
15+
test/misc.test | 3 ++-
16+
1 file changed, 2 insertions(+), 1 deletion(-)
17+
18+
diff --git a/test/misc.test b/test/misc.test
19+
index 06b3136..57c02e5 100644
20+
--- a/test/misc.test
21+
+++ b/test/misc.test
22+
@@ -440,8 +440,9 @@ Dangling symlink test https://savannah.nongnu.org/bugs/?28131
23+
> other::r-x
24+
>
25+
$ setfacl -R -m u:bin:rw d
26+
- $ getfacl -RL d
27+
+ $ getfacl -RL d > /dev/null
28+
> getfacl: d/b: No such file or directory
29+
+ $ getfacl -RL d 2> /dev/null
30+
> # file: d
31+
> # owner: %TUSER
32+
> # group: %TGROUP
33+
--
34+
2.43.0
35+

meta/recipes-support/attr/acl/0001-test-patch-out-failing-bits.patch

Lines changed: 0 additions & 60 deletions
This file was deleted.

meta/recipes-support/attr/acl/0001-tests-do-not-hardcode-the-build-path-into-a-helper-l.patch

Lines changed: 0 additions & 24 deletions
This file was deleted.

meta/recipes-support/attr/acl/run-ptest

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
#!/bin/sh
2-
#
3-
#This script is used to run acl test suites
42

5-
#umask 077
3+
failed=0
4+
all=0
65

7-
mkdir -p /tmp/acl-ptest/test
8-
cp test/test.* /tmp/acl-ptest/test
96

10-
set +e
11-
make test-suite.log
12-
exitcode=$?
13-
if [ $exitcode -ne 0 -a -e test-suite.log ]; then
14-
cat test-suite.log
7+
for f in *.test; do
8+
LD_PRELOAD=$(pwd)/libtestlookup.so ./run $f
9+
case "$?" in
10+
0)
11+
echo "PASS: $f"
12+
all=$((all + 1))
13+
;;
14+
77)
15+
echo "SKIP: $f"
16+
;;
17+
*)
18+
echo "FAIL: $f"
19+
failed=$((failed + 1))
20+
all=$((all + 1))
21+
;;
22+
esac
23+
done
24+
25+
if [ "$failed" -eq 0 ] ; then
26+
echo "All $all tests passed"
27+
exit 0
28+
else
29+
echo "$failed of $all tests failed"
30+
exit 1
1531
fi
16-
exit $exitcode

meta/recipes-support/attr/acl_2.3.2.bb

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ LIC_FILES_CHKSUM = "file://doc/COPYING;md5=c781d70ed2b4d48995b790403217a249 \
1616
DEPENDS = "attr"
1717

1818
SRC_URI = "${SAVANNAH_GNU_MIRROR}/acl/${BP}.tar.gz \
19+
file://0001-libmisc-__acl_get_uid-fix-memory-wasting-loop-if-use.patch \
20+
file://0001-test-misc.test-Don-t-mix-stdout-and-stderr.patch \
1921
file://run-ptest \
20-
file://0001-tests-do-not-hardcode-the-build-path-into-a-helper-l.patch \
21-
file://0001-test-patch-out-failing-bits.patch \
2222
"
23-
2423
SRC_URI[sha256sum] = "5f2bdbad629707aa7d85c623f994aa8a1d2dec55a73de5205bac0bf6058a2f7c"
2524

2625
inherit autotools gettext ptest
@@ -31,57 +30,41 @@ PACKAGES =+ "lib${BPN}"
3130

3231
FILES:lib${BPN} = "${libdir}/lib*${SOLIBS}"
3332

34-
PTEST_BUILD_HOST_FILES = "builddefs"
35-
PTEST_BUILD_HOST_PATTERN = "^RPM"
36-
3733
do_compile_ptest() {
38-
oe_runmake libtestlookup.la
34+
oe_runmake libtestlookup.la libtestlookup_la_CFLAGS=-DBASEDIR=\\\"${PTEST_PATH}\\\"
3935
}
4036

4137
do_install_ptest() {
42-
cp -rf ${S}/test/ ${D}${PTEST_PATH}
43-
cp -rf ${S}/build-aux/ ${D}${PTEST_PATH}
44-
mkdir -p ${D}${PTEST_PATH}/.libs
45-
cp -rf ${B}/.libs/libtestlookup* ${D}${PTEST_PATH}/.libs
46-
cp ${B}/Makefile ${D}${PTEST_PATH}
47-
48-
sed -e 's,--sysroot=${STAGING_DIR_TARGET},,g' \
49-
-e 's|${DEBUG_PREFIX_MAP}||g' \
50-
-e 's:${HOSTTOOLS_DIR}/::g' \
51-
-e 's:${RECIPE_SYSROOT_NATIVE}::g' \
52-
-e 's:${BASE_WORKDIR}/${MULTIMACH_TARGET_SYS}::g' \
53-
-i ${D}${PTEST_PATH}/Makefile
54-
55-
sed -e "s|^srcdir =.*|srcdir = .|" \
56-
-e "s|^abs_srcdir =.*|abs_srcdir = .|" \
57-
-e "s|^abs_top_srcdir =.*|abs_top_srcdir = ..|" \
58-
-e "s|^Makefile:.*|Makefile:|" \
59-
-e "/^TEST_LOG_DRIVER =/s|(top_srcdir)|(top_builddir)|" \
60-
-i ${D}${PTEST_PATH}/Makefile
61-
62-
rm ${D}${PTEST_PATH}/.libs/libtestlookup.lai
63-
}
64-
65-
do_install_ptest:append:libc-musl() {
66-
sed -i -e '/test\/misc.test/d' ${D}${PTEST_PATH}/Makefile
38+
install -m755 ${S}/test/run ${S}/test/sort-getfacl-output ${D}${PTEST_PATH}/
39+
install -m644 ${S}/test/*.acl ${D}${PTEST_PATH}/
40+
41+
# Install the tests
42+
for t in $(makefile-getvar ${S}/test/Makemodule.am TESTS); do
43+
install -m644 ${S}/$t ${D}${PTEST_PATH}/
44+
done
45+
# Remove the tests that are expected to fail (they need a NFS server configured)
46+
for t in $(makefile-getvar ${S}/test/Makemodule.am XFAIL_TESTS); do
47+
rm ${D}${PTEST_PATH}/$(basename $t)
48+
done
49+
# These tests need a very specific user/group setup
50+
# (https://savannah.nongnu.org/bugs/index.php?66927)
51+
rm -f ${D}${PTEST_PATH}/getfacl.test ${D}${PTEST_PATH}/permissions.test ${D}${PTEST_PATH}/restore.test ${D}${PTEST_PATH}/setfacl.test
52+
53+
${B}/libtool --mode=install install ${B}/libtestlookup.la ${D}${PTEST_PATH}/
54+
rm -f ${D}${PTEST_PATH}/*.la
55+
install -d ${D}${PTEST_PATH}/test
56+
install -m644 ${S}/test/test.passwd ${S}/test/test.group ${D}${PTEST_PATH}/test
6757
}
6858

6959
RDEPENDS:${PN}-ptest = "acl \
70-
bash \
7160
coreutils \
7261
perl \
73-
perl-module-constant \
74-
perl-module-filehandle \
75-
perl-module-getopt-std \
76-
perl-module-posix \
77-
shadow \
78-
make \
79-
gawk \
80-
e2fsprogs-mke2fs \
8162
perl-module-cwd \
8263
perl-module-file-basename \
8364
perl-module-file-path \
84-
perl-module-file-spec \
65+
perl-module-filehandle \
66+
perl-module-getopt-std \
67+
perl-module-posix \
8568
"
8669

8770
BBCLASSEXTEND = "native nativesdk"

0 commit comments

Comments
 (0)