From patchwork Tue Apr 26 19:30:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 8943591 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 33CC8BF29F for ; Tue, 26 Apr 2016 19:38:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 689072015A for ; Tue, 26 Apr 2016 19:38:56 +0000 (UTC) Received: from emsm-gh1-uea11.nsa.gov (emsm-gh1-uea11.nsa.gov [8.44.101.9]) by mail.kernel.org (Postfix) with ESMTP id 4CA192013D for ; Tue, 26 Apr 2016 19:38:55 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.24,538,1454976000"; d="scan'208";a="15642631" IronPort-PHdr: =?us-ascii?q?9a23=3A8uT0jxYMWBO//h2gxiQXjb3/LSx+4OfEezUN459i?= =?us-ascii?q?sYplN5qZo8m9bnLW6fgltlLVR4KTs6sC0LqG9f+xEjVbud6oizMrTt9lb1c9k8?= =?us-ascii?q?IYnggtUoauKHbQC7rUVRE8B9lIT1R//nu2YgB/Ecf6YEDO8DXptWZBUiv2OQc9?= =?us-ascii?q?HOnpAIma153xjLDivcKCKFwT3HKUWvBbElaflU3prM4YgI9veO4a6yDihT92Qd?= =?us-ascii?q?lQ3n5iPlmJnhzxtY+a9Z9n9DlM6bp6r5YTGY2zRakzTKRZATI6KCh1oZSz7ViQ?= =?us-ascii?q?BTeIszExSGQd2iUOSyLE4R33RJL4tGGy4ud32SSWMNfzZaAxWC+57qBtDhTvjX?= =?us-ascii?q?FDfxc9/XHejMB9luploQim70hhwpTTSJOYMvtgOKfce84KA21bUYBMVHoFSrix?= =?us-ascii?q?dYQCR8oIOeJJqcGpvFYUohb4BQCoAPLp4jRBgHjw3KYz16IqFgSQmEQCFtcDqz?= =?us-ascii?q?zxq8/vNbxaBeK8yaTTizGFavRMwzbmwI/SexslrLeHWrcmNYKb8kQ1GA6NoxPY?= =?us-ascii?q?iYXhOyKTnKxZqGWB4OdIVeurj38h7Qp2p2786N0rj9zyi54Vgn7D7z55zYt9cc?= =?us-ascii?q?a1VE49b9m+C5tdugmRPo1xRMIpSmUusyE/nO5V8aWndTQHncx0jyXUbOaKJs3R?= =?us-ascii?q?ukru?= X-IPAS-Result: =?us-ascii?q?A2EFBQBXwx9X/wHyM5BeHAGDG4FQtVWGIh+HOkwBAQEBAQE?= =?us-ascii?q?CAmIngi2CFQEBBAECJBMUIAsDAwkBARcpCAgDASgFFREGAQcLBRgEiAnEOgEBC?= =?us-ascii?q?AIBHYYhiFoKBwGFdAWOSIlIgVWMRIlPhUBFjmtiggUbgWlOAYdvCReBHgEBAQ?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2016 19:38:22 +0000 Received: from prometheus.infosec.tycho.ncsc.mil (prometheus [192.168.25.40]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u3QJcLk0012129; Tue, 26 Apr 2016 15:38:21 -0400 Received: from tarius.tycho.ncsc.mil (tarius.infosec.tycho.ncsc.mil [144.51.242.1]) by prometheus.infosec.tycho.ncsc.mil (8.15.2/8.15.2) with ESMTP id u3QJUql1172213 for ; Tue, 26 Apr 2016 15:30:52 -0400 Received: from goalie.tycho.ncsc.mil (goalie [144.51.242.250]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id u3QJUoHK010214 for ; Tue, 26 Apr 2016 15:30:52 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BABQAQwR9X/yUp0ApeHYMbgVCCc7JkghmLYkwBAQEBAQFmJ4RCAQUnUhAISSwrBgESiCrEZ4YhiGSFfAWOSIlIgVWMRIlPhUBFjmtigTYBThuBaR4wAYdvgT4BAQE X-IPAS-Result: A0BABQAQwR9X/yUp0ApeHYMbgVCCc7JkghmLYkwBAQEBAQFmJ4RCAQUnUhAISSwrBgESiCrEZ4YhiGSFfAWOSIlIgVWMRIlPhUBFjmtigTYBThuBaR4wAYdvgT4BAQE X-IronPort-AV: E=Sophos;i="5.24,537,1454994000"; d="scan'208";a="5410353" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 26 Apr 2016 15:30:52 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AzIANSBJN6909bvblfNmcpTZWNBhigK39O0sv0rFi?= =?us-ascii?q?tYgSL/vxwZ3uMQTl6Ol3ixeRBMOAu6IC1Lud6vu4EUU7or+/81k6OKRWUBEEjc?= =?us-ascii?q?hE1ycBO+WiTXPBEfjxciYhF95DXlI2t1uyMExSBdqsLwaK+i760zceF13FOBZv?= =?us-ascii?q?IaytQ8iJ35TxiLH5osaLKyxzxxODIppKZC2sqgvQssREyaBDEY0WjiXzn31TZu?= =?us-ascii?q?5NznlpL1/A1zz158O34YIxu38I46Fp34d6XK77Z6U1S6BDRHRjajhtpZ6jiR6W?= =?us-ascii?q?ByaV53BUbSNeuBtFDwXf6Rj8FN+lvyH7u+ZwwiyyLcj3Vqs1XjLk5KBuHlugoS?= =?us-ascii?q?MKJzc//GzNwvJxlqUT9AygvRtX0YPSYZ/TMPt4Y7ObeskVA3dCCIIZbCFbDY70?= =?us-ascii?q?T4ILC/sHdbJDopPyqh0OpB+6FA+ED+rpzTlJjXbym6Y91rJlWSPP2QE7V/cJqm?= =?us-ascii?q?7Vt52hNq4XXPvzyO/Nyi/Zbuh+3i3044zFNBsmpKfIFfhLfNDexAECUUvlh1GU?= =?us-ascii?q?uIqvd2eO2/4CvkCb5u5kROTpgGki/VJfuD+qk/whlomBqIUP0VDJ+G0t24spJZ?= =?us-ascii?q?u2T1RgYdOpOJBZsSacNoB/RoUpRGQ+63Vy8aEPpZPuJHtC858g3ROKLqXfK4U?= =?us-ascii?q?=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0FPBQDdwB9X/3/oP4heHYMbgVCCc7Jkg?= =?us-ascii?q?hmLYkwBAQEBAQECAmIngi2CFQEFJ1IQCBA5LCsGARKIKsRnhiGIZIV8BY5IiUi?= =?us-ascii?q?BVYxEiU+FQEWOa2KBNgFOG4FpHjABh2+BPgEBAQ?= X-IPAS-Result: =?us-ascii?q?A0FPBQDdwB9X/3/oP4heHYMbgVCCc7JkghmLYkwBAQEBAQE?= =?us-ascii?q?CAmIngi2CFQEFJ1IQCBA5LCsGARKIKsRnhiGIZIV8BY5IiUiBVYxEiU+FQEWOa?= =?us-ascii?q?2KBNgFOG4FpHjABh2+BPgEBAQ?= X-IronPort-AV: E=Sophos;i="5.24,537,1454976000"; d="scan'208";a="15642330" Received: from unknown (HELO ubuntu-hedt) ([136.63.232.127]) by emsm-gh1-uea11.nsa.gov with ESMTP; 26 Apr 2016 19:30:50 +0000 Received: by ubuntu-hedt (Postfix, from userid 1000) id 775FE302399; Tue, 26 Apr 2016 14:30:50 -0500 (CDT) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro , Serge Hallyn , James Morris , "Serge E. Hallyn" Subject: [PATCH v4 08/21] userns: Replace in_userns with current_in_userns Date: Tue, 26 Apr 2016 14:30:31 -0500 Message-Id: <1461699046-30485-9-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1461699046-30485-1-git-send-email-seth.forshee@canonical.com> References: <1461699046-30485-1-git-send-email-seth.forshee@canonical.com> X-Mailman-Approved-At: Tue, 26 Apr 2016 15:34:29 -0400 X-BeenThere: selinux@tycho.nsa.gov X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Security-Enhanced Linux \(SELinux\) mailing list" List-Post: List-Help: Cc: Miklos Szeredi , Seth Forshee , dm-devel@redhat.com, linux-security-module@vger.kernel.org, Richard Weinberger , linux-bcache@vger.kernel.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org, fuse-devel@lists.sourceforge.net, Austin S Hemmelgarn , linux-mtd@lists.infradead.org, selinux@tycho.nsa.gov, linux-fsdevel@vger.kernel.org, cgroups@vger.kernel.org, Pavel Tikhomirov MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP All current callers of in_userns pass current_user_ns as the first argument. Simplify by replacing in_userns with current_in_userns which checks whether current_user_ns is in the namespace supplied as an argument. Signed-off-by: Seth Forshee Acked-by: James Morris Acked-by: Serge Hallyn --- fs/namespace.c | 2 +- include/linux/user_namespace.h | 6 ++---- kernel/user_namespace.c | 6 +++--- security/commoncap.c | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index 6e9db4c166b4..0ad8e4a4f50b 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -3294,7 +3294,7 @@ bool mnt_may_suid(struct vfsmount *mnt) * in other namespaces. */ return !(mnt->mnt_flags & MNT_NOSUID) && check_mnt(real_mount(mnt)) && - in_userns(current_user_ns(), mnt->mnt_sb->s_user_ns); + current_in_userns(mnt->mnt_sb->s_user_ns); } static struct ns_common *mntns_get(struct task_struct *task) diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h index a43faa727124..9217169c64cb 100644 --- a/include/linux/user_namespace.h +++ b/include/linux/user_namespace.h @@ -72,8 +72,7 @@ extern ssize_t proc_projid_map_write(struct file *, const char __user *, size_t, extern ssize_t proc_setgroups_write(struct file *, const char __user *, size_t, loff_t *); extern int proc_setgroups_show(struct seq_file *m, void *v); extern bool userns_may_setgroups(const struct user_namespace *ns); -extern bool in_userns(const struct user_namespace *ns, - const struct user_namespace *target_ns); +extern bool current_in_userns(const struct user_namespace *target_ns); #else static inline struct user_namespace *get_user_ns(struct user_namespace *ns) @@ -103,8 +102,7 @@ static inline bool userns_may_setgroups(const struct user_namespace *ns) return true; } -static inline bool in_userns(const struct user_namespace *ns, - const struct user_namespace *target_ns) +static inline bool current_in_userns(const struct user_namespace *target_ns) { return true; } diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c index dee3be5445da..68f594212759 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -942,10 +942,10 @@ bool userns_may_setgroups(const struct user_namespace *ns) * Returns true if @ns is the same namespace as or a descendant of * @target_ns. */ -bool in_userns(const struct user_namespace *ns, - const struct user_namespace *target_ns) +bool current_in_userns(const struct user_namespace *target_ns) { - for (; ns; ns = ns->parent) { + struct user_namespace *ns; + for (ns = current_user_ns(); ns; ns = ns->parent) { if (ns == target_ns) return true; } diff --git a/security/commoncap.c b/security/commoncap.c index a306c5d90709..e657227d221e 100644 --- a/security/commoncap.c +++ b/security/commoncap.c @@ -461,7 +461,7 @@ static int get_file_caps(struct linux_binprm *bprm, bool *effective, bool *has_c * explicit that capability bits are limited to s_user_ns and its * descendants. */ - if (!in_userns(current_user_ns(), bprm->file->f_path.mnt->mnt_sb->s_user_ns)) + if (!current_in_userns(bprm->file->f_path.mnt->mnt_sb->s_user_ns)) return 0; rc = get_vfs_caps_from_disk(bprm->file->f_path.dentry, &vcaps);