From patchwork Tue Nov 17 16:39:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7640101 Return-Path: X-Original-To: patchwork-selinux@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E3F7C9F392 for ; Tue, 17 Nov 2015 17:25:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 358052049E for ; Tue, 17 Nov 2015 17:25:41 +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 3C1A7204E4 for ; Tue, 17 Nov 2015 17:25:40 +0000 (UTC) X-TM-IMSS-Message-ID: <32594d5c00055609@nsa.gov> Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by nsa.gov ([63.239.67.9]) with ESMTP (TREND IMSS SMTP Service 7.1) id 32594d5c00055609 ; Tue, 17 Nov 2015 12:23:47 -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 tAHHNcVb010346; Tue, 17 Nov 2015 12:23:42 -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 tAHGeRQO018639 for ; Tue, 17 Nov 2015 11:40:27 -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 tAHGeRBp005656 for ; Tue, 17 Nov 2015 11:40:27 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1AwBQCOVktW/7DVVdFeGQEBAg8BAQEBgwuBQrxHhA2GDwKBUEwBAQEBAQGFQAEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDAWeCIExPjGKV4VUAQWLTwEBAQEBAQEDAgEaBgqEOoIQjjeOFog4ljiGH4tMNoEXY4IEDR2BdVMBhQkBAQE X-IPAS-Result: A1AwBQCOVktW/7DVVdFeGQEBAg8BAQEBgwuBQrxHhA2GDwKBUEwBAQEBAQGFQAEBAQMSFRkBATcBD1E0AQUBHAYBEiKIDAWeCIExPjGKV4VUAQWLTwEBAQEBAQEDAgEaBgqEOoIQjjeOFog4ljiGH4tMNoEXY4IEDR2BdVMBhQkBAQE X-IronPort-AV: E=Sophos;i="5.20,308,1444708800"; d="scan'208";a="4940874" Received: from emvm-gh1-uea09.nsa.gov ([63.239.67.10]) by goalie.tycho.ncsc.mil with ESMTP; 17 Nov 2015 11:40:13 -0500 X-TM-IMSS-Message-ID: <322a831b00051605@nsa.gov> Received: from mail-ig0-f176.google.com (mail-ig0-f176.google.com [209.85.213.176]) by nsa.gov ([63.239.67.10]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 322a831b00051605 ; Tue, 17 Nov 2015 11:41:27 -0500 Received: by igcph11 with SMTP id ph11so82749206igc.1 for ; Tue, 17 Nov 2015 08:40:12 -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=SkUEOy/+bMHH6lGCaY0ndjUGVZ7HktFyeBtvm5KsdD0=; b=otil1+kvniUBcPCWBy60sZcw5okH5Z1aBxxlH66Qlof0gejBImiG0f+P4Tsf5vDTRf vzpfWD+v0u3eNhLbZu2wWnqZozcoZFNctnZCMDAFJaOpdHzJyQnn1bwO+ZKDWJErqj/r X0suNQLpFctcE/uIMkn2P0RldZKRTehyPwZhlu+GFSrj8JTky0ZbY2QaG4272lLU42kv 7tPWV2Gdz5VNXQxOlktSaScxKnLd+CCRiqp4Vihr/j3KDdIX38RzUlspw0PT78o2PbqN WxvNySrdSHqW7ujHAsoeWz3i94oMCDnEtrY/cl97ax5+8lm/A5HGVpfXQYRrZHFCoEdg NvAA== 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=SkUEOy/+bMHH6lGCaY0ndjUGVZ7HktFyeBtvm5KsdD0=; b=YLaRoDliw/syX30NygT9VytebEy0njI5mL1zANh9HE6CoCu4aGDp6Krn0andWMgz5I ImssyLIIVeVMto6IYM2597bWYmldDN+rZFcz4SY3C1FFWzUpc1lpvASmuzDZf+kgM7XF U44CT7+6DFAh6p6o1E5OmxUt915JNnCr7BiPZqOnUqN3l1DLxMmwtWeMwR9QQbK+VKr8 G6Z2TdGJh8Ip9O41b0SxceHOJeDMrRN47ItRoybTOvETnrOG7rrUa72rnLvn7+/VokAh UN9UbxtqDQ6RM+5m6wkYRnKuEuTE7okeePknNDh/6Gnr6HaCXuGqz/oO6OYRvY+9gbDT dM4w== X-Gm-Message-State: ALoCoQkzIL9xng/CdZEruIaE9O4SFtZXFbJMlBkpc0swvYScO772ZUUCExC9SmB6J8A2AnuBuio7 X-Received: by 10.50.79.201 with SMTP id l9mr2972341igx.60.1447778411923; Tue, 17 Nov 2015 08:40:11 -0800 (PST) Received: from localhost (199-87-125-144.dyn.kc.surewest.net. [199.87.125.144]) by smtp.gmail.com with ESMTPSA id c92sm13970166iod.0.2015.11.17.08.40.11 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 17 Nov 2015 08:40:11 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro , Serge Hallyn , James Morris , "Serge E. Hallyn" Subject: [PATCH v3 6/7] userns: Replace in_userns with current_in_userns Date: Tue, 17 Nov 2015 10:39:09 -0600 Message-Id: <1447778351-118699-7-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1447778351-118699-1-git-send-email-seth.forshee@canonical.com> References: <1447778351-118699-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Tue, 17 Nov 2015 12:08:01 -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, dm-devel@redhat.com, linux-kernel@vger.kernel.org, Andy Lutomirski , linux-raid@vger.kernel.org, Seth Forshee , linux-bcache@vger.kernel.org, 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=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,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 --- 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);