lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251025160905.3857885-309-sashal@kernel.org>
Date: Sat, 25 Oct 2025 11:59:00 -0400
From: Sasha Levin <sashal@...nel.org>
To: patches@...ts.linux.dev,
	stable@...r.kernel.org
Cc: Petr Machata <petrm@...dia.com>,
	Nikolay Aleksandrov <razor@...ckwall.org>,
	Jakub Kicinski <kuba@...nel.org>,
	Sasha Levin <sashal@...nel.org>,
	davem@...emloft.net,
	edumazet@...gle.com,
	pabeni@...hat.com,
	netdev@...r.kernel.org
Subject: [PATCH AUTOSEL 6.17] selftests: net: lib.sh: Don't defer failed commands

From: Petr Machata <petrm@...dia.com>

[ Upstream commit fa57032941d4b451c7264ebf3ad595bc98e3a9a9 ]

Usually the autodefer helpers in lib.sh are expected to be run in context
where success is the expected outcome. However when using them for feature
detection, failure can legitimately occur. But the failed command still
schedules a cleanup, which will likely fail again.

Instead, only schedule deferred cleanup when the positive command succeeds.

This way of organizing the cleanup has the added benefit that now the
return code from these functions reflects whether the command passed.

Signed-off-by: Petr Machata <petrm@...dia.com>
Acked-by: Nikolay Aleksandrov <razor@...ckwall.org>
Link: https://patch.msgid.link/af10a5bb82ea11ead978cf903550089e006d7e70.1757004393.git.petrm@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@...nel.org>
Signed-off-by: Sasha Levin <sashal@...nel.org>
---

LLM Generated explanations, may be completely bogus:

YES

- What it fixes
  - In tools/testing/selftests/net/lib.sh: wrapper helpers schedule
    deferred cleanups even when the “positive” command fails, and they
    unintentionally mask failures because the last executed command
    (defer) returns success. This leads to confusing follow-up errors
    and unreliable feature-detection logic.
  - The change makes deferred cleanup conditional on success and
    preserves the original command’s exit status, so failures are
    detected and reported correctly.

- Specific code changes
  - ip_link_add(): from running defer unconditionally to chaining with
    success, i.e. `ip link add ... && defer ip link del dev "$name"`
    (tools/testing/selftests/net/lib.sh).
  - ip_link_set_master(): `ip link set dev "$member" master "$master" &&
    defer ip link set dev "$member" nomaster`.
  - ip_link_set_addr(): captures `old_addr=$(mac_get "$name")` and only
    schedules rollback if setting the new address succeeds: `... &&
    defer ip link set dev "$name" address "$old_addr"`.
  - ip_link_set_up()/ip_link_set_down(): only schedule the opposite
    action if the set operation actually succeeded, e.g. `... && defer
    ip link set dev "$name" down/up`.
  - ip_addr_add(): `ip addr add dev "$name" "$@" && defer ip addr del
    dev "$name" "$@"`.
  - ip_route_add(): `ip route add "$@" && defer ip route del "$@"`.
  - bridge_vlan_add(): `bridge vlan add "$@" && defer bridge vlan del
    "$@"`.
  - Net effect: cleanup commands are deferred only after successful
    state changes; failure paths do not schedule doomed cleanups.

- Why it’s a good stable backport
  - User impact: Fixes real test flakiness and misleading pass/fail
    reporting in widely used net selftests. Feature detection can
    legitimately fail; previously that failure both scheduled a failing
    cleanup and could be hidden by a succeeding defer, making debugging
    hard.
  - Scope and size: Small, contained changes to a single selftests shell
    library file; no kernel/runtime code affected.
  - Risk profile: Minimal. The helpers now return the true result of the
    underlying ip/bridge command and don’t enqueue impossible cleanups.
    Tests that “passed” due to masked errors will start failing earlier
    and more clearly, which is the correct behavior.
  - Architecture/ABI: No architectural changes, no new features;
    strictly test reliability and correctness improvement.
  - Stable policy fit: Important bugfix for selftests that improves
    determinism and correctness with minimal risk.

- Side effects considered
  - Return codes of these helpers now reflect the command outcome. Any
    test inadvertently relying on the old, incorrect “always succeed”
    behavior may fail earlier, but that exposes pre-existing issues
    rather than introducing regressions.
  - Cleanup behavior in failure paths becomes a no-op (correct),
    avoiding secondary errors and noise.

Given the correctness fix, limited scope, and low risk, this commit is
well-suited for stable backporting.

 tools/testing/selftests/net/lib.sh | 32 +++++++++++++++---------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/tools/testing/selftests/net/lib.sh b/tools/testing/selftests/net/lib.sh
index c7add0dc4c605..80cf1a75136cf 100644
--- a/tools/testing/selftests/net/lib.sh
+++ b/tools/testing/selftests/net/lib.sh
@@ -547,8 +547,8 @@ ip_link_add()
 {
 	local name=$1; shift
 
-	ip link add name "$name" "$@"
-	defer ip link del dev "$name"
+	ip link add name "$name" "$@" && \
+		defer ip link del dev "$name"
 }
 
 ip_link_set_master()
@@ -556,8 +556,8 @@ ip_link_set_master()
 	local member=$1; shift
 	local master=$1; shift
 
-	ip link set dev "$member" master "$master"
-	defer ip link set dev "$member" nomaster
+	ip link set dev "$member" master "$master" && \
+		defer ip link set dev "$member" nomaster
 }
 
 ip_link_set_addr()
@@ -566,8 +566,8 @@ ip_link_set_addr()
 	local addr=$1; shift
 
 	local old_addr=$(mac_get "$name")
-	ip link set dev "$name" address "$addr"
-	defer ip link set dev "$name" address "$old_addr"
+	ip link set dev "$name" address "$addr" && \
+		defer ip link set dev "$name" address "$old_addr"
 }
 
 ip_link_has_flag()
@@ -590,8 +590,8 @@ ip_link_set_up()
 	local name=$1; shift
 
 	if ! ip_link_is_up "$name"; then
-		ip link set dev "$name" up
-		defer ip link set dev "$name" down
+		ip link set dev "$name" up && \
+			defer ip link set dev "$name" down
 	fi
 }
 
@@ -600,8 +600,8 @@ ip_link_set_down()
 	local name=$1; shift
 
 	if ip_link_is_up "$name"; then
-		ip link set dev "$name" down
-		defer ip link set dev "$name" up
+		ip link set dev "$name" down && \
+			defer ip link set dev "$name" up
 	fi
 }
 
@@ -609,20 +609,20 @@ ip_addr_add()
 {
 	local name=$1; shift
 
-	ip addr add dev "$name" "$@"
-	defer ip addr del dev "$name" "$@"
+	ip addr add dev "$name" "$@" && \
+		defer ip addr del dev "$name" "$@"
 }
 
 ip_route_add()
 {
-	ip route add "$@"
-	defer ip route del "$@"
+	ip route add "$@" && \
+		defer ip route del "$@"
 }
 
 bridge_vlan_add()
 {
-	bridge vlan add "$@"
-	defer bridge vlan del "$@"
+	bridge vlan add "$@" && \
+		defer bridge vlan del "$@"
 }
 
 wait_local_port_listen()
-- 
2.51.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ