From patchwork Wed Dec 2 15:40:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7748461 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 29990BEEE1 for ; Wed, 2 Dec 2015 16:26:53 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6BE5D205E1 for ; Wed, 2 Dec 2015 16:26:52 +0000 (UTC) Received: from emvm-gh1-uea08.nsa.gov (emvm-gh1-uea08.nsa.gov [63.239.67.9]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5FA8120503 for ; Wed, 2 Dec 2015 16:26:51 +0000 (UTC) X-TM-IMSS-Message-ID: <237d8b0a000178c2@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1) id 237d8b0a000178c2 ; Wed, 2 Dec 2015 11:25:00 -0500 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 tB2GOlWe010844; Wed, 2 Dec 2015 11:24:49 -0500 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 tB2FgHBx185553 for ; Wed, 2 Dec 2015 10:42:17 -0500 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 tB2Fg5os006458 for ; Wed, 2 Dec 2015 10:42:17 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CgBAA0EF9W/7LfVdFeGQEBAQEPAQEBAYRMu3CEDwcXhXcCghgBAQEBAQGFQAEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDaEVgTE+MYpXhVQBBYwjAQEBAQEBAQMCARoGCoQ6ghCMOAxBgTGOIIhBlkyGIYtrNoEXY4IEDR2BdVMBhW4BAQE X-IPAS-Result: A1CgBAA0EF9W/7LfVdFeGQEBAQEPAQEBAYRMu3CEDwcXhXcCghgBAQEBAQGFQAEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDaEVgTE+MYpXhVQBBYwjAQEBAQEBAQMCARoGCoQ6ghCMOAxBgTGOIIhBlkyGIYtrNoEXY4IEDR2BdVMBhW4BAQE X-IronPort-AV: E=Sophos;i="5.20,373,1444708800"; d="scan'208";a="4986114" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 02 Dec 2015 10:42:12 -0500 X-TM-IMSS-Message-ID: <23567b6f00015eb1@nsa.gov> Received: from mail-io0-f178.google.com (mail-io0-f178.google.com [209.85.223.178]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 23567b6f00015eb1 ; Wed, 2 Dec 2015 10:42:20 -0500 Received: by iofh3 with SMTP id h3so49551839iof.3 for ; Wed, 02 Dec 2015 07:42:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ggrc89FnOJ4yw6XUTvNdR1O7b9l8mFg4Vv9S9udUL/Q=; b=msS1fzn4XNUxjkVkdYZ+1EpDJi0N3aNn7T8+w+HpJAEsZRkQLQhUj1/3ooyg4Yq5Gi JkBlHR7rtt4zF7iXrTnqdzTnrzapsJ/MiPtaLv7XoX/90Or99yIPllUkNs46O5+BzYPS uP8PksmU6Pp4ByT9MIj7MOpAwfYBd0nJUbkRyY/bmWDRBE4r4p0LEEt4/73/cs9JbZBN 1nP+oxWWU18E922fgYzfM6kPUHTdNqrUdyt68cd/2vWHMgxUQKVC4hyp8c3JO8xokxrZ KMqUPohy8copWh3U4H4SKzKYGWvqWqvnwQCnuNmiahfgBNfS88eHrxfZ+ip/TxoKq31d zXjA== 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=ggrc89FnOJ4yw6XUTvNdR1O7b9l8mFg4Vv9S9udUL/Q=; b=djF51I7rxsEuNpCCaT8hMtWtdE1F2lZpV1GzYr2hhALOg0QfK4rB5FuedMPVjbP511 nJY8U4ICGG1lxnhTJmHmqrnsgKGse4TFTVHJ4UyiQRrbM7BPrAAPnokUSHKIp5S/UvnH Mj8Ac0f4pfRGH/WZ8z0VW3eskUqjsv9BTMScOb8F/k02PIdg4uJcbPYP1RUZfAYEwhIG E/74sLd3XndN3kKuCW0uF9pOX6Gmk7VtcliTlcYDqFXooHy7oBrQavMkRqvLku6kbsDj xFT1D44fprIXWx5eCdWynVEibkFbxGI2Pn4UqLH1+LKjUBStcOSkMmoMs/Cz1emSNzA4 N5nQ== X-Gm-Message-State: ALoCoQkXPabXBuQfv9zz8EM4J1ggxHzAfxPheQ53T2rtOo6UmkrViK+tBzX/tycKI1gPSySPXzTp X-Received: by 10.107.133.204 with SMTP id p73mr5231641ioi.71.1449070930262; Wed, 02 Dec 2015 07:42:10 -0800 (PST) Received: from localhost (199-87-125-144.dyn.kc.surewest.net. [199.87.125.144]) by smtp.gmail.com with ESMTPSA id qb2sm11462007igb.10.2015.12.02.07.42.09 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 02 Dec 2015 07:42:09 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro , Serge Hallyn , James Morris , "Serge E. Hallyn" Subject: [PATCH 05/19] userns: Replace in_userns with current_in_userns Date: Wed, 2 Dec 2015 09:40:05 -0600 Message-Id: <1449070821-73820-6-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449070821-73820-1-git-send-email-seth.forshee@canonical.com> References: <1449070821-73820-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Wed, 02 Dec 2015 11:15:49 -0500 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: linux-security-module@vger.kernel.org, Seth Forshee , dm-devel@redhat.com, Miklos Szeredi , 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 MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable 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 2101ce7b96ab..18fc58760aec 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -3286,7 +3286,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 69fbc377357b..5960edc7e644 100644 --- a/kernel/user_namespace.c +++ b/kernel/user_namespace.c @@ -949,10 +949,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 6243aef5860e..2119421613f6 100644 --- a/security/commoncap.c +++ b/security/commoncap.c @@ -450,7 +450,7 @@ static int get_file_caps(struct linux_binprm *bprm, bool *effective, bool *has_c if (!mnt_may_suid(bprm->file->f_path.mnt)) return 0; - 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);