From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f68.google.com ([74.125.82.68]:34288 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423235AbcFMTpb (ORCPT ); Mon, 13 Jun 2016 15:45:31 -0400 From: Topi Miettinen To: linux-kernel@vger.kernel.org Cc: Topi Miettinen , Alexander Viro , Ingo Molnar , Peter Zijlstra , Serge Hallyn , Andrew Morton , Kees Cook , Christoph Lameter , "Serge E. Hallyn" , Andy Shevchenko , "Richard W.M. Jones" , =?UTF-8?q?Iago=20L=C3=B3pez=20Galeiras?= , Chris Metcalf , Andy Lutomirski , Jann Horn , linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and infrastructure)), linux-security-module@vger.kernel.org (open list:CAPABILITIES) 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> In-Reply-To: <1465847065-3577-1-git-send-email-toiwoton@gmail.com> References: <1465847065-3577-1-git-send-email-toiwoton@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Track what capabilities are actually used and present the current situation in /proc/self/status. Signed-off-by: Topi Miettinen --- 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