From patchwork Mon Jun 13 19:44:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Topi Miettinen X-Patchwork-Id: 9174229 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D4B806044F for ; Mon, 13 Jun 2016 19:51:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C53342040D for ; Mon, 13 Jun 2016 19:51:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9BE0262AE; Mon, 13 Jun 2016 19:51:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 750FF2040D for ; Mon, 13 Jun 2016 19:51:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423310AbcFMTpi (ORCPT ); Mon, 13 Jun 2016 15:45:38 -0400 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 Received: by mail-wm0-f68.google.com with SMTP id n184so17312040wmn.1; Mon, 13 Jun 2016 12:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=deiQmx69ek+iUTIoCrrXfDTmr6O5WX9yjeRWWAm1jBs=; b=msWsRwxsAepyGE9RQGC6YYkjv8vhilbXc6U/Xn1Rd9xJgBv3tobtUGjidFDEM32Nsg ExnJgpY3vbaM55466+HilTwKx8T8ezrgqNDEfSEa1bhbHjdMjh4OiUFJl2YbkXqVdzQK vugMijQ4hKSC14xgfkvR4JWg8yepSOyXVLTvZn1lZ56VbDSas8le2zF2BTlzvK2p8JHk noU7CLMX8DJJy3fq8fJRAAaz5yVZm+mQacWah+HAwhQWW3Q29F2/HB8Z8sTNLcpZceBW GoZqgLFk7FBrqD42rb5Z2tf5JaUQYJ+txH5TQo8vJrCT7Et99Kp4s8dsMdy6c2zI6PR5 gj9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=deiQmx69ek+iUTIoCrrXfDTmr6O5WX9yjeRWWAm1jBs=; b=K6tT8bXFJDqTIu5kBTT53oAp+4t7eKjdIwbfo8DU4QuXNSPH72p0Re/ve8k2+c5uWh jy+Tmvx2A0S8uOsZXv3LpPr/VzYuwDq6+KRgslQS0J9fW9gahsiu6lIFUlE4mKxAFb3U 4CPpwYvW9VwXy0HelSb6e3IoYVqGh3UxF/jwkQwd0PpBk/0WNdxVu8SohymKT6T+/Ia5 TZ6xWXWpKYc34iWlmwJUmLFoNi7hQdx4shh8EysujzjKdeD2a9SaEeJq2Y7uHwGbIeL3 ITuSGtqT6SD/HaYzHtPUYjJBzvy49Eo8eO9HIEV+59tSTTCXmN8YxGr8Sg24Veob2Y2y wPfg== X-Gm-Message-State: ALyK8tIOl8LYwhXy0OBzRiZVvtuD8PMymWLuwva/LPtJsGoPnaosKolLRxJvSK+MOddZog== X-Received: by 10.194.117.35 with SMTP id kb3mr2867579wjb.136.1465847129623; Mon, 13 Jun 2016 12:45:29 -0700 (PDT) Received: from localhost.localdomain ([2001:2003:f54a:b700:2ab2:bdff:fe10:799e]) by smtp.gmail.com with ESMTPSA id c9sm29135737wjh.49.2016.06.13.12.45.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Jun 2016 12:45:29 -0700 (PDT) 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> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1465847065-3577-1-git-send-email-toiwoton@gmail.com> References: <1465847065-3577-1-git-send-email-toiwoton@gmail.com> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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; }