qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: qemu-devel@nongnu.org
Cc: Riku Voipio <riku.voipio@iki.fi>, Laurent Vivier <laurent@vivier.eu>
Subject: [Qemu-devel] [PATCH] linux-user: allow to use sudo in guest qemu must have suid/gid bit and root owner/group
Date: Sat,  8 Dec 2012 16:22:11 +0100	[thread overview]
Message-ID: <1354980131-19274-1-git-send-email-laurent@vivier.eu> (raw)

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(-)

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);
-- 
1.7.10.4

                 reply	other threads:[~2012-12-08 15:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1354980131-19274-1-git-send-email-laurent@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).