Re: Linux capabilities shouldn't be lost during setuid to non-rootfrom root or to another non-root uid from a non-root uid.
From: Serge E. Hallyn
Date: Sun Apr 17 2011 - 14:07:35 EST
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@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/