From: Christoph Lameter <cl@linux.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: "Serge E. Hallyn" <serge@hallyn.com>,
"Andrew G. Morgan" <morgan@kernel.org>,
Serge Hallyn <serge.hallyn@ubuntu.com>,
Serge Hallyn <serge.hallyn@canonical.com>,
Jonathan Corbet <corbet@lwn.net>,
Aaron Jones <aaronmdjones@gmail.com>, "Ted Ts'o" <tytso@mit.edu>,
LSM List <linux-security-module@vger.kernel.org>,
lkml <linux-kernel@vger.kernel.org>,
Andrew Morton <akpm@linuxfoundation.org>
Subject: Re: [RFC] Implement ambient capability set V2
Date: Wed, 4 Feb 2015 16:02:35 -0600 (CST) [thread overview]
Message-ID: <alpine.DEB.2.11.1502041601480.26492@gentwo.org> (raw)
In-Reply-To: <alpine.DEB.2.11.1502041558290.26492@gentwo.org>
Subject: [capabilities] Implement ambient capability set V2
DRAFT -- untested -- DRAFT
Implement an ambient capabilty set to allow capabilties
to be inherited with unix semantics used also for other
attributes.
Implements PR_CAP_AMBIENT. The second argument to prctl
is a the capability number and the third the desired state.
0 for off. Otherwise on.
Serge:
A new capability set, pA, is empty by default. You can
add bits to it using prctl if ns_capable(CAP_SETPCAP) and
all the new bits are in your pE. Once set, they stay until
they are removed using prctl. At exec, pA' = pA, and
fI |= pA (after reading fI from disk but before
calculating pI').
Since the ambient caps "stay on" cap_inheritable does not
really matter anymore. Simply set the permitted caps when
the ambient cap is set.
Signed-off-by: Christoph Lameter <cl@linux.com>
Index: linux/security/commoncap.c
===================================================================
--- linux.orig/security/commoncap.c
+++ linux/security/commoncap.c
@@ -351,9 +351,10 @@ static inline int bprm_caps_from_vfs_cap
__u32 inheritable = caps->inheritable.cap[i];
/*
- * pP' = (X & fP) | (pI & fI)
+ * pP' = (pA & fP) | (X & fP) | (pI & fI)
*/
new->cap_permitted.cap[i] =
+ (current_cred()->cap_ambient.cap[i] & permitted) |
(new->cap_bset.cap[i] & permitted) |
(new->cap_inheritable.cap[i] & inheritable);
@@ -453,9 +454,13 @@ static int get_file_caps(struct linux_bi
if (rc == -EINVAL)
printk(KERN_NOTICE "%s: get_vfs_caps_from_disk returned %d for %s\n",
__func__, rc, bprm->filename);
- else if (rc == -ENODATA)
- rc = 0;
- goto out;
+ else if (rc != -ENODATA)
+ goto out;
+ rc = 0;
+ if (cap_isclear(current_cred()->cap_ambient))
+ goto out;
+ *effective = true;
+ *has_cap = true;
}
rc = bprm_caps_from_vfs_caps(&vcaps, bprm, effective, has_cap);
@@ -577,6 +582,7 @@ skip:
}
new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
+ new->cap_ambient = old->cap_ambient;
return 0;
}
@@ -933,6 +939,23 @@ int cap_task_prctl(int option, unsigned
new->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
return commit_creds(new);
+ case PR_CAP_AMBIENT:
+ if (!ns_capable(current_user_ns(), CAP_SETPCAP))
+ return -EPERM;
+
+ if (!cap_valid(arg2))
+ return -EINVAL;
+
+ if (!ns_capable(current_user_ns(), arg2))
+ return -EPERM;
+
+ new = prepare_creds();
+ if (arg3 == 0)
+ cap_lower(new->cap_ambient, arg2);
+ else
+ cap_raise(new->cap_ambient, arg2);
+ return commit_creds(new);
+
default:
/* No functionality available - continue with default */
return -ENOSYS;
Index: linux/include/linux/cred.h
===================================================================
--- linux.orig/include/linux/cred.h
+++ linux/include/linux/cred.h
@@ -122,6 +122,7 @@ struct cred {
kernel_cap_t cap_permitted; /* caps we're permitted */
kernel_cap_t cap_effective; /* caps we can actually use */
kernel_cap_t cap_bset; /* capability bounding set */
+ kernel_cap_t cap_ambient; /* Ambient capability set */
#ifdef CONFIG_KEYS
unsigned char jit_keyring; /* default keyring to attach requested
* keys to */
Index: linux/include/uapi/linux/prctl.h
===================================================================
--- linux.orig/include/uapi/linux/prctl.h
+++ linux/include/uapi/linux/prctl.h
@@ -185,4 +185,7 @@ struct prctl_mm_map {
#define PR_MPX_ENABLE_MANAGEMENT 43
#define PR_MPX_DISABLE_MANAGEMENT 44
+/* Control the ambient capability set */
+#define PR_CAP_AMBIENT 45
+
#endif /* _LINUX_PRCTL_H */
next prev parent reply other threads:[~2015-02-04 22:02 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-02-04 18:49 [RFC] Implement ambient capability set Christoph Lameter
2015-02-04 20:44 ` Andy Lutomirski
2015-02-04 21:16 ` Serge E. Hallyn
2015-02-04 21:24 ` Andy Lutomirski
2015-02-04 21:27 ` Serge E. Hallyn
2015-02-04 21:31 ` Andy Lutomirski
2015-02-04 21:51 ` Serge E. Hallyn
2015-02-04 22:02 ` Serge E. Hallyn
2015-02-04 22:32 ` Andy Lutomirski
2015-02-05 0:03 ` Serge E. Hallyn
2015-02-04 21:57 ` Christoph Lameter
2015-02-04 22:29 ` Andy Lutomirski
2015-02-04 21:51 ` Christoph Lameter
2015-02-04 21:56 ` Andy Lutomirski
2015-02-04 22:01 ` Christoph Lameter
2015-02-04 22:02 ` Christoph Lameter [this message]
2015-02-05 7:20 ` Michael Kerrisk
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=alpine.DEB.2.11.1502041601480.26492@gentwo.org \
--to=cl@linux.com \
--cc=aaronmdjones@gmail.com \
--cc=akpm@linuxfoundation.org \
--cc=corbet@lwn.net \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=morgan@kernel.org \
--cc=serge.hallyn@canonical.com \
--cc=serge.hallyn@ubuntu.com \
--cc=serge@hallyn.com \
--cc=tytso@mit.edu \
/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
all inboxes | Powered by JetHome®