|
|
Subscribe / Log in / New account

[RFC 01/18] capabilities: track actually used capabilities

From:  Topi Miettinen <toiwoton-AT-gmail.com>
To:  linux-kernel-AT-vger.kernel.org
Subject:  [RFC 01/18] capabilities: track actually used capabilities
Date:  Mon, 13 Jun 2016 22:44:08 +0300
Message-ID:  <1465847065-3577-2-git-send-email-toiwoton@gmail.com>
Cc:  Topi Miettinen <toiwoton-AT-gmail.com>, Alexander Viro <viro-AT-zeniv.linux.org.uk>, Ingo Molnar <mingo-AT-redhat.com>, Peter Zijlstra <peterz-AT-infradead.org>, Serge Hallyn <serge.hallyn-AT-canonical.com>, Andrew Morton <akpm-AT-linux-foundation.org>, Kees Cook <keescook-AT-chromium.org>, Christoph Lameter <cl-AT-linux.com>, "Serge E. Hallyn" <serge.hallyn-AT-ubuntu.com>, Andy Shevchenko <andriy.shevchenko-AT-linux.intel.com>, "Richard W.M. Jones" <rjones-AT-redhat.com>, =?UTF-8?q?Iago=20L=C3=B3pez=20Galeiras?= <iago-AT-endocode.com>, Chris Metcalf <cmetcalf-AT-ezchip.com>, Andy Lutomirski <luto-AT-kernel.org>, Jann Horn <jann-AT-thejh.net>, linux-fsdevel-AT-vger.kernel.org (open list:FILESYSTEMS (VFS and infrastructure)), linux-security-module-AT-vger.kernel.org (open list:CAPABILITIES)
Archive‑link:  Article

Track what capabilities are actually used and present the current
situation in /proc/self/status.

Signed-off-by: Topi Miettinen <toiwoton@gmail.com>
---
 fs/exec.c             | 1 +
 fs/proc/array.c       | 1 +
 include/linux/sched.h | 1 +
 kernel/capability.c   | 1 +
 4 files changed, 4 insertions(+)

diff --git a/fs/exec.c b/fs/exec.c
index 887c1c9..ff6f644 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1269,6 +1269,7 @@ void setup_new_exec(struct linux_binprm * bprm)
 		if (bprm->interp_flags & BINPRM_FLAGS_ENFORCE_NONDUMP)
 			set_dumpable(current->mm, suid_dumpable);
 	}
+	cap_clear(current->cap_used);
 
 	/* An exec changes our domain. We are no longer part of the thread
 	   group */
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 88c7de1..cccc9ee 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -343,6 +343,7 @@ static inline void task_cap(struct seq_file *m, struct task_struct *p)
 	render_cap_t(m, "CapEff:\t", &cap_effective);
 	render_cap_t(m, "CapBnd:\t", &cap_bset);
 	render_cap_t(m, "CapAmb:\t", &cap_ambient);
+	render_cap_t(m, "CapUsd:\t", &p->cap_used);
 }
 
 static inline void task_seccomp(struct seq_file *m, struct task_struct *p)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 6e42ada..9c48a08 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1918,6 +1918,7 @@ struct task_struct {
 #ifdef CONFIG_MMU
 	struct task_struct *oom_reaper_list;
 #endif
+	kernel_cap_t	cap_used;	/* Capabilities actually used */
 /* CPU-specific state of this task */
 	struct thread_struct thread;
 /*
diff --git a/kernel/capability.c b/kernel/capability.c
index 45432b5..aad8854 100644
--- a/kernel/capability.c
+++ b/kernel/capability.c
@@ -380,6 +380,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
 	}
 
 	if (security_capable(current_cred(), ns, cap) == 0) {
+		cap_raise(current->cap_used, cap);
 		current->flags |= PF_SUPERPRIV;
 		return true;
 	}
-- 
2.8.1

--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html




to post comments


Copyright © 2016, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds