lists.linaro.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2025
April
March
February
January
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
List overview
Download
Linux-kselftest-mirror
September 2024
----- 2025 -----
April 2025
March 2025
February 2025
January 2025
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
linux-kselftest-mirror@lists.linaro.org
255 participants
325 discussions
Start a n
N
ew thread
[PATCH] clone3: clone3_cap_checkpoint_restore: remove unused MAX_PID_NS_LEVEL macro
by Ba Jing
The macro MAX_PID_NS_LEVEL is never referenced in the code, so remove it. Signed-off-by: Ba Jing <bajing(a)cmss.chinamobile.com> --- tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c b/tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c index 31b56d625655..3c196fa86c99 100644 --- a/tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c +++ b/tools/testing/selftests/clone3/clone3_cap_checkpoint_restore.c @@ -27,8 +27,6 @@ #include "../kselftest_harness.h" #include "clone3_selftests.h" -#define MAX_PID_NS_LEVEL 32 - static void child_exit(int ret) { fflush(stdout); -- 2.33.0
7 months
3
2
0
0
[PATCH] memfd: fuse_mnt: remove unused macro
by Ba Jing
The macro FUSE_USE_VERSION is never referenced in the code, just remove it. Signed-off-by: Ba Jing <bajing(a)cmss.chinamobile.com> --- tools/testing/selftests/memfd/fuse_mnt.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/testing/selftests/memfd/fuse_mnt.c b/tools/testing/selftests/memfd/fuse_mnt.c index 6936f2a001f3..f9f06fd43c5f 100644 --- a/tools/testing/selftests/memfd/fuse_mnt.c +++ b/tools/testing/selftests/memfd/fuse_mnt.c @@ -12,8 +12,6 @@ * file-system. */ -#define FUSE_USE_VERSION 26 - #include <fuse.h> #include <stdio.h> #include <string.h> -- 2.33.0
7 months
3
2
0
0
[PATCH AUTOSEL 6.6 071/139] selftests/nolibc: avoid passing NULL to printf("%s")
by Sasha Levin
From: Thomas Weißschuh <linux(a)weissschuh.net> [ Upstream commit f1a58f61d88642ae1e6e97e9d72d73bc70a93cb8 ] Clang on higher optimization levels detects that NULL is passed to printf("%s") and warns about it. While printf() from nolibc gracefully handles that NULL, it is undefined behavior as per POSIX, so the warning is reasonable. Avoid the warning by transforming NULL into a non-NULL placeholder. Reviewed-by: Shuah Khan <skhan(a)linuxfoundation.org> Acked-by: Willy Tarreau <w(a)1wt.eu> Link:
https://lore.kernel.org/r/20240807-nolibc-llvm-v2-8-c20f2f5fc7c2@weissschuh…
Signed-off-by: Thomas Weißschuh <linux(a)weissschuh.net> Signed-off-by: Sasha Levin <sashal(a)kernel.org> --- tools/testing/selftests/nolibc/nolibc-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 1fc4998f06bf6..4aaafbfc2f973 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -522,7 +522,7 @@ int expect_strzr(const char *expr, int llen) { int ret = 0; - llen += printf(" = <%s> ", expr); + llen += printf(" = <%s> ", expr ? expr : "(null)"); if (expr) { ret = 1; result(llen, FAIL); @@ -541,7 +541,7 @@ int expect_strnz(const char *expr, int llen) { int ret = 0; - llen += printf(" = <%s> ", expr); + llen += printf(" = <%s> ", expr ? expr : "(null)"); if (!expr) { ret = 1; result(llen, FAIL); -- 2.43.0
7 months
1
0
0
0
[PATCH AUTOSEL 6.10 092/197] selftests/nolibc: avoid passing NULL to printf("%s")
by Sasha Levin
From: Thomas Weißschuh <linux(a)weissschuh.net> [ Upstream commit f1a58f61d88642ae1e6e97e9d72d73bc70a93cb8 ] Clang on higher optimization levels detects that NULL is passed to printf("%s") and warns about it. While printf() from nolibc gracefully handles that NULL, it is undefined behavior as per POSIX, so the warning is reasonable. Avoid the warning by transforming NULL into a non-NULL placeholder. Reviewed-by: Shuah Khan <skhan(a)linuxfoundation.org> Acked-by: Willy Tarreau <w(a)1wt.eu> Link:
https://lore.kernel.org/r/20240807-nolibc-llvm-v2-8-c20f2f5fc7c2@weissschuh…
Signed-off-by: Thomas Weißschuh <linux(a)weissschuh.net> Signed-off-by: Sasha Levin <sashal(a)kernel.org> --- tools/testing/selftests/nolibc/nolibc-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 994477ee87bef..4bd8360d54225 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -534,7 +534,7 @@ int expect_strzr(const char *expr, int llen) { int ret = 0; - llen += printf(" = <%s> ", expr); + llen += printf(" = <%s> ", expr ? expr : "(null)"); if (expr) { ret = 1; result(llen, FAIL); @@ -553,7 +553,7 @@ int expect_strnz(const char *expr, int llen) { int ret = 0; - llen += printf(" = <%s> ", expr); + llen += printf(" = <%s> ", expr ? expr : "(null)"); if (!expr) { ret = 1; result(llen, FAIL); -- 2.43.0
7 months
1
0
0
0
[PATCH AUTOSEL 6.11 147/244] selftests/bpf: fix uprobe.path leak in bpf_testmod
by Sasha Levin
From: Jiri Olsa <olsajiri(a)gmail.com> [ Upstream commit db61e6a4eee5a7884b2cafeaf407895f253bbaa7 ] testmod_unregister_uprobe() forgets to path_put(&uprobe.path). Signed-off-by: Jiri Olsa <olsajiri(a)gmail.com> Signed-off-by: Oleg Nesterov <oleg(a)redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz(a)infradead.org> Link:
https://lore.kernel.org/r/20240801132724.GA8791@redhat.com
Signed-off-by: Sasha Levin <sashal(a)kernel.org> --- tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c index fd28c1157bd3d..72f565af4f829 100644 --- a/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c +++ b/tools/testing/selftests/bpf/bpf_testmod/bpf_testmod.c @@ -477,6 +477,7 @@ static void testmod_unregister_uprobe(void) if (uprobe.offset) { uprobe_unregister(d_real_inode(uprobe.path.dentry), uprobe.offset, &uprobe.consumer); + path_put(&uprobe.path); uprobe.offset = 0; } -- 2.43.0
7 months
1
0
0
0
[PATCH AUTOSEL 6.11 108/244] selftests/nolibc: avoid passing NULL to printf("%s")
by Sasha Levin
From: Thomas Weißschuh <linux(a)weissschuh.net> [ Upstream commit f1a58f61d88642ae1e6e97e9d72d73bc70a93cb8 ] Clang on higher optimization levels detects that NULL is passed to printf("%s") and warns about it. While printf() from nolibc gracefully handles that NULL, it is undefined behavior as per POSIX, so the warning is reasonable. Avoid the warning by transforming NULL into a non-NULL placeholder. Reviewed-by: Shuah Khan <skhan(a)linuxfoundation.org> Acked-by: Willy Tarreau <w(a)1wt.eu> Link:
https://lore.kernel.org/r/20240807-nolibc-llvm-v2-8-c20f2f5fc7c2@weissschuh…
Signed-off-by: Thomas Weißschuh <linux(a)weissschuh.net> Signed-off-by: Sasha Levin <sashal(a)kernel.org> --- tools/testing/selftests/nolibc/nolibc-test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 093d0512f4c57..8cbb51dca0cd6 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -542,7 +542,7 @@ int expect_strzr(const char *expr, int llen) { int ret = 0; - llen += printf(" = <%s> ", expr); + llen += printf(" = <%s> ", expr ? expr : "(null)"); if (expr) { ret = 1; result(llen, FAIL); @@ -561,7 +561,7 @@ int expect_strnz(const char *expr, int llen) { int ret = 0; - llen += printf(" = <%s> ", expr); + llen += printf(" = <%s> ", expr ? expr : "(null)"); if (!expr) { ret = 1; result(llen, FAIL); -- 2.43.0
7 months
1
0
0
0
[PATCH] selftests/bpf: Add missing va_end.
by zhangjiao2
From: zhang jiao <zhangjiao2(a)cmss.chinamobile.com> There is no va_end after va_copy, just add it. Signed-off-by: zhang jiao <zhangjiao2(a)cmss.chinamobile.com> --- tools/testing/selftests/bpf/test_progs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/bpf/test_progs.c b/tools/testing/selftests/bpf/test_progs.c index c7a70e1a1085..7846f7f98908 100644 --- a/tools/testing/selftests/bpf/test_progs.c +++ b/tools/testing/selftests/bpf/test_progs.c @@ -868,6 +868,7 @@ static int libbpf_print_fn(enum libbpf_print_level level, va_copy(args2, args); vfprintf(libbpf_capture_stream, format, args2); + va_end(args2); } if (env.verbosity < VERBOSE_VERY && level == LIBBPF_DEBUG) -- 2.33.0
7 months
3
2
0
0
[PATCH v1 1/1] selftests: set executable bit
by David Hunter
Turn on the executable bit for the following script files. These scripts are set to TEST_PROGS in their respective Makefiles, but currently, when these tests are run, a warning occurs: # Warning: <file> is not executable Signed-off-by: David Hunter <david.hunter.linux(a)gmail.com> --- tools/testing/selftests/damon/damon_nr_regions.py | 0 tools/testing/selftests/damon/damos_apply_interval.py | 0 tools/testing/selftests/damon/damos_quota.py | 0 tools/testing/selftests/damon/damos_quota_goal.py | 0 tools/testing/selftests/damon/damos_tried_regions.py | 0 tools/testing/selftests/damon/debugfs_target_ids_pid_leak.sh | 0 .../damon/debugfs_target_ids_read_before_terminate_race.sh | 0 .../selftests/damon/sysfs_update_schemes_tried_regions_hang.py | 0 .../damon/sysfs_update_schemes_tried_regions_wss_estimation.py | 0 tools/testing/selftests/net/rds/test.py | 0 10 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 tools/testing/selftests/damon/damon_nr_regions.py mode change 100644 => 100755 tools/testing/selftests/damon/damos_apply_interval.py mode change 100644 => 100755 tools/testing/selftests/damon/damos_quota.py mode change 100644 => 100755 tools/testing/selftests/damon/damos_quota_goal.py mode change 100644 => 100755 tools/testing/selftests/damon/damos_tried_regions.py mode change 100644 => 100755 tools/testing/selftests/damon/debugfs_target_ids_pid_leak.sh mode change 100644 => 100755 tools/testing/selftests/damon/debugfs_target_ids_read_before_terminate_race.sh mode change 100644 => 100755 tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py mode change 100644 => 100755 tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py mode change 100644 => 100755 tools/testing/selftests/net/rds/test.py diff --git a/tools/testing/selftests/damon/damon_nr_regions.py b/tools/testing/selftests/damon/damon_nr_regions.py old mode 100644 new mode 100755 diff --git a/tools/testing/selftests/damon/damos_apply_interval.py b/tools/testing/selftests/damon/damos_apply_interval.py old mode 100644 new mode 100755 diff --git a/tools/testing/selftests/damon/damos_quota.py b/tools/testing/selftests/damon/damos_quota.py old mode 100644 new mode 100755 diff --git a/tools/testing/selftests/damon/damos_quota_goal.py b/tools/testing/selftests/damon/damos_quota_goal.py old mode 100644 new mode 100755 diff --git a/tools/testing/selftests/damon/damos_tried_regions.py b/tools/testing/selftests/damon/damos_tried_regions.py old mode 100644 new mode 100755 diff --git a/tools/testing/selftests/damon/debugfs_target_ids_pid_leak.sh b/tools/testing/selftests/damon/debugfs_target_ids_pid_leak.sh old mode 100644 new mode 100755 diff --git a/tools/testing/selftests/damon/debugfs_target_ids_read_before_terminate_race.sh b/tools/testing/selftests/damon/debugfs_target_ids_read_before_terminate_race.sh old mode 100644 new mode 100755 diff --git a/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py b/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_hang.py old mode 100644 new mode 100755 diff --git a/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py b/tools/testing/selftests/damon/sysfs_update_schemes_tried_regions_wss_estimation.py old mode 100644 new mode 100755 diff --git a/tools/testing/selftests/net/rds/test.py b/tools/testing/selftests/net/rds/test.py old mode 100644 new mode 100755 -- 2.43.0
7 months
3
2
0
0
[PATCH] selftest: remoteproc: Add basic test for start/stop sequence
by Wasim Nazir
Add new basic remoteproc test that check start/stop sequence of all subsystems available. diff --git a/MAINTAINERS b/MAINTAINERS index e062b5328341..aff76edc4242 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18225,6 +18225,7 @@ F: Documentation/staging/remoteproc.rst F: drivers/remoteproc/ F: include/linux/remoteproc.h F: include/linux/remoteproc/ +F: tools/testing/selftests/remoteproc/ REMOTE PROCESSOR MESSAGING (RPMSG) SUBSYSTEM M: Bjorn Andersson <andersson(a)kernel.org> diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 697f13bbbc32..31db0311efdc 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -68,6 +68,7 @@ TARGETS += proc TARGETS += pstore TARGETS += ptrace TARGETS += openat2 +TARGETS += remoteproc TARGETS += resctrl TARGETS += riscv TARGETS += rlimits diff --git a/tools/testing/selftests/remoteproc/Makefile b/tools/testing/selftests/remoteproc/Makefile new file mode 100644 index 000000000000..a84b3934fd36 --- /dev/null +++ b/tools/testing/selftests/remoteproc/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +TEST_PROGS := remoteproc_test.sh + +include ../lib.mk diff --git a/tools/testing/selftests/remoteproc/config b/tools/testing/selftests/remoteproc/config new file mode 100644 index 000000000000..a5c237d2f3b4 --- /dev/null +++ b/tools/testing/selftests/remoteproc/config @@ -0,0 +1 @@ +CONFIG_REMOTEPROC=y diff --git a/tools/testing/selftests/remoteproc/remoteproc_test.sh b/tools/testing/selftests/remoteproc/remoteproc_test.sh new file mode 100644 index 000000000000..88c8f15d8406 --- /dev/null +++ b/tools/testing/selftests/remoteproc/remoteproc_test.sh @@ -0,0 +1,165 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (c) 2024 Qualcomm Innovation Center, Inc. All rights reserved. +# + +DIR="$(dirname $(readlink -f "$0"))" + +KTAP_HELPERS="${DIR}/../kselftest/ktap_helpers.sh" +if [ -e "$KTAP_HELPERS" ]; then + source "$KTAP_HELPERS" +else + echo -n "1..0 # SKIP $KTAP_HELPERS file not found" + exit 4 +fi + +RPROC_SYS=/sys/class/remoteproc +RPROC_SEQ_SLEEP=5 +rproc_ss_files= +num_tests=0 +test_err=0 + +check_error() { + if [ $? -ne 0 ]; then + test_err=$((test_err+1)) + ktap_print_msg "$@" + fi +} + +rproc_seq_test_ss_one() { + ss=$1 + rproc=${RPROC_SYS}/$ss + rproc_name=$(cat $rproc/name) + rproc_state=$(cat $rproc/state) + rproc_ssr=$(cat $rproc/recovery) + ktap_print_msg "Testing rproc sequence for $rproc_name" + + # Reset test_err value + test_err=0 + if [ "$rproc_ssr" != "enabled" ]; then + echo enabled > $rproc/recovery + check_error "$rproc_name SSR-enabled failed" + fi + + if [ "$rproc_state" != "running" ]; then + echo start > "$rproc/state" + check_error "$rproc_name state-start failed" + + sleep ${RPROC_SEQ_SLEEP} + + echo stop > "$rproc/state" + check_error "$rproc_name state-stop failed" + else + echo stop > "$rproc/state" + check_error "$rproc_name state-stop failed" + + sleep ${RPROC_SEQ_SLEEP} + + echo start > "$rproc/state" + check_error "$rproc_name state-start failed" + fi + + if [ $test_err -ne 0 ]; then + ktap_test_fail "$rproc_name" + else + ktap_test_pass "$rproc_name" + fi +} + +rproc_seq_test_all_ss() { + # Declare an array to save initial states of each ss + org_ss_to_state="" + + # Reset test_err value + test_err=0 + + for ss in ${rproc_ss_files}; do + rproc=${RPROC_SYS}/$ss + rproc_name=$(cat $rproc/name) + rproc_ssr=$(cat $rproc/recovery) + + # Enable SSR-recovery support + if [ "$rproc_ssr" != "enabled" ]; then + echo enabled > $rproc/recovery + check_error "$rproc_name SSR-enabled failed" + fi + done + + for ss in ${rproc_ss_files}; do + rproc=${RPROC_SYS}/$ss + rproc_name=$(cat $rproc/name) + rproc_state=$(cat $rproc/state) + + # Save initial states for each ss + org_ss_to_state="$org_ss_to_state $rproc_state" + + # Initiate start/stop sequence + if [ "$rproc_state" != "running" ]; then + echo start > "$rproc/state" + check_error "$rproc_name state-start failed" + else + echo stop > "$rproc/state" + check_error "$rproc_name state-stop failed" + fi + sleep ${RPROC_SEQ_SLEEP} + done + + index=1 + for ss in ${rproc_ss_files}; do + rproc=${RPROC_SYS}/$ss + rproc_name=$(cat $rproc/name) + rproc_state=$(cat $rproc/state) + + ss_state=$(echo $org_ss_to_state | cut -d' ' -f$index) + # Terminate start/stop sequence + if [ "$ss_state" != "running" ]; then + echo stop > "$rproc/state" + check_error "$rproc_name state-stop failed" + else + echo start > "$rproc/state" + check_error "$rproc_name state-start failed" + fi + index=$((index+1)) + sleep ${RPROC_SEQ_SLEEP} + done + + if [ $test_err -ne 0 ]; then + ktap_test_fail "for any of $rproc_ss_files" + else + ktap_test_pass "for all $rproc_ss_files" + fi +} + +ktap_print_header + +if [[ ! -d "${RPROC_SYS}" ]]; then + ktap_skip_all "${RPROC_SYS} doesn't exist." + exit "${KSFT_SKIP}" +fi + +rproc_ss_files=$(find ${RPROC_SYS}/remoteproc* -maxdepth 1 -exec basename {} \;) +num_tests=$(echo ${rproc_ss_files} | wc -w) +if [[ "${num_tests}" -eq 0 ]]; then + ktap_skip_all "${RPROC_SYS}/remoteproc* doesn't exist." + exit "${KSFT_SKIP}" +fi + +# Total tests will be: +# 1) Seq tests for each subsystem sequencially +# 2) Seq tests for all subsystems concurrently +num_tests=$((num_tests+1)) + +ktap_set_plan "${num_tests}" + +# Test 1 +ktap_print_msg "Testing rproc up/down sequence for each subsystem sequencially" +for ss in ${rproc_ss_files}; do + rproc_seq_test_ss_one $ss +done + +# Test 2 +ktap_print_msg "Testing rproc up/down sequence for all subsystems concurrently" +rproc_seq_test_all_ss + +ktap_finished -- 2.46.1
7 months
2
1
0
0
[PATCH bpf-next v1] selftests/bpf:Enhance bpf ability to detect ksym read error by libcap
by Lin Yikai
Ksym addr access is restricted by ``kptr_restrict``(/proc/sys/kernel/kptr_restrict). On some OS systems(like Android), ksym addr access is not accessed because ``kptr_restrict=2`. And it took me a long time to find the root case. -When ``kptr_restrict==0``, addr is accessed. # echo 0 > /proc/sys/kernel/kptr_restrict # cat /proc/kallsyms | grep bpf_link_fops ffffffd6bfd3fb60 d bpf_link_fops -When ``kptr_restrict==2``, addr is replaced by ZERO. # echo 2 > /proc/sys/kernel/kptr_restrict # cat /proc/kallsyms | grep bpf_link_fops 0000000000000000 d bpf_link_fops -When ``kptr_restrict==1``, addr is accessed for user having CAP_SYSLOG. So we should perform a check to remind users for these conditions before reading /proc/kallsyms. [before]: # echo 2 > /proc/sys/kernel/kptr_restrict # ./test_progs -t ksyms #133 ksyms:FAIL [after]: # echo 2 > /proc/sys/kernel/kptr_restrict # ./test_progs -t ksym ksyms restricted, please check /proc/sys/kernel/kptr_restrict #133 ksyms:FAIL Signed-off-by: Lin Yikai <yikai.lin(a)vivo.com> --- tools/testing/selftests/bpf/Makefile | 7 ++- tools/testing/selftests/bpf/trace_helpers.c | 63 +++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile index 04716a5e43f1..369c5ad8fc4a 100644 --- a/tools/testing/selftests/bpf/Makefile +++ b/tools/testing/selftests/bpf/Makefile @@ -183,7 +183,7 @@ NON_CHECK_FEAT_TARGETS := clean docs-clean CHECK_FEAT := $(filter-out $(NON_CHECK_FEAT_TARGETS),$(or $(MAKECMDGOALS), "none")) ifneq ($(CHECK_FEAT),) FEATURE_USER := .selftests -FEATURE_TESTS := llvm +FEATURE_TESTS := llvm libcap FEATURE_DISPLAY := $(FEATURE_TESTS) # Makefile.feature expects OUTPUT to end with a slash @@ -208,6 +208,11 @@ ifeq ($(feature-llvm),1) LLVM_LDFLAGS += $(shell $(LLVM_CONFIG) --ldflags) endif +ifeq ($(feature-libcap), 1) + CFLAGS += -DHAVE_LIBCAP_SUPPORT + LDLIBS += -lcap +endif + SCRATCH_DIR := $(OUTPUT)/tools BUILD_DIR := $(SCRATCH_DIR)/build INCLUDE_DIR := $(SCRATCH_DIR)/include diff --git a/tools/testing/selftests/bpf/trace_helpers.c b/tools/testing/selftests/bpf/trace_helpers.c index 2d742fdac6b9..8d2f951464ff 100644 --- a/tools/testing/selftests/bpf/trace_helpers.c +++ b/tools/testing/selftests/bpf/trace_helpers.c @@ -17,6 +17,10 @@ #include <linux/limits.h> #include <libelf.h> #include <gelf.h> +#include <stdbool.h> +#include <linux/capability.h> +#include <linux/compiler.h> +#include <sys/types.h> #include "bpf/libbpf_internal.h" #define TRACEFS_PIPE "/sys/kernel/tracing/trace_pipe" @@ -31,6 +35,55 @@ struct ksyms { static struct ksyms *ksyms; static pthread_mutex_t ksyms_mutex = PTHREAD_MUTEX_INITIALIZER; +#ifdef HAVE_LIBCAP_SUPPORT +#include <sys/capability.h> +static bool bpf_cap__capable(cap_value_t cap) +{ + cap_flag_value_t val; + cap_t caps = cap_get_proc(); + + if (!caps) + return false; + + if (cap_get_flag(caps, cap, CAP_EFFECTIVE, &val) != 0) + val = CAP_CLEAR; + + if (cap_free(caps) != 0) + return false; + + return val == CAP_SET; +} +#else +static inline bool bpf_cap__capable(int cap __maybe_unused) +{ + return geteuid() == 0; +} +#endif /* HAVE_LIBCAP_SUPPORT */ + +/* For older systems */ +#ifndef CAP_SYSLOG +#define CAP_SYSLOG 34 +#endif + +static bool ksyms__kptr_restrict(void) +{ + bool value = false; + FILE *fp = fopen("/proc/sys/kernel/kptr_restrict", "r"); + + if (fp != NULL) { + char line[8]; + + if (fgets(line, sizeof(line), fp) != NULL) + value = bpf_cap__capable(CAP_SYSLOG) ? + (atoi(line) >= 2) : + (atoi(line) != 0); + + fclose(fp); + } + + return value; +} + static int ksyms__add_symbol(struct ksyms *ksyms, const char *name, unsigned long addr) { @@ -72,6 +125,11 @@ static struct ksyms *load_kallsyms_local_common(ksym_cmp_t cmp_cb) int ret; struct ksyms *ksyms; + if (ksyms__kptr_restrict()) { + printf("ksyms restricted, please check /proc/sys/kernel/kptr_restrict\n"); + return NULL; + } + f = fopen("/proc/kallsyms", "r"); if (!f) return NULL; @@ -218,6 +276,11 @@ int kallsyms_find(const char *sym, unsigned long long *addr) int err = 0; FILE *f; + if (ksyms__kptr_restrict()) { + printf("ksyms restricted, please check /proc/sys/kernel/kptr_restrict\n"); + return -EINVAL; + } + f = fopen("/proc/kallsyms", "r"); if (!f) return -EINVAL; -- 2.34.1
7 months
2
1
0
0
← Newer
1
...
11
12
13
14
15
16
17
...
33
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
Results per page:
10
25
50
100
200