Skip to contentSkip to conversation

selftests: pid_namespace: test fork with dead ancestor

PATCH Applied Sahaj Chaudhari 2 participants 2 messages Oct 7 – Oct 12

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests: pid_namespace: test fork with dead ancestor

Add a regression test for fork() into a PID namespace whose parent namespace has lost its init process. Since the kernel cannot assign the new process a PID in that dead ancestor, fork() must fail with ENOMEM.

Create the nested PID namespaces, keep the child namespace handle open after its init process exits, then enter it and verify fork() fails.

Register the test with the PID namespace selftests and ignore its generated binary. Skip when namespace operations are denied or procfs cannot provide the pid_for_children handle.

---
 .../selftests/pid_namespace/.gitignore        |   1 +
 .../testing/selftests/pid_namespace/Makefile  |   2 +-
 .../pid_namespace/pidns_dead_ancestor.c       | 174 ++++++++++++++++++
 3 files changed, 176 insertions(+), 1 deletion(-)
 create mode 100644 tools/testing/selftests/pid_namespace/pidns_dead_ancestor.c
tools/testing/selftests/pid_namespace/.gitignore +1 -0
index c647c6eb33672..b87295802a73c 100644
@@ -1,3 +1,4 @@
 pid_max
+pidns_dead_ancestor
 pidns_init_via_setns
 regression_enomem
tools/testing/selftests/pid_namespace/Makefile +1 -1
index b01a924ac04bd..3199e6bebbdd8 100644
@@ -1,7 +1,7 @@
 # SPDX-License-Identifier: GPL-2.0
 CFLAGS += -g $(KHDR_INCLUDES)
 
-TEST_GEN_PROGS = regression_enomem pid_max pidns_init_via_setns
+TEST_GEN_PROGS = regression_enomem pid_max pidns_dead_ancestor pidns_init_via_setns
 
 LOCAL_HDRS += $(selfdir)/pidfd/pidfd.h
 
tools/testing/selftests/pid_namespace/pidns_dead_ancestor.c new file +174 -0

174 lines not on this page · raw message

#1 lore raw
Quoted 8 lines · Sahaj Chaudhari

Add a regression test for fork() into a PID namespace whose parent namespace has lost its init process. Since the kernel cannot assign the new process a PID in that dead ancestor, fork() must fail with ENOMEM.

Create the nested PID namespaces, keep the child namespace handle open after its init process exits, then enter it and verify fork() fails.

[...]

Applied to the kernel-7.4.signal branch of the vfs/vfs.git tree. Patches in the kernel-7.4.signal branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: kernel-7.4.signal

[1/1] selftests: pid_namespace: test fork with dead ancestor

      https://git.kernel.org/vfs/vfs/c/2ec5a0709461