From: Serge Aleynikov <serge@hq.idt.net>
To: linux-kernel@vger.kernel.org
Cc: Linus Torvalds <torvalds@osdl.org>, Alan Cox <alan@redhat.com>
Subject: non-critical security bug fix
Date: Wed, 11 Oct 2006 14:58:33 -0400 [thread overview]
Message-ID: <452D3ED9.509@hq.idt.net> (raw)
To Maintainers of the linux/security/commoncap.c:
Patch description:
==================
This bug-fix ensures that if a process with root access sets
keep_capabilities flag, current capabilities get preserved when the
process switches from root to another effective user. It looks like
this was intended from the way capabilities are documented, but the
current->keep_capabilities flag is not being checked.
Regards,
Serge
----------------------------[ Begin patch ]---------------------------
--- linux/security/commoncap.c.orig 2005-10-29 16:00:58.656572231 -0400
+++ linux/security/commoncap.c 2005-10-29 16:04:45.093411424 -0400
@@ -217,6 +217,10 @@
* Keeping uid 0 is not an option because uid 0 owns too many vital
* files..
* Thanks to Olaf Kirch and Peter Benie for spotting this.
+ *
+ * Serge Aleynikov <serge@hq.idt.net> IDT Corp, Oct 2005
+ * Control the case (old_euid==0 && current->euid!=0) via
+ * current->keep_capabilities as well.
*/
static inline void cap_emulate_setxuid (int old_ruid, int old_euid,
int old_suid)
@@ -227,7 +231,8 @@
cap_clear (current->cap_permitted);
cap_clear (current->cap_effective);
}
- if (old_euid == 0 && current->euid != 0) {
+ if (old_euid == 0 && current->euid != 0 &&
+ !current->keep_capabilities) {
cap_clear (current->cap_effective);
}
if (old_euid != 0 && current->euid == 0) {
----------------------------[ End patch ]---------------------------
----------------------------[ Begin test ]--------------------------
Change the EFFECTIVE_UID value, compile and run the following as root.
This test tries to set the capability cap_net_raw, then switch from root
to an effective user, and open a raw socket being not a root.
#include <sys/socket.h>
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <linux/if_ether.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/capability.h>
#include <sys/prctl.h>
#define EFFECTIVE_UID 501
int main()
{
int s1, s2, rc;
cap_t caps;
char cmd [1024];
if (prctl (PR_SET_KEEPCAPS, 1, 0, 0, 0) < 0)
printf ("\nCould not SET_KEEPCAPS\n");
printf ("Keeping the Capabilities: %d\n",
prctl (PR_GET_KEEPCAPS, 0,0,0,0));
printf ("\nReal UID=%d, Real GID=%d, Eff UID=%d, Eff GID=%d\n",
getuid(), getgid(), geteuid(), getegid());
caps = cap_get_proc ();
printf ("\nInitial Capabilities: %s\n",
cap_to_text (caps, NULL));
sprintf (cmd, "cap_setuid,cap_setgid,cap_net_raw=eip");
printf ("\nSetting the Capabilities %s\n", cmd);
rc = cap_set_proc (cap_from_text (cmd));
if (rc != 0)
printf ("Failed to set the Capabilities: %s\n",
strerror(errno));
caps = cap_get_proc ();
printf ("\nPrivileged Capabilities: %s\n",
cap_to_text(caps, NULL));
setegid (EFFECTIVE_UID);
seteuid (EFFECTIVE_UID);
printf ("\nReal UID=%d, Real GID=%d, Eff UID=%d, Eff GID=%d\n",
getuid(), getgid(), geteuid(), getegid());
caps = cap_get_proc ();
printf ("\nUnPrivileged Capabilities: %s\n",
cap_to_text(caps, NULL));
s1 = socket (PF_INET, SOCK_RAW, IPPROTO_RAW);
if (s1 < 0)
printf ("PF_INET error: %s\n", strerror (errno));
s2 = socket (PF_PACKET, SOCK_RAW, htonl(ETH_P_IP));
if (s2 < 0)
printf ("PF_INET error: %s\n", strerror (errno));
return 0;
}
----------------------------[ End test ]----------------------------
Regards,
Serge
--
Serge Aleynikov
Routing R&D, IDT Telecom
Tel: +1 (973) 438-3436
Fax: +1 (973) 438-1464
next reply other threads:[~2006-10-11 18:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-11 18:58 Serge Aleynikov [this message]
2006-10-12 19:06 ` non-critical security bug fix Serge E. Hallyn
2006-10-12 19:25 ` Serge Aleynikov
2006-10-12 20:29 ` Serge E. Hallyn
2006-10-12 21:11 ` Serge Aleynikov
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=452D3ED9.509@hq.idt.net \
--to=serge@hq.idt.net \
--cc=alan@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@osdl.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