[PATCH] util-linux-ng/sys-util/unshare.c: drop potential euid privs before exec*

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

here is a patch that drops potential euid privileges before exec'ing the
target program.  This allows to setuid unshare.

Signed-off-by:  Martin Pohlack  <mp26@xxxxxxxxxxxxxxxxxxxx>
diff --git a/sys-utils/unshare.c b/sys-utils/unshare.c
index df75d17..1c25d71 100644
--- a/sys-utils/unshare.c
+++ b/sys-utils/unshare.c
@@ -113,6 +113,12 @@ int main(int argc, char *argv[])
 	if(-1 == unshare(unshare_flags))
 		err(EXIT_FAILURE, _("unshare failed"));
 
+	/* drop potential root euid/egid if we had been setuid'd */
+	while (0 != setuid(getuid()))
+		;
+	while (0 != setgid(getgid()))
+		;
+
 	execvp(argv[optind], argv + optind);
 
 	err(EXIT_FAILURE, _("exec %s failed"), argv[optind]);

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux