All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Madore <david.madore@ens.fr>
To: Linux Kernel mailing-list <linux-kernel@vger.kernel.org>
Cc: David Wagner <daw-usenet@taverner.cs.berkeley.edu>
Subject: Re: patch to make Linux capabilities into something useful (v 0.3.1)
Date: Sat, 9 Sep 2006 14:49:13 +0200	[thread overview]
Message-ID: <20060909124913.GA22748@clipper.ens.fr> (raw)
In-Reply-To: <edt3m6$9kn$1@taverner.cs.berkeley.edu>

On Sat, Sep 09, 2006 at 01:01:02AM +0000, David Wagner wrote:
> David Madore  wrote:
> >On Fri, Sep 08, 2006 at 12:54:29AM +0200, Pavel Machek wrote:
> >>		      Alternatively disallow suid/sgid-anything exec
> >> when all "usual" capabilities are not present.
> >
> >This is probably too stringent: remove any trivial capability
> >whatsoever and you lose a rather important ability.
> 
> This might not be so terrible.  At least, I'm not sure I'd rule it
> out at this point -- it seems like it might be worth considering.

The following patch (follows version 0.4.3 of my main patch) should
make people happy in this respect: it adds a securebit (off by
default) to enable suid non-root execution by underprivileged
processes.

Signed-off-by: David A. Madore <david.madore@ens.fr>

---
 fs/exec.c                  |   16 ++++++++++++----
 include/linux/securebits.h |    9 +++++++++
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/fs/exec.c b/fs/exec.c
index 1cb5e34..adf834b 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -44,6 +44,7 @@ #include <linux/proc_fs.h>
 #include <linux/ptrace.h>
 #include <linux/mount.h>
 #include <linux/security.h>
+#include <linux/securebits.h>
 #include <linux/syscalls.h>
 #include <linux/rmap.h>
 #include <linux/acct.h>
@@ -918,6 +919,7 @@ int prepare_binprm(struct linux_binprm *
 	int mode;
 	struct inode * inode = bprm->file->f_dentry->d_inode;
 	int retval;
+	char ok_to_sxid;
 
 	mode = inode->i_mode;
 	if (bprm->file->f_op == NULL)
@@ -928,9 +930,16 @@ int prepare_binprm(struct linux_binprm *
 	bprm->is_suid = 0;
 	bprm->is_sgid = 0;
 
-	if(!(bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID)) {
+	ok_to_sxid = capable(CAP_REG_SXID)
+	  && !(bprm->file->f_vfsmnt->mnt_flags & MNT_NOSUID);
+	if (!cap_issubset(CAP_REGULAR_SET, current->cap_permitted)
+	    && !issecure(SECURE_UNDERPRIVILEGED_MAY_SXID)
+	    && (issecure(SECURE_NOROOT) || inode->i_uid != 0))
+		ok_to_sxid = 0;
+
+	if (ok_to_sxid) {
 		/* Set-uid? */
-		if (mode & S_ISUID && capable(CAP_REG_SXID)) {
+		if (mode & S_ISUID) {
 			bprm->is_suid = 1;
 			current->personality &= ~PER_CLEAR_ON_SETID;
 			bprm->e_uid = inode->i_uid;
@@ -942,8 +951,7 @@ int prepare_binprm(struct linux_binprm *
 		 * is a candidate for mandatory locking, not a setgid
 		 * executable.
 		 */
-		if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)
-		    && capable(CAP_REG_SXID)) {
+		if ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) {
 			bprm->is_sgid = 1;
 			current->personality &= ~PER_CLEAR_ON_SETID;
 			bprm->e_gid = inode->i_gid;
diff --git a/include/linux/securebits.h b/include/linux/securebits.h
index 5b06178..16e8f3e 100644
--- a/include/linux/securebits.h
+++ b/include/linux/securebits.h
@@ -18,6 +18,15 @@ #define SECURE_NOROOT            0
    privileges. When unset, setuid doesn't change privileges. */
 #define SECURE_NO_SETUID_FIXUP   2
 
+/* When set, allow underprivileged processes (= not possessing all
+   "regular" caps) to execute SUID/SGID executables (this is a
+   security issue as such executables might be surprised to run with
+   reduced privileges); if SECURE_NOROOT is _not_ set, this _does not_
+   apply to SUID root processes (they are already made secure by
+   raising all caps).  Removing the (regular) CAP_REG_SXID capability
+   also always inhibits any kind of SUID/SGID. */
+#define SECURE_UNDERPRIVILEGED_MAY_SXID 4
+
 /* Each securesetting is implemented using two bits. One bit specify
    whether the setting is on or off. The other bit specify whether the
    setting is fixed or not. A setting which is fixed cannot be changed

  reply	other threads:[~2006-09-09 12:49 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-05 21:26 patch to make Linux capabilities into something useful (v 0.3.1) David Madore
2006-09-06  0:27 ` Casey Schaufler
2006-09-06 10:06   ` David Madore
2006-09-06 13:26     ` David Madore
2006-09-07  0:11       ` Casey Schaufler
2006-09-07  0:32         ` David Madore
2006-09-07  1:01           ` Casey Schaufler
2006-09-07  1:29             ` David Wagner
2006-09-07 16:00               ` Casey Schaufler
2006-09-07 18:33                 ` David Wagner
2006-09-07 17:34             ` David Madore
2006-09-07 19:38               ` Bernd Eckenfels
2006-09-07 23:00                 ` Pavel Machek
2006-09-08  1:22                   ` Bernd Eckenfels
2006-09-08 10:45                     ` Pavel Machek
2006-09-08 16:08                       ` Casey Schaufler
2006-09-08 14:39                     ` Pavel Machek
2006-09-08 19:10                       ` Bernd Eckenfels
2006-09-07 22:54               ` Pavel Machek
2006-09-08  4:10                 ` David Madore
2006-09-08 10:52                   ` Pavel Machek
2006-09-08 22:51                     ` David Madore
2006-09-09  0:11                       ` Casey Schaufler
2006-09-09 11:59                         ` Pavel Machek
2006-09-09 11:40                       ` Pavel Machek
2006-09-10 10:41                         ` David Madore
2006-09-10 13:06                           ` Pavel Machek
2006-09-10 14:25                             ` capability inheritance (was: Re: patch to make Linux capabilities into something useful (v 0.3.1)) David Madore
2006-09-10 22:42                               ` Pavel Machek
2006-09-11 16:00                               ` Casey Schaufler
2006-09-11 17:39                                 ` David Madore
2006-09-09  0:59                   ` patch to make Linux capabilities into something useful (v 0.3.1) David Wagner
2006-09-09 12:49                     ` David Madore [this message]
2006-09-09 23:18       ` Theodore Tso
2006-09-10 10:13         ` David Madore
2006-09-10 12:36         ` Pavel Machek
2006-09-10 23:24           ` Theodore Tso
2006-09-11  8:09             ` Pavel Machek
2006-09-06 18:25 ` Serge E. Hallyn
2006-09-06 22:27   ` David Madore
2006-09-07  0:04     ` David Madore
2006-09-07 23:06       ` Serge E. Hallyn
2006-09-08  4:16         ` David Madore
2006-09-07  6:43     ` Jan Engelhardt
2006-09-07 23:02     ` Serge E. Hallyn
2006-09-08  1:08       ` David Madore
2006-09-08  1:31         ` Serge E. Hallyn
2006-09-08 21:45           ` David Madore
2006-09-07 18:21 ` James Antill
2006-09-07 18:33   ` Kyle Moffett
2006-09-07 20:05     ` James Antill
2006-09-08  4:00   ` David Madore

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=20060909124913.GA22748@clipper.ens.fr \
    --to=david.madore@ens.fr \
    --cc=daw-usenet@taverner.cs.berkeley.edu \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.