From: "Serge E. Hallyn" <serge@hallyn.com>
To: crocket <crockabiscuit@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Linux capabilities shouldn't be lost during setuid to non-root from root or to another non-root uid from a non-root uid.
Date: Sun, 17 Apr 2011 13:07:22 -0500 [thread overview]
Message-ID: <20110417180722.GA21112@hallyn.com> (raw)
In-Reply-To: <BANLkTikTxCFHs2xb4b5QFQp3SJAEjgyRJg@mail.gmail.com>
You need
prctl(PR_SET_KEEPCAPS, 1);
man prctl for details. In particular, see the following example:
#include <stdio.h>
#include <sys/prctl.h>
#include <sys/capability.h>
int main()
{
cap_t c;
c = cap_get_proc();
printf("uid %d, current caps: %s\n", getuid(), cap_to_text(c, NULL));
cap_free(c);
prctl(PR_SET_KEEPCAPS, 1);
setuid(1001, 1001, 1001);
c = cap_get_proc();
printf("uid %d, current caps: %s\n", getuid(), cap_to_text(c, NULL));
cap_free(c);
}
You can either run that as root, or you can do
sudo setcap cap_setuid,cap_setgid,cap_sys_admin=eip captest
and then run it as non-root.
HTH,
-serge
next prev parent reply other threads:[~2011-04-17 18:07 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-17 14:05 Linux capabilities shouldn't be lost during setuid to non-root from root or to another non-root uid from a non-root uid crocket
2011-04-17 18:07 ` Serge E. Hallyn [this message]
2011-04-18 1:20 ` crocket
2011-04-18 2:05 ` Serge E. Hallyn
2011-04-18 7:21 ` crocket
2011-04-18 8:28 ` Serge E. Hallyn
2011-04-18 15:02 ` crocket
2011-04-18 22:02 ` Serge E. Hallyn
2011-04-19 1:14 ` crocket
2011-04-19 1:29 ` Serge E. Hallyn
2011-04-19 14:27 ` crocket
2011-04-19 14:35 ` Serge E. Hallyn
2011-04-20 23:51 ` crocket
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=20110417180722.GA21112@hallyn.com \
--to=serge@hallyn.com \
--cc=crockabiscuit@gmail.com \
--cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox