public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Why can setuid programs regain root after dropping it when using capabilities?
@ 2005-11-30  2:35 David Chau
  2005-12-31 20:58 ` David Wagner
  0 siblings, 1 reply; 3+ messages in thread
From: David Chau @ 2005-11-30  2:35 UTC (permalink / raw)
  To: linux-kernel

Hi,

While debugging some code, I found that a setuid program could regain
root after dropping root if the program used capabilities. (I tested
this on 2.6.14 and 2.6.9.) Is this the expected behavior? Here's a
short test case:

/* chown root this program, suid it, and run it as non-root */
#include <sys/types.h>
#include <sys/capability.h>
#include <unistd.h>
#include <stdio.h>
int main() {
   cap_set_proc(cap_from_text("all-eip")); /* drop all caps */
   setuid(getuid());                       /* drop root. this call succeeds */
   setuid(0);                              /* this should fail! but doesn't */
   printf("%d\n", geteuid());              /* we regained root. prints 0 */
   return 0;
}

(If we don't use capabilities at all, and take out the cap_set_proc
line, then the program behaves as expected, and doesn't allow us to
regain root.)

--David

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-01-01 15:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-30  2:35 Why can setuid programs regain root after dropping it when using capabilities? David Chau
2005-12-31 20:58 ` David Wagner
2006-01-01 15:26   ` Jan Engelhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox