From patchwork Fri Apr 22 15:38:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 8913471 Return-Path: X-Original-To: patchwork-linux-fsdevel@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 D358ABF29F for ; Fri, 22 Apr 2016 15:50:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E490F20121 for ; Fri, 22 Apr 2016 15:50:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC5C720122 for ; Fri, 22 Apr 2016 15:50:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932242AbcDVPt5 (ORCPT ); Fri, 22 Apr 2016 11:49:57 -0400 Received: from mail-oi0-f46.google.com ([209.85.218.46]:33874 "EHLO mail-oi0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754566AbcDVPjK (ORCPT ); Fri, 22 Apr 2016 11:39:10 -0400 Received: by mail-oi0-f46.google.com with SMTP id k142so120569275oib.1 for ; Fri, 22 Apr 2016 08:39:10 -0700 (PDT) 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=ylqAUx50qbtiGyqZLZPAtVdtHNCbkqhpSpcM4iBvZGQ=; b=rSsFKefYXAQ7MERlqmznYcIK7P5LRzNPY0xzrkig9ZUX8xlVjZRQCGOorH3Ew6whVU NlUIM+FO9c7ZzSUdV/mOTrq/zKwJTJxVkejGfSl0Al8IZB9EQV30IFER1pj3OtFYj7Ei jtmmSGfvCQTxqbK0k9DV0AbMcZiX6tWHyk9A1tz6ESL92fTObgL132HSe0CCm12pTTHW tw95MCjRVprKF5ID+Q49k+PNrSRlTPal+k9J4WmpHWMxYOxklzfQzVSOd0/k7QVsYYYM sRenYS/CNjyqPJiJoH449xIsI8IeIzPke04Luj6FmnqcaBYrU4oMrv7WU2wx3BBI2hG2 KmVw== 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=ylqAUx50qbtiGyqZLZPAtVdtHNCbkqhpSpcM4iBvZGQ=; b=h/KeTXSpep5uzTio6AXghPWFJxhBq8PV1kXWfgf4Ij2webtQ/HFvkw0Sf+RAFcBczX +7QqmYRGzbuboWOb+/H/zIi2vtfp2coUQA7uA0B7+aDwpwLsOYLBwAgCBZJi5VKH4+2k oNGaupR9hHelGncMEqafIBMBTNS+/gR7uOOtHYi3YKuhPmu2E7fwjBh9QkBgLKwnUbQX 9GrEI4B7x6e1JnojtD6FcC/PU07Vdn4FxSGlIqKMNbiyYLqaaARN95KQ6sBR0HSsOFRc sVJCEccj6AHOx9Rcxl0fdDSIb/3AY7I9CvRYjw7vMkpwAC+rpLK3qcBKWTFJATzwDWRn 1H+w== X-Gm-Message-State: AOPr4FUYtb7tZrRqt/X6KRBziZODsFklyKD1TTWeEbvfUwHymocW7xvvlaH4oeNHpHQV/4Wi X-Received: by 10.157.63.70 with SMTP id m64mr768318otc.170.1461339549754; Fri, 22 Apr 2016 08:39:09 -0700 (PDT) Received: from localhost ([2605:a601:aab:f920:ad1c:41df:dcb1:a4a0]) by smtp.gmail.com with ESMTPSA id k6sm2089574oeo.10.2016.04.22.08.39.09 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 22 Apr 2016 08:39:09 -0700 (PDT) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro , Serge Hallyn , James Morris , "Serge E. Hallyn" Cc: Richard Weinberger , Austin S Hemmelgarn , Miklos Szeredi , Pavel Tikhomirov , linux-kernel@vger.kernel.org, linux-bcache@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org, fuse-devel@lists.sourceforge.net, linux-security-module@vger.kernel.org, selinux@tycho.nsa.gov, cgroups@vger.kernel.org, Seth Forshee Subject: [PATCH v3 08/21] userns: Replace in_userns with current_in_userns Date: Fri, 22 Apr 2016 10:38:25 -0500 Message-Id: <1461339521-123191-9-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1461339521-123191-1-git-send-email-seth.forshee@canonical.com> References: <1461339521-123191-1-git-send-email-seth.forshee@canonical.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-7.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 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);