[linux-yocto] [PATCH] capabilities: add a securebit to disable PR_CAP_AMBIENT_RAISE

Saul Wold sgw at linux.intel.com
Thu Feb 11 08:16:56 PST 2016

From: Andy Lutomirski <luto at kernel.org>

commit 746bf6d64275be0c65b0631d8a72b16f1454cfa1 upstream.

Per Andrew Morgan's request, add a securebit to allow admins to disable
PR_CAP_AMBIENT_RAISE.  This securebit will prevent processes from adding
capabilities to their ambient set.

For simplicity, this disables PR_CAP_AMBIENT_RAISE entirely rather than
just disabling setting previously cleared bits.

Signed-off-by: Andy Lutomirski <luto at kernel.org>
Acked-by: Andrew G. Morgan <morgan at kernel.org>
Acked-by: Serge Hallyn <serge.hallyn at canonical.com>
Cc: Kees Cook <keescook at chromium.org>
Cc: Christoph Lameter <cl at linux.com>
Cc: Serge Hallyn <serge.hallyn at canonical.com>
Cc: Jonathan Corbet <corbet at lwn.net>
Cc: Aaron Jones <aaronmdjones at gmail.com>
Cc: Ted Ts'o <tytso at mit.edu>
Cc: Andrew G. Morgan <morgan at kernel.org>
Cc: Mimi Zohar <zohar at linux.vnet.ibm.com>
Cc: Austin S Hemmelgarn <ahferroin7 at gmail.com>
Cc: Markku Savela <msa at moth.iki.fi>
Cc: Jarkko Sakkinen <jarkko.sakkinen at linux.intel.com>
Cc: Michael Kerrisk <mtk.manpages at gmail.com>
Cc: James Morris <james.l.morris at oracle.com>
Signed-off-by: Andrew Morton <akpm at linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>

diff --git a/include/uapi/linux/securebits.h b/include/uapi/linux/securebits.h
index 985aac9..35ac35c 100644
--- a/include/uapi/linux/securebits.h
+++ b/include/uapi/linux/securebits.h
@@ -43,9 +43,18 @@
 #define SECBIT_KEEP_CAPS	(issecure_mask(SECURE_KEEP_CAPS))
+/* When set, a process cannot add new capabilities to its ambient set. */
+#define SECURE_NO_CAP_AMBIENT_RAISE_LOCKED	7  /* make bit-6 immutable */
 #define SECURE_ALL_BITS		(issecure_mask(SECURE_NOROOT) | \
 				 issecure_mask(SECURE_NO_SETUID_FIXUP) | \
-				 issecure_mask(SECURE_KEEP_CAPS))
+				 issecure_mask(SECURE_KEEP_CAPS) | \
+				 issecure_mask(SECURE_NO_CAP_AMBIENT_RAISE))
diff --git a/security/commoncap.c b/security/commoncap.c
index 1f74dde..1832cf7 100644
--- a/security/commoncap.c
+++ b/security/commoncap.c
@@ -993,7 +993,8 @@ int cap_task_prctl(int option, unsigned long arg2, unsigned long arg3,
 			if (arg2 == PR_CAP_AMBIENT_RAISE &&
 			    (!cap_raised(current_cred()->cap_permitted, arg3) ||
-					 arg3)))
+					 arg3) ||
+			     issecure(SECURE_NO_CAP_AMBIENT_RAISE)))
 				return -EPERM;
 			new = prepare_creds();

More information about the linux-yocto mailing list