From patchwork Mon Jan 4 18:03:44 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 7950071 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 4354CBEEE5 for ; Mon, 4 Jan 2016 18:28:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 81AE22021B for ; Mon, 4 Jan 2016 18:28:12 +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 8F8A6201E4 for ; Mon, 4 Jan 2016 18:28:11 +0000 (UTC) X-TM-IMSS-Message-ID: <75ca8de700103df7@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 75ca8de700103df7 ; Mon, 4 Jan 2016 13:25:57 -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 u04IP13i015693; Mon, 4 Jan 2016 13:25:04 -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 u04I4KDK225738 for ; Mon, 4 Jan 2016 13:04:20 -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 u04I4Bef013312 for ; Mon, 4 Jan 2016 13:04:20 -0500 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A1DyAAAys4pWlLLVVdFeGQEBAQEPAQEBAYRJiFm1YQcYhXcCgWgBAQEBAQESAQEBAQcLCwkfhGUBAQEDEhUZAQE3AQ9RNAEFARwGARIiiA2iToExPjGKV4VUAQWMHgEBAQEBAQEDAgEaBgqEO4IRjDgMQYE2jjWIVpZqhWJEjCo1gReCaA0VB4F8UwGFDwEBAQ X-IPAS-Result: A1DyAAAys4pWlLLVVdFeGQEBAQEPAQEBAYRJiFm1YQcYhXcCgWgBAQEBAQESAQEBAQcLCwkfhGUBAQEDEhUZAQE3AQ9RNAEFARwGARIiiA2iToExPjGKV4VUAQWMHgEBAQEBAQEDAgEaBgqEO4IRjDgMQYE2jjWIVpZqhWJEjCo1gReCaA0VB4F8UwGFDwEBAQ X-IronPort-AV: E=Sophos;i="5.20,521,1444708800"; d="scan'208";a="5070750" Received: from emvm-gh1-uea08.nsa.gov ([10.208.42.193]) by goalie.tycho.ncsc.mil with ESMTP; 04 Jan 2016 13:04:19 -0500 X-TM-IMSS-Message-ID: <75b65dd300103473@nsa.gov> Received: from mail-ig0-f178.google.com (mail-ig0-f178.google.com [209.85.213.178]) by nsa.gov ([10.208.42.193]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id 75b65dd300103473 ; Mon, 4 Jan 2016 13:03:54 -0500 Received: by mail-ig0-f178.google.com with SMTP id mw1so109130897igb.1 for ; Mon, 04 Jan 2016 10:04:18 -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=NkPmEt3ZQze0wWaDcm80YnTGJQTh1CfHESIziM/qhMf0J4AljIu1ux49FtjF/jVMvu wIJVcuE8q5/hT/AoJF8KT/0tG1NLBQSaVs+8NMrHVlW7FmhPr2Kz2tDVPA4TiCCZx5mh rj4MfTr4pT+PCTp2ezAiJESbBYkwYQRJfoQHBw+0oeKZrB4d/0QcEffSiG8llMcr9oVs DBba0RXDPcHPU7fN4MOpj7vT5NBOcN+9Tn0R54YODJ0v93ijBKQZUpAipkxMO4pPan55 yXNm9TH6N6FjvL5oS7KQZoNrvUPonXm/rFg02u+oYG1HbPHxrL1rx3V5pNKbzzBqO5no p38w== 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=kF6O//6o3vkj/dGcVK6aLLyk+CWuO4Pa7INm1D+FckNcXGb9oznPYmEZDKQyoNGXQ4 VtVBn0pap9nBJ+HZwXpiFuWqUbJ9dqyI3bTv94r8vWBCjqo5161ywyU377Nx9x1jkZbg eVZEKgQLCyRXVg6wNDrSI2FzFmzdW1SEauuLM1QDBr3le+RTAPVGFmdU4j37k9Rea11f GjHj/bBtLzz7qS2woezr4evaCROWFymv4x/hvEb50xCxY+KE3zbMra4CDFSGU/S99MmQ 0Veve2UrpVDS7btFwMLpxS9e0lVXv01TvHaVdBVx1juslRFOdqHFxQ1AiXcEJZWZHWlk bfUw== X-Gm-Message-State: ALoCoQnUc2nKe7U0RfZXJ5XOhONisU59zoFhuB3UOeUG4sbkA5ZZDKq5DTOnGE1YM4va3XemdPY9rxdc81Zk5JdRFhtBtxy0LA== X-Received: by 10.50.138.74 with SMTP id qo10mr1850109igb.51.1451930657867; Mon, 04 Jan 2016 10:04:17 -0800 (PST) Received: from localhost ([66.64.121.229]) by smtp.gmail.com with ESMTPSA id p8sm14896481ioe.38.2016.01.04.10.04.17 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 04 Jan 2016 10:04:17 -0800 (PST) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro , Serge Hallyn , James Morris , "Serge E. Hallyn" Subject: [PATCH RESEND v2 05/18] userns: Replace in_userns with current_in_userns Date: Mon, 4 Jan 2016 12:03:44 -0600 Message-Id: <1451930639-94331-6-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451930639-94331-1-git-send-email-seth.forshee@canonical.com> References: <1451930639-94331-1-git-send-email-seth.forshee@canonical.com> X-TM-AS-MML: disable X-Mailman-Approved-At: Mon, 04 Jan 2016 13:14:22 -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,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 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);