[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20110417180722.GA21112@hallyn.com>
Date: Sun, 17 Apr 2011 13:07:22 -0500
From: "Serge E. Hallyn" <serge@...lyn.com>
To: crocket <crockabiscuit@...il.com>
Cc: linux-kernel@...r.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.
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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists