selftests/mm: Validate selections and scope memfd_secret setup
Subsystems (3)
v3 cover selftests/mm: Validate selections and scope memfd_secret setup
run_vmtests.sh can reach test setup after invalid options or category selections. Its memfd_secret preparation can also change ptrace_scope when that category was not selected.
Patch 1 rejects invalid selections before setup. Patch 2 gates memfd_secret preparation on category selection and executable presence.
The patches and commit messages are unchanged from v3. This resend uses git send-email through Gmail's SMTP server to send the patches inline. Before resending, I sent them to my SpaceMail mailbox and verified the received contents and whitespace. Both patches passed git apply --check and git am, and the resulting trees matched the original commits.
David, this is my first time setting up Gmail SMTP for patch submission. I'm very sorry for the formatting problems I caused and for taking up so much of your time. Thank you for your patience.
Changes in v3:
- Initialize VM_SELFTEST_ITEMS to "default" before getopts, as David suggested. Only -t changes the selection.
- Use Assisted-by: LLM in both patches.
- Carry David's Acked-by on patch 2, unchanged from v2.
Tianyi Chen (2):
selftests/mm: Reject invalid test selections before running tests selftests/mm: Only prepare ptrace_scope when memfd_secret is selected
tools/testing/selftests/mm/run_vmtests.sh | 28 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-)
Signature · 1 line
2.55.0
PATCH RESEND v3 1/2 selftests/mm: Reject invalid test selections before running tests
From: Tianyi Chen <[email protected]>
getopts reports unknown options and missing arguments, but run_vmtests.sh ignores its error result and continues with test setup. An empty -t argument also falls back to the default selection, while unknown category names can silently select no tests and still reach setup code.
Exit on getopts errors and validate category names against the existing list in usage() before any test setup. Reject empty and whitespace-only selections, and normalize category separators so validation and execution agree. Initialize the default selection before parsing options so only -t changes the selection.
--- tools/testing/selftests/mm/run_vmtests.sh | 26 +++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-)
tools/testing/selftests/mm/run_vmtests.sh +22 -4
@@ -96,26 +96,44 @@ separated by spaces: example: ./run_vmtests.sh -t "hmm mmap ksm" EOF - exit 0 } RUN_ALL=false RUN_DESTRUCTIVE=false TAP_PREFIX="# " +VM_SELFTEST_ITEMS="default" + while getopts "aht:nd" OPT; do case ${OPT} in "a") RUN_ALL=true ;; - "h") usage ;; + "h") usage; exit 0 ;; "t") VM_SELFTEST_ITEMS=${OPTARG} ;; "n") TAP_PREFIX= ;; "d") RUN_DESTRUCTIVE=true ;; + "?") exit 1 ;; esac done shift $((OPTIND -1)) -# default behavior: run all tests -VM_SELFTEST_ITEMS=${VM_SELFTEST_ITEMS:-default} +# Normalize whitespace so validation and test_selected() use the same names. +read -r -a selected_categories <<< "${VM_SELFTEST_ITEMS//$'\n'/ }" +VM_SELFTEST_ITEMS="${selected_categories[*]}" +if [ -z "$VM_SELFTEST_ITEMS" ]; then + echo "No test categories specified" >&2 + exit 1 +fi + +if [ "$VM_SELFTEST_ITEMS" != "default" ]; then + # Keep the documented category list as the source of valid names. + valid_categories=$(usage | sed -n 's/^- //p') + for category in "${selected_categories[@]}"; do + if ! grep -Fxq -- "$category" <<< "$valid_categories"; then + echo "Unknown test category: $category" >&2 + exit 1 + fi + done +fi test_selected() { if [ "$VM_SELFTEST_ITEMS" == "default" ]; then
Signature · 1 line
2.55.0
PATCH RESEND v3 2/2 selftests/mm: Only prepare ptrace_scope when memfd_secret is selected
In reply to Tianyi ChenFrom: Tianyi Chen <[email protected]>
The memfd_secret setup clears ptrace_scope whenever its test binary is executable, even when a different category was selected. run_test() filters the test invocation, but it does not protect the preceding setup.
Check the category selection before entering the memfd_secret block so running unrelated categories does not change ptrace_scope. Keep the existing executable check and the behavior when memfd_secret is selected.
--- tools/testing/selftests/mm/run_vmtests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/mm/run_vmtests.sh +1 -1
@@ -370,7 +370,7 @@ CATEGORY="process_madv" run_test ./process_madv CATEGORY="vma_merge" run_test ./merge -if [ -x ./memfd_secret ] +if test_selected "memfd_secret" && [ -x ./memfd_secret ] then if [ -f /proc/sys/kernel/yama/ptrace_scope ]; then (echo 0 > /proc/sys/kernel/yama/ptrace_scope 2>&1) | tap_prefix
Signature · 1 line
2.55.0