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>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240423183819.22367-1-yedaya.ka@gmail.com>
Date: Tue, 23 Apr 2024 21:38:20 +0300
From: Yedaya Katsman <yedaya.ka@...il.com>
To: netdev@...r.kernel.org
Cc: Stephen Hemminger <stephen@...workplumber.org>,
	Yedaya Katsman <yedaya.ka@...il.com>
Subject: [PATCH] ip: Exit exec in child process if setup fails

If we forked, returning from the function will make the calling code to
continue in both the child and parent process. Make cmd_exec exit if
setup failed and it forked already.

An example of issues this causes, where a failure in setup causes
multiple unnecessary tries:

```
$ ip netns
ef
ab
$ ip -all netns exec ls

netns: ef
setting the network namespace "ef" failed: Operation not permitted

netns: ab
setting the network namespace "ab" failed: Operation not permitted

netns: ab
setting the network namespace "ab" failed: Operation not permitted
```

Signed-off-by: Yedaya Katsman <yedaya.ka@...il.com>
---
 lib/exec.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/lib/exec.c b/lib/exec.c
index 9b1c8f4a1396..893937550079 100644
--- a/lib/exec.c
+++ b/lib/exec.c
@@ -36,8 +36,13 @@ int cmd_exec(const char *cmd, char **argv, bool do_fork,
 		}
 	}
 
-	if (setup && setup(arg))
+	if (setup && setup(arg)) {
+		if (do_fork) {
+			/* In child, nothing to do */
+			_exit(1);
+		}
 		return -1;
+	}
 
 	if (execvp(cmd, argv)  < 0)
 		fprintf(stderr, "exec of \"%s\" failed: %s\n",
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ