Patchwork linux-user: allow to use sudo in guest qemu must have suid/gid bit and root owner/group

login
register
mail settings
Submitter Laurent Vivier
Date Dec. 8, 2012, 3:22 p.m.
Message ID <1354980131-19274-1-git-send-email-laurent@vivier.eu>
Download mbox | patch
Permalink /patch/204671/
State New
Headers show

Comments

Laurent Vivier - Dec. 8, 2012, 3:22 p.m.
Signed-off-by: Laurent Vivier <laurent@vivier.eu>
---
 linux-user/linuxload.c |   12 +++++++-----
 linux-user/main.c      |    3 +++
 2 files changed, 10 insertions(+), 5 deletions(-)

Patch

diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c
index 381ab89..0fccf58 100644
--- a/linux-user/linuxload.c
+++ b/linux-user/linuxload.c
@@ -58,11 +58,6 @@  static int prepare_binprm(struct linux_binprm *bprm)
     bprm->e_uid = geteuid();
     bprm->e_gid = getegid();
 
-    /* Set-uid? */
-    if(mode & S_ISUID) {
-    	bprm->e_uid = st.st_uid;
-    }
-
     /* Set-gid? */
     /*
      * If setgid is set but no group execute bit then this
@@ -72,6 +67,13 @@  static int prepare_binprm(struct linux_binprm *bprm)
     if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
 	bprm->e_gid = st.st_gid;
     }
+    setresgid(getgid(), bprm->e_gid, bprm->e_gid);
+
+    /* Set-uid? */
+    if(mode & S_ISUID) {
+    	bprm->e_uid = st.st_uid;
+    }
+    setresuid(getuid(), bprm->e_uid, bprm->e_uid);
 
     retval = read(bprm->fd, bprm->buf, BPRM_BUF_SIZE);
     if (retval < 0) {
diff --git a/linux-user/main.c b/linux-user/main.c
index 25e35cd..3cddb2e 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3400,6 +3400,9 @@  int main(int argc, char **argv, char **envp)
     int i;
     int ret;
 
+    seteuid(getuid());
+    setegid(getgid());
+
     module_call_init(MODULE_INIT_QOM);
 
     qemu_cache_utils_init(envp);