From patchwork Tue Apr 26 19:36:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 8944541 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 86ED6BF29F for ; Tue, 26 Apr 2016 20:12:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C07372014A for ; Tue, 26 Apr 2016 20:12:51 +0000 (UTC) Received: from emsm-gh1-uea11.nsa.gov (emsm-gh1-uea11.nsa.gov [8.44.101.9]) by mail.kernel.org (Postfix) with ESMTP id 1BA2F20138 for ; Tue, 26 Apr 2016 20:12:50 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.24,538,1454976000"; d="scan'208";a="15644064" IronPort-PHdr: =?us-ascii?q?9a23=3AnS75jBdlofjrI/yb9phtDGKslGMj4u6mDksu8pMi?= =?us-ascii?q?zoh2WeGdxci/Yx7h7PlgxGXEQZ/co6odzbGG4+a/CCdZusjJmUtBWaIPfidNsd?= =?us-ascii?q?8RkQ0kDZzNImzAB9muURYHGt9fXkRu5XCxPBsdMs//Y1rPvi/6tmZKSV3BPAZ4?= =?us-ascii?q?bt74BpTVx5zukbviq9uMMk4R32T1SIgxBSv1hD2ZjtMRj4pmJ/R54TryiVwMRd?= =?us-ascii?q?5rw3h1L0mYhRf265T41pdi9yNNp6BprJYYAu3SNp41Rr1ADTkgL3t9pIiy7UGC?= =?us-ascii?q?HkOz4S5Wf38XmVJ3RUDv7Rz2U430uy2w/r5w0iiXMcDsSJgkXDW59KZsTlnjjy?= =?us-ascii?q?JRc3YQ9GzHg8p8gbgTnhO7oFQr3Y/OZ6mHOfx/YOXZfNUHVSxGRMkXSi8XRsuH?= =?us-ascii?q?YpEAAqIhNOJcvo+180ADtxSzQwmlAOf+zBdDj3nx26wx2uBnGgbDikhoPdsLvW?= =?us-ascii?q?+cidLvLqYJGbS3xazF1nPHKfZRwy3886DPaBkqpfzKVrV1J46Zg3IiDQzIxnjW?= =?us-ascii?q?4azsOzeE0K5F53OW9eVtfeKmj2o2rUd6pT35lek2jYycvY8Jyhjq8j9iwIs4bY?= =?us-ascii?q?mjRVJ7J9CjCoBQuiyyPIJwRcUjSGhs/i09z+tV6taAYCEWxcF/lFbkYPudft3N?= =?us-ascii?q?u0q7WQ=3D=3D?= X-IPAS-Result: =?us-ascii?q?A2EKBQBzyh9X/wHyM5BeHAGCcCuBULVVhiIfgXaFRUwBAQE?= =?us-ascii?q?BAQECAmIngi19Wz0BAQEDAQIPFRMGAQEMIAsBAgMJAQEXKQgIAwEtAwEFAQsRB?= =?us-ascii?q?gEHCwUYBAGICAGlVYExPjGKT4UoAQSMRgEBAQcBAQEBFgYKhA2CCohaCgcBhXS?= =?us-ascii?q?OTYlIgVWMRIkqJYVARY0tMIEOYoIFG4FpTgGHbwkXgR4BAQE?= Received: from unknown (HELO tarius.tycho.ncsc.mil) ([144.51.242.1]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Apr 2016 20:12:48 +0000 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 u3QKClFI021825; Tue, 26 Apr 2016 16:12:48 -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 u3QJb0IE172303 for ; Tue, 26 Apr 2016 15:37:00 -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 u3QJakxt011587 for ; Tue, 26 Apr 2016 15:36:59 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0A+BQD9wR9X/yUp0ApeHYJwK4FQtVeCGYQRhg8CgUBMAQEBAQEBZieEQgEBAQMSFRkBATcBD1E0AQUBHAYBEiKICAGlV4ExPjGKT4UoAQSMSgEBAQEBAQEDAgEXBgqEDYIKiGSFfI5NiUiBVYxEiSqFZUWNLTCBDmKBeA0bgWlOAYdvgT4BAQE X-IPAS-Result: A0A+BQD9wR9X/yUp0ApeHYJwK4FQtVeCGYQRhg8CgUBMAQEBAQEBZieEQgEBAQMSFRkBATcBD1E0AQUBHAYBEiKICAGlV4ExPjGKT4UoAQSMSgEBAQEBAQEDAgEXBgqEDYIKiGSFfI5NiUiBVYxEiSqFZUWNLTCBDmKBeA0bgWlOAYdvgT4BAQE X-IronPort-AV: E=Sophos;i="5.24,537,1454994000"; d="scan'208";a="5410380" 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; 26 Apr 2016 15:37:00 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AXPEpMR3FBUx3kL8IsmDT+DRfVm0co7zxezQtwd8Z?= =?us-ascii?q?se4TLfad9pjvdHbS+e9qxAeQG96Lu7Qb2qGP6PiocFdDyKjCmUhKSIZLWR4BhJ?= =?us-ascii?q?detC0bK+nBN3fGKuX3ZTcxBsVIWQwt1Xi6NU9IBJS2PAWK8TWM5DIfUi/yKRBy?= =?us-ascii?q?brysXNWC34LohqvroMWbSj4LrQT+SIs6FA+xowTVu5teqqpZAYF19CH0pGBVcf?= =?us-ascii?q?9d32JiKAHbtR/94sCt4MwrqHwI6LoJvvRNWqTifqk+UacQTHF/azh0t4XXskyJ?= =?us-ascii?q?YBGO7TMjFC08kxdEDhLA5RewFsP8uCr3uudn3QGKOMztVrEzX3Kp6KI9DFfBjC?= =?us-ascii?q?oXPjg1/XuftM1qi+oPvhO7oDRtzojVfseRNfxjbuXaZ9xcWGkXGo5qWjZOD8uc?= =?us-ascii?q?Zo8LHuxJaf1VtYbw4VsHqR+vAyGnDeXozD5Dj3uw1qo/haBpMwjD0RdoOtUUqn?= =?us-ascii?q?XP5IH3PaIfSqaxiqzP1y/CdNtRwz727IWOeRck97XEF4l9a8XcgWRpXyPMilGB?= =?us-ascii?q?r8atayiYzOsAm2iS6+5xU6SkjGtx+C9rpT36/cowisHngZgOyl3JvXFizZo1Y9?= =?us-ascii?q?O/UlV7bNOMG5JWsCebPIJyBMglRjc7624B1rQatMvjL2Axw5M9ykuaMqTffg?= =?us-ascii?q?=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0HzAAD9wR9Xj63VVdFeHYJwgXu1V4IZh?= =?us-ascii?q?AkIF4F2hAICgUBMAQEBAQEBAgIPAQEBAQcLCwkhL4ItfVs9AQEBAxIVGQEBNwE?= =?us-ascii?q?PUTQBBQEcBgESIogIAaVXgTE+MYpPhSgBBIxKAQEBAQEBAQMCARcGCoQNggqIZ?= =?us-ascii?q?IJuC0CCQ45NiUiBVYxEiSqFZUWNLTCBDoJaDREKgWlOAYdvgT4BAQE?= X-IPAS-Result: =?us-ascii?q?A0HzAAD9wR9Xj63VVdFeHYJwgXu1V4IZhAkIF4F2hAICgUB?= =?us-ascii?q?MAQEBAQEBAgIPAQEBAQcLCwkhL4ItfVs9AQEBAxIVGQEBNwEPUTQBBQEcBgESI?= =?us-ascii?q?ogIAaVXgTE+MYpPhSgBBIxKAQEBAQEBAQMCARcGCoQNggqIZIJuC0CCQ45NiUi?= =?us-ascii?q?BVYxEiSqFZUWNLTCBDoJaDREKgWlOAYdvgT4BAQE?= X-IronPort-AV: E=Sophos;i="5.24,537,1454976000"; d="scan'208";a="15642552" Received: from mail-ig0-f173.google.com ([209.85.213.173]) by emsm-gh1-uea11.nsa.gov with ESMTP/TLS/AES128-GCM-SHA256; 26 Apr 2016 19:36:58 +0000 Received: by mail-ig0-f173.google.com with SMTP id g8so25520363igr.0 for ; Tue, 26 Apr 2016 12:36:58 -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=XN0VEjNp7CAxfuE3oWm8eRX9UvQ5a9jIhWtwswECLLw=; b=SZ7tex4/WLx7C78g5S4kw6Mzw2aSk9W2wv+V5DAGxy6ttPwo1Dhw9/YHBw+20OdL3n mrreeNw58JQbjyQmjUTqFStKpa3CkOf7/3vRjAqxpN/6sO5pdaSdBPRZQm02DAKoRr3V EVBkP5VQoo43CnquHsT0VYZ4qXzkXb1K/aUxG7819BQf/z8mN+v0nmACGzO7UrkoCf9s qsK7X9MExsTWIYZlH4h40GPd1ceiLrPN5+kvQTclLmLfwOB74CCexHWqjC6ZhsJ6jng1 aio+eeMp8900yooD75di9VQ0EWIQXpe8SZ2npnEa456CC6MOhQuCDyw7xXfb1Dk5vS48 sPZw== 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=XN0VEjNp7CAxfuE3oWm8eRX9UvQ5a9jIhWtwswECLLw=; b=Txd1DfRYrZbjLvj1yUoVv7prdONQbCzWdAJHzcw3lvuwaLy+uXOZoS/CLDvPsv4o+g E6dRXxSV0waOwrZIfOMGFEdTSKcj3VxZbFNkr8+gA4pQKTn4OMZcDOWm+k/EFI+dY1UO aChKLr5m8EmqzKyPE9/t2Z35eThbkUnTIZOO/rEpaUWl95PUP+aZIhYjxBG2JFAbfWmR O7oMHcjRYGc1HLjsH6ms03l/JU/io/UGWDqCionP8Ma/tUPEvvBqNruNqqAUeqzBXqCy g5sKya5fxVEIfN/4w6ct6sfICj4VvO+jDht9mygWiWDKbFJ6BEuDgG2C7feugZEgapwx NG1w== X-Gm-Message-State: AOPr4FVV3vquDSEzWtTqUlpWiR/PKT964V4+ou2KB1ss7g7x1VtZjCt8aGY6JX8mcle06wo4 X-Received: by 10.50.9.202 with SMTP id c10mr5990502igb.46.1461699418127; Tue, 26 Apr 2016 12:36:58 -0700 (PDT) Received: from localhost ([2605:a601:aab:f920:39a1:5bcf:aa:5b00]) by smtp.gmail.com with ESMTPSA id au6sm14968450igc.0.2016.04.26.12.36.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Apr 2016 12:36:57 -0700 (PDT) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro , Serge Hallyn , James Morris , "Serge E. Hallyn" Subject: [PATCH v4 08/21] userns: Replace in_userns with current_in_userns Date: Tue, 26 Apr 2016 14:36:21 -0500 Message-Id: <1461699396-33000-9-git-send-email-seth.forshee@canonical.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1461699396-33000-1-git-send-email-seth.forshee@canonical.com> References: <1461699396-33000-1-git-send-email-seth.forshee@canonical.com> X-Mailman-Approved-At: Tue, 26 Apr 2016 16:11:01 -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);