From patchwork Mon Dec 7 21:21:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7791881 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 532D3BEEE1 for ; Mon, 7 Dec 2015 22:29:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 92D462055B for ; Mon, 7 Dec 2015 22:29:28 +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 7223320555 for ; Mon, 7 Dec 2015 22:29:27 +0000 (UTC) X-TM-IMSS-Message-ID: <3e894aae0002922a@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 3e894aae0002922a ; Mon, 7 Dec 2015 17:27:33 -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 tB7MRWW1007291; Mon, 7 Dec 2015 17:27:33 -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 tB7LQ9CY263187 for ; Mon, 7 Dec 2015 16:26:09 -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 tB7LOYBM001477 for ; Mon, 7 Dec 2015 16:26:09 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1CgBABD9WVW/6rfVdFeGQEBAQEPAQEBAYRLuxeEDwcXhXcCghMBAQEBAQGFQAEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDaJHgTE+MYpXhVQBBYt1AQEBAQEBAQMCARoGCoQ6ghCMOgxBgTGOJIhClk2GIYtuNoEXY4IEDR2BdVMBhW4BAQE X-IPAS-Result: A1CgBABD9WVW/6rfVdFeGQEBAQEPAQEBAYRLuxeEDwcXhXcCghMBAQEBAQGFQAEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDaJHgTE+MYpXhVQBBYt1AQEBAQEBAQMCARoGCoQ6ghCMOgxBgTGOJIhClk2GIYtuNoEXY4IEDR2BdVMBhW4BAQE X-IronPort-AV: E=Sophos;i="5.20,396,1444708800"; d="scan'208";a="5004900" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 07 Dec 2015 16:23:25 -0500 X-TM-IMSS-Message-ID: <3e4e828e0002801a@nsa.gov> Received: from mail-io0-f170.google.com (mail-io0-f170.google.com [209.85.223.170]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 3e4e828e0002801a ; Mon, 7 Dec 2015 16:23:21 -0500 Received: by ioc74 with SMTP id 74so3998289ioc.2 for ; Mon, 07 Dec 2015 13:23:23 -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=iskkmDiMtrfqY4q/n1NV3RNOa5/IA7tN2X/mXj9nJrY=; b=a7ldi+sf2d4jgYlz/oWPDvPMK5KXunYuKihKpTXBRWvc7YyEGg9FfoN2LjdHEucK8s gi15xdxY0Ui8bwyLy3XkXSBd8V7r2JN7M3tJ5Jt3+J94WilRiXOWZ84CBrqdievI1KYW qJL0rTkPfXLaoU4rAOGz17zTOP7CyS3caXEw0gdbav9PN81WIwlghvOC/5HxtsTjEUZw AYDTsVYINvOTVEFGJkgj1xcm7HMamcZmAAZE8o1k4I4t+cmnnUaGfygDkm5OvL2jlUM9 MBZDHgG+dympWOXdy4UUAwBIX3bg9aaa7qGGn3i0OkXjcvl5yhgkqqUCr7HrXwTLwhgE CLvw== 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=iskkmDiMtrfqY4q/n1NV3RNOa5/IA7tN2X/mXj9nJrY=; b=UQAeoBgNzVVn3hReB28YutFgFipawFwNB+hv/iXqtNGL37FCzr2JPrxHHs6lT5qBS6 0q8WEG7RoWwJqFs4MqHNegIk1hQRTpejOFHxs8AGpTpuklq5g0OWhepkhumYCChQ89In Ax+7jMe1wWXr0u2plGBrojHlowDWIJlP/WC4wazaudtrC/dzGH38OAK+HdzXhu5NuKBx x9ZOOkDQCvaRTjU7k/gKlBJoSnePRCTJr8rDzEE6Z1pqF68p2TWji1/2VxFq+rPLLPse JN2Js/CPr45r11abfTZcI3R5bEOwY4MgIQPNpBK8c+7dSbhKKmF6ZxwcXM9eyn+2oYzl y/WA== X-Gm-Message-State: ALoCoQlSvCw70YMxdB4Gqv2Lz2AH3/3w6idx23NQdinQm353AGxsFv0hYwrcBigNxf0nuqrdkxv96fKbRiGFij+W2xL+W+3S+g== X-Received: by 10.107.138.16 with SMTP id m16mr541854iod.40.1449523403545; Mon, 07 Dec 2015 13:23:23 -0800 (PST) Received: from localhost (199-87-125-144.dyn.kc.surewest.net. [199.87.125.144]) by smtp.gmail.com with ESMTPSA id a5sm7089064iga.7.2015.12.07.13.23.22 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 07 Dec 2015 13:23:23 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro , Serge Hallyn , James Morris , "Serge E. Hallyn" Subject: [PATCH v2 05/18] userns: Replace in_userns with current_in_userns Date: Mon, 7 Dec 2015 15:21:14 -0600 Message-Id: <1449523289-144238-6-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1449523289-144238-1-git-send-email-seth.forshee@canonical.com> References: <1449523289-144238-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Mon, 07 Dec 2015 16:44:28 -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);