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: 8913641 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 AED769F39A for ; Fri, 22 Apr 2016 15:54:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EFD3E20225 for ; Fri, 22 Apr 2016 15:54:50 +0000 (UTC) Received: from emvm-gh1-uea08.nsa.gov (emvm-gh1-uea08.nsa.gov [8.44.101.8]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9D2BE20149 for ; Fri, 22 Apr 2016 15:54:44 +0000 (UTC) X-TM-IMSS-Message-ID: <61c10eb200000a4f@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 61c10eb200000a4f ; Fri, 22 Apr 2016 11:50:37 -0400 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 u3MFpEqI008411; Fri, 22 Apr 2016 11:51:15 -0400 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 u3MFdCqc105271 for ; Fri, 22 Apr 2016 11:39:12 -0400 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 u3MFdCRB004343 for ; Fri, 22 Apr 2016 11:39:12 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CqBAA7RBpX/yUp0ApeHYJwgXu1XoIZhBCGDgKBdAEBAQEBAWYnhEIBAQEDEhUZAQE3AQ9RNAEFARwGARIiiAgBoGmBMT4xik+FKAEEjF0BAQEBAQEBAwIBFwYKhA2CCohkhXyOTIlIgVWMQYkphWVFjSwwgQ5igXgNG4FpTgGHPIE+AQEB X-IPAS-Result: A0CqBAA7RBpX/yUp0ApeHYJwgXu1XoIZhBCGDgKBdAEBAQEBAWYnhEIBAQEDEhUZAQE3AQ9RNAEFARwGARIiiAgBoGmBMT4xik+FKAEEjF0BAQEBAQEBAwIBFwYKhA2CCohkhXyOTIlIgVWMQYkphWVFjSwwgQ5igXgNG4FpTgGHPIE+AQEB X-IronPort-AV: E=Sophos;i="5.24,517,1454994000"; d="scan'208";a="5402617" Received: from emsm-gh1-uea11.corp.nsa.gov (HELO emsm-gh1-uea11.nsa.gov) ([10.208.41.37]) by goalie.tycho.ncsc.mil with ESMTP; 22 Apr 2016 11:39:11 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AheWBdR10kY4LnYo0smDT+DRfVm0co7zxezQtwd8Z?= =?us-ascii?q?se4TL/ad9pjvdHbS+e9qxAeQG96Lu7Qb06GG7+jJYi8p39WoiDg6aptCVhsI24?= =?us-ascii?q?09vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6kO74TNaIBjjLw09?= =?us-ascii?q?fr2zQd6CyZvvnLDus7ToICx2xxOFKYtoKxu3qQiD/uI3uqBFbpgL9x3Sv3FTcP?= =?us-ascii?q?5Xz247bXianhL7+9vitMU7q3cYk7sb+sVBSaT3ebgjBfwdVWx+cjN92Mq+/zTZ?= =?us-ascii?q?TADH2T1UeGQbnhdSBgHDplmuU53wvyf3rO9VyCybJtb3SrZyUjOnueMjYRvlmC?= =?us-ascii?q?4BOzMjuF/WkMs42LxauhWJtRF5wpCSZICTKeo4ebnSO84ZEy4JZctLWCEJIoq4?= =?us-ascii?q?a5oJR74aMPxXos/9rl8KvB2WDgCqA+XuwTZMwHTx2Pt+m8YoFAzdlCknBcgPqz?= =?us-ascii?q?yArtzwObxUVaawy7PSzC7raOlf0jPwroPPd0Zl6bu3UKh/fIL8jwEPHgfBn1Pa?= =?us-ascii?q?4dj+Mima28wNumyf/uwmXuWq3T0JsQZ09wOi2sdkpI7TnYIYxxiQ7ihlwMA7Is?= =?us-ascii?q?ejSEN2SdWtFpxWtiqTM819RcZ0EDIggzoz1rBT4c3zRyMN0plygkeHM/E=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A1EjAQCfQhpXjzPaVdFeHYJwgXu1XoIZh?= =?us-ascii?q?AgIF4F2hAECgXQBAQEBAQECAg8BAQEBBwsLCSGCXH1bPQEBAQMSFRkBATcBD1E?= =?us-ascii?q?0AQUBHAYBEiKICAGgbIExPjGKT4UoAQSMXQEBAQEBAQEDAgEXBgqEDYIKiGSCb?= =?us-ascii?q?gtAgkOOTIlIgVWMQYkphWVFjSwwgQ6CWg0RCoFpTgGHPIE+AQEB?= X-IPAS-Result: =?us-ascii?q?A1EjAQCfQhpXjzPaVdFeHYJwgXu1XoIZhAgIF4F2hAECgXQ?= =?us-ascii?q?BAQEBAQECAg8BAQEBBwsLCSGCXH1bPQEBAQMSFRkBATcBD1E0AQUBHAYBEiKIC?= =?us-ascii?q?AGgbIExPjGKT4UoAQSMXQEBAQEBAQEDAgEXBgqEDYIKiGSCbgtAgkOOTIlIgVW?= =?us-ascii?q?MQYkphWVFjSwwgQ6CWg0RCoFpTgGHPIE+AQEB?= X-IronPort-AV: E=Sophos;i="5.24,517,1454976000"; d="scan'208";a="15532478" Received: from emvm-gh1-uea09.nsa.gov ([10.208.42.194]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-SHA; 22 Apr 2016 15:39:10 +0000 X-TM-IMSS-Message-ID: Received: from mail-oi0-f51.google.com (mail-oi0-f51.google.com [209.85.218.51]) by nsa.gov ([10.208.42.194]) with ESMTP (TREND IMSS SMTP Service 7.1; TLSv1/SSLv3 AES128-SHA (128/128)) id ad9463730000062c ; Fri, 22 Apr 2016 11:38:44 -0400 Received: by mail-oi0-f51.google.com with SMTP id p188so136859130oih.2 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=CGf2hyWQF1dGxeKJZjT0Cj5NUWZY+Iez3fKQLW64pQLiqu4up+rM7DBUaNbOUG7q8O IiOXUeLydaVkdZERTziXXM/fiOMqWjvqGBel8w+sXVajsDnMpL5rjmXp3uGVKDzquDrf YkcEJu9Eyr5PMJaV7Cf6FAejQ6wuqWEkS1lKqypNhxEtIjHQYc/l9xxB3TOQQ5fMpoe2 gM/JJYmSIrrWQw0P46lcqqXrNOIpv/8x+btLNfzmNZr7d7FXzbn8hgBOwQhimvJAblth FXgIBbOcItrZYqmT4uByoq4+Ps29P8UHvhf4ZeqyCWL5qGwVhg4JDnrIWEgiSxGP2tNS SEHQ== X-Gm-Message-State: AOPr4FWfPwEtTTx/rjT4LD5fZIYN3OnH52kTjIULfQTZxXulYKiijK1T8LA6oCUVQE65FBiQ 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" 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> X-TM-AS-MML: disable X-Mailman-Approved-At: Fri, 22 Apr 2016 11:40:16 -0400 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: Miklos Szeredi , Seth Forshee , dm-devel@redhat.com, linux-security-module@vger.kernel.org, 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, cgroups@vger.kernel.org, Pavel Tikhomirov MIME-Version: 1.0 Errors-To: selinux-bounces@tycho.nsa.gov Sender: "Selinux" X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, 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);