All of lore.kernel.org
 help / color / mirror / Atom feed
From: Karel Zak <kzak@redhat.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Richard Weinberger <richard@nod.at>,
	util-linux@vger.kernel.org, davidlohr.bueso@hp.com
Subject: Re: [PATCH] nsenter: Allow selecting the uid and gid to be used in the entered userns
Date: Mon, 6 May 2013 17:39:53 +0200	[thread overview]
Message-ID: <20130506153953.GA9740@x2.net.home> (raw)
In-Reply-To: <871u9yqf5d.fsf@xmission.com>

On Thu, Apr 25, 2013 at 06:01:02PM -0700, Eric W. Biederman wrote:
> Richard Weinberger <richard@nod.at> writes:
> 
> > Using -S (--setuid) and -G (--setgid) one can select
> > the uid/gid which will be used in the entered user namespace.
> 
> There is definitely utility here.  I don't have a strong preference but
> I am inclined to suggest that you remove the set_uid and set_gid
> variables, and unconditionally call setuid and setgid when entering
> a user namespace.

 I agree.

> > --- a/sys-utils/nsenter.c
> > +++ b/sys-utils/nsenter.c
> > @@ -72,6 +72,8 @@ static void usage(int status)
> >  	fputs(_(" -n, --net   [=<file>]  enter network namespace\n"), out);
> >  	fputs(_(" -p, --pid   [=<file>]  enter pid namespace\n"), out);
> >  	fputs(_(" -U, --user  [=<file>]  enter user namespace\n"), out);
> > +	fputs(_(" -S, --setuid <uid>     set uid in user namespace\n"), out);
> > +	fputs(_(" -G, --setgid <gid>     set gid in user namespace\n"), out);

 Richard, update man page too. Please.

> > @@ -319,5 +335,15 @@ int main(int argc, char *argv[])
> >  		execvp(argv[optind], argv + optind);
> >  		err(EXIT_FAILURE, _("failed to execute %s"), argv[optind]);
> >  	}
> > +
> > +	if (namespaces & CLONE_NEWUSER) {
> > +		if (set_uid)
> > +			if (setuid(uid) < 0)
> > +				err(EXIT_FAILURE, _("setuid failed"));
> > +		if (set_gid)
> > +			if (setgid(gid) < 0)
> > +				err(EXIT_FAILURE, _("setgid failed"));
> > +	}
> > +
> >  	exec_shell();

 Why do call setuid/gid() only for shell? Would be better to move all
 this code before the block with execvp() to call setuid/gid() for
 all execvp() as well as for exec_shell()?

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

  parent reply	other threads:[~2013-05-06 15:41 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-25 19:11 [PATCH] nsenter: Allow selecting the uid and gid to be used in the entered userns Richard Weinberger
2013-04-26  1:01 ` Eric W. Biederman
2013-04-26  5:39   ` Richard Weinberger
2013-05-06 15:39   ` Karel Zak [this message]
2013-06-18  8:41 ` Karel Zak
2014-02-06 13:00 ` Karel Zak

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=20130506153953.GA9740@x2.net.home \
    --to=kzak@redhat.com \
    --cc=davidlohr.bueso@hp.com \
    --cc=ebiederm@xmission.com \
    --cc=richard@nod.at \
    --cc=util-linux@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.