Skip to contentSkip to conversation

Correct setuid behavious in linux-user

PATCH New Stuart Anderson 1 participant 1 message Mar 19, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Correct setuid behavious in linux-user

The attached patch is needed to correctly emulate setuid executables. With this change, and by making qemu be setuid root (and assumming all of the risks and responsibilites of doing so), executables such as /bin/su will be able to create the correct environment.

Stuart

Stuart R. Anderson                               [email protected]
Network & Software Engineering                   http://www.netsweng.com/
1024D/37A79149:                                  0791 D3B8 9A4C 2CDC A31F
                                                 BD03 0A62 E534 37A7 9149

Index: linux-user/linuxload.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/linuxload.c,v retrieving revision 1.2

linuxload.c +4 -0
diff -u -r1.2 linuxload.c
@@ -78,6 +78,8 @@
 	if(bprm->e_uid != geteuid()) {
 	    id_change = 1;
 	}
+    } else {
+      seteuid(getuid());
     }
 
     /* Set-gid? */
@@ -91,6 +93,8 @@
 	if (!in_group_p(bprm->e_gid)) {
 		id_change = 1;
 	}
+    } else {
+      setegid(getgid());
     }
 
     memset(bprm->buf, 0, sizeof(bprm->buf));