[PATCH net 2/2] selftests: net: test devinet inheritance after failed writes
From: Yingjie Wang
Date: Thu Oct 29 2026 - 10:36:35 EST
A failed per-device IPv4 sysctl write must not mark the setting as
explicitly configured. Otherwise, later conf/default updates stop
propagating to that device.
Add a test which rejects an invalid lo/arp_ignore write and then checks
that lo inherits a new default. Keep loopback unconfigured because adding
its address marks all devconf settings as explicit. Also verify the
complementary case: a valid same-value write marks the setting as explicit
and prevents inheritance.
Before each case, change the default to a value different from the current
lo value and require lo to inherit it. This avoids depending on init_net
defaults and skips the test if inherited state has already disabled
propagation.
The failed-write case fails on the base kernel. Both cases pass with the
preceding fix.
Signed-off-by: Yingjie Wang <x-professor@xxxxxxxxxxx>
---
tools/testing/selftests/net/Makefile | 1 +
tools/testing/selftests/net/devinet_conf.sh | 101 ++++++++++++++++++++
2 files changed, 102 insertions(+)
create mode 100755 tools/testing/selftests/net/devinet_conf.sh
diff --git a/tools/testing/selftests/net/Makefile b/tools/testing/selftests/net/Makefile
index df215e1a62621..f551bd40bab80 100644
--- a/tools/testing/selftests/net/Makefile
+++ b/tools/testing/selftests/net/Makefile
@@ -26,6 +26,7 @@ TEST_PROGS := \
cmsg_so_priority.sh \
cmsg_time.sh \
cork_fragsize.py \
+ devinet_conf.sh \
double_udp_encap.sh \
drop_monitor_tests.sh \
ecmp_rehash.sh \
diff --git a/tools/testing/selftests/net/devinet_conf.sh b/tools/testing/selftests/net/devinet_conf.sh
new file mode 100755
index 0000000000000..54655dc2b0bd8
--- /dev/null
+++ b/tools/testing/selftests/net/devinet_conf.sh
@@ -0,0 +1,101 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+
+source lib.sh
+
+cleanup()
+{
+ cleanup_all_ns
+}
+
+trap cleanup EXIT
+
+prepare_inheritance()
+{
+ local ns=$1
+ local result=$2
+ local current
+ local probe
+ local value
+
+ if ! current=$(ip netns exec "$ns" \
+ sysctl -n net.ipv4.conf.lo.arp_ignore); then
+ echo "ERROR: failed to read lo/arp_ignore in $ns"
+ return "$ksft_fail"
+ fi
+ if ((current == 0)); then
+ probe=1
+ else
+ probe=0
+ fi
+
+ if ! ip netns exec "$ns" sysctl -qw \
+ net.ipv4.conf.default.arp_ignore="$probe"; then
+ echo "ERROR: failed to update default/arp_ignore in $ns"
+ return "$ksft_fail"
+ fi
+ if ! value=$(ip netns exec "$ns" \
+ sysctl -n net.ipv4.conf.lo.arp_ignore); then
+ echo "ERROR: failed to read lo/arp_ignore in $ns"
+ return "$ksft_fail"
+ fi
+ if ((value != probe)); then
+ echo "SKIP: lo/arp_ignore does not inherit conf/default in $ns"
+ return "$ksft_skip"
+ fi
+
+ printf -v "$result" '%d' "$probe"
+}
+
+# Adding the loopback address marks all devconf settings as explicit.
+# Leave it unconfigured so default inheritance remains active.
+failed_ns="failed-$(mktemp -u XXXXXX)"
+if ! ip netns add "$failed_ns"; then
+ echo "Failed to create network namespace $failed_ns"
+ exit "$ksft_skip"
+fi
+NS_LIST+=("$failed_ns")
+
+explicit_ns="explicit-$(mktemp -u XXXXXX)"
+if ! ip netns add "$explicit_ns"; then
+ echo "Failed to create network namespace $explicit_ns"
+ exit "$ksft_skip"
+fi
+NS_LIST+=("$explicit_ns")
+
+prepare_inheritance "$failed_ns" failed_value
+ret=$?
+((ret == 0)) || exit "$ret"
+prepare_inheritance "$explicit_ns" explicit_value
+ret=$?
+((ret == 0)) || exit "$ret"
+failed_next=$((!failed_value))
+explicit_next=$((!explicit_value))
+
+RET=0
+ip netns exec "$failed_ns" sh -c \
+ 'printf x > /proc/sys/net/ipv4/conf/lo/arp_ignore' 2>/dev/null
+check_fail $? "invalid arp_ignore write was accepted"
+ip netns exec "$failed_ns" sysctl -qw \
+ net.ipv4.conf.default.arp_ignore="$failed_next"
+check_err $? "failed to update default arp_ignore"
+value=$(ip netns exec "$failed_ns" sysctl -n net.ipv4.conf.lo.arp_ignore)
+check_err $? "failed to read lo arp_ignore"
+check_err "$((value != failed_next))" \
+ "failed write prevented lo from inheriting arp_ignore"
+log_test "Failed devinet write preserves inheritance"
+
+RET=0
+ip netns exec "$explicit_ns" sysctl -qw \
+ net.ipv4.conf.lo.arp_ignore="$explicit_value"
+check_err $? "failed to explicitly set lo arp_ignore"
+ip netns exec "$explicit_ns" sysctl -qw \
+ net.ipv4.conf.default.arp_ignore="$explicit_next"
+check_err $? "failed to update default arp_ignore"
+value=$(ip netns exec "$explicit_ns" sysctl -n net.ipv4.conf.lo.arp_ignore)
+check_err $? "failed to read lo arp_ignore"
+check_err "$((value != explicit_value))" \
+ "explicit lo arp_ignore unexpectedly inherited the default"
+log_test "Valid same-value devinet write prevents inheritance"
+
+exit "$EXIT_STATUS"
--
2.43.0