From patchwork Tue Apr 26 19:36:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Seth Forshee X-Patchwork-Id: 8944481 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 A77CDBF29F for ; Tue, 26 Apr 2016 20:12:33 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E86292014A for ; Tue, 26 Apr 2016 20:12:32 +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 81A4820138 for ; Tue, 26 Apr 2016 20:12:31 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.24,538,1454976000"; d="scan'208";a="15643995" IronPort-PHdr: =?us-ascii?q?9a23=3AbMeneRRw+HtprngnYJV6XxrvANpsv+yvbD5Q0YIu?= =?us-ascii?q?jvd0So/mwa6/YhSN2/xhgRfzUJnB7Loc0qyN4/CmBj1LuM3f+Fk5M7VyFDY9wf?= =?us-ascii?q?0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5?= =?us-ascii?q?K6zPF5LIiIzvjqbpq82VPFQD3WHjKZpJbzyI7izp/vEMhoVjLqtjgjDomVBvP9?= =?us-ascii?q?ps+GVzOFiIlAz97MrjtLRq8iBXpu5zv5UYCfayV+0CQLdZFDUrNXwurI2u7EGb?= =?us-ascii?q?DFjH2nxJGEgMkxEAPE6NxhD3UprrtyL8/KIp1SObMMH7V7UcSTGj9LxqTxmugy?= =?us-ascii?q?ACYXpx2WXamsV2gK9B6CygvRs3l5DVeoa9Jvd4f72bedIcWHoHWdxeETFCVMf0?= =?us-ascii?q?QJECAKIiJ+FRr8zdrkESqBK4TV2jHu7gyT9ggn7wwL001PknHQja3QsmWdUUvy?= =?us-ascii?q?KQ5Pf4Oqlademk0K7OhWHBa/pHxTD7wJDPdRshoPyWUL5rN8zc1R9rX0nnyB26?= =?us-ascii?q?s5HuMnu71+kJv3PRp75qW+Oij2I8gw9wrzyj3co3zI7TidRRgmzJ9zh/iKY4Ip?= =?us-ascii?q?XsVExTYtO+FpZU8SaAON0yCucjC1Nlti88gukCuIy2ciEM4JQ6zgHSarqMdI3e?= =?us-ascii?q?plrBU+aYJzF1nzpadbO5igz6pUipzOvxTeG/1U5apSpK1N7WuSZe+QbU7528R+?= =?us-ascii?q?d9tmmmwy2P2g2bvvpJPUBym63BMJ4sz5Y7n5wUt0XIFyuwk0Lz2vzFPn448/Sl?= =?us-ascii?q?vry0Ko7toYWRYsot0lnz?= X-IPAS-Result: =?us-ascii?q?A2EKBQBzyh9X/wHyM5BeHAGCcCuBULt3H4F2g3iBTUwBAQE?= =?us-ascii?q?BAQECAmIngi19Wz0BAQEDAQIPFRMGAQEMIAsBAgMJAQEXKQgIAwEtAwEFAQsRB?= =?us-ascii?q?gEHCwUYBAGICAGlVYExPjGKT4UoAQSMRgEBAQcBAQEBFgYKhA2CCohaEQGFdAG?= =?us-ascii?q?NWHSJSIFVjESJKiWFQI1yMIEOYoIFGxaBU04Bh3iBNQEBAQ?= 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:29 +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 u3QKCSa8021578; Tue, 26 Apr 2016 16:12:29 -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 u3QJaqLV172288 for ; Tue, 26 Apr 2016 15:36:52 -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 u3QJakxm011587 for ; Tue, 26 Apr 2016 15:36:51 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0A+BQD9wR9X/yQp0ApeHYJwK4FQt3CEEYYPAoFATAEBAQEBAWYnhEIBAQEDEhUZAQE3AQ9RNAEFARwGARIiiAgBpVeBMT4xik+FKAEEjEoBAQEBAQEBAwIBFwYKhA2CCo5gjVl0iUiBVYxEiSqFZY1yMIEOYoF4DRsWgVNOAYktAQEB X-IPAS-Result: A0A+BQD9wR9X/yQp0ApeHYJwK4FQt3CEEYYPAoFATAEBAQEBAWYnhEIBAQEDEhUZAQE3AQ9RNAEFARwGARIiiAgBpVeBMT4xik+FKAEEjEoBAQEBAQEBAwIBFwYKhA2CCo5gjVl0iUiBVYxEiSqFZY1yMIEOYoF4DRsWgVNOAYktAQEB X-IronPort-AV: E=Sophos;i="5.24,537,1454994000"; d="scan'208";a="5410373" Received: from emsm-gh1-uea10.corp.nsa.gov (HELO emsm-gh1-uea10.nsa.gov) ([10.208.41.36]) by goalie.tycho.ncsc.mil with ESMTP; 26 Apr 2016 15:36:52 -0400 IronPort-PHdr: =?us-ascii?q?9a23=3AktAVdxydlLKUA1fXCy+O+j09IxM/srCxBDY+r6Qd?= =?us-ascii?q?1uwWIJqq85mqBkHD//Il1AaPBtWLra0VwLON6+jJYi8p39WoiDg6aptCVhsI24?= =?us-ascii?q?09vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6kO74TNaIBjjLw09?= =?us-ascii?q?fr2zQd6CyZvmnLnpo9X6WEZhunmUWftKNhK4rAHc5IE9oLBJDeIP8CbPuWZCYO?= =?us-ascii?q?9MxGlldhq5lhf44dqsrtY4q3wD89pozcNLUL37cqIkVvQYSW1+ayFmrPHs4FPu?= =?us-ascii?q?VwqErkRaGk8XnxZFGQ3M6luyCpr7syb2u/B48DmfPNbtTLcyHz+l6vEvADbshT?= =?us-ascii?q?cOMTI06inpi9Z3xPZFoQimjw5yxY/KJoWUMuduOKTHcpUHRjwFFulLWiMJIZm7?= =?us-ascii?q?ZotKL+MbIeNRqcGpqEEDohi+LQ2tAv7/xDhVgHP/waw91aImCw6QmEQCEtwA+F?= =?us-ascii?q?DdvcnyMu9GU+S83bXPyx3baPRd2Tbw8oXEaVYnrO3aGfo6U4yZ41MyHA6NoFSd?= =?us-ascii?q?rYD+dXvB3OoMvmyX9MJuVO+rh3UqsEd2uDf5go8Qh4vUgMo1x1eMoTl76IU4P9?= =?us-ascii?q?u1TAh8e9HyVNN0tmmoOoV/RIt2R2B6tSgzzJUGpJekcSlMw5MikVqXSfuHeo6O?= =?us-ascii?q?7wmra+uQJzpizCZlcbS5ig2a+k242ub8WY+zylkc/QRfldyZjX0R11T97dKcSv?= =?us-ascii?q?ZwthO61CqPkQ7U8PpELE0cnqPdLJggybc00JEUtBKQTWfNhEzqgfrOJQ0f8e+y?= =?us-ascii?q?5rGiO+2+qw=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0HzAAC5wh9Xj6/fVdFeHYJwgXu3cIQJC?= =?us-ascii?q?BeBdoQCAoFATAEBAQEBAQICDwEBAQEHCwsJIS+CLX1bPQEBAQMSFRkBATcBD1E?= =?us-ascii?q?0AQUBHAYBEiKICAGlV4ExPjGKT4UoAQSMSgEBAQEBAQEDAgEXBgqEDYIKi1ILQ?= =?us-ascii?q?IJDjVl0iUiBVYxEiSqFZY1yMIEOgloNEQoWgVNOAYktAQEB?= X-IPAS-Result: =?us-ascii?q?A0HzAAC5wh9Xj6/fVdFeHYJwgXu3cIQJCBeBdoQCAoFATAE?= =?us-ascii?q?BAQEBAQICDwEBAQEHCwsJIS+CLX1bPQEBAQMSFRkBATcBD1E0AQUBHAYBEiKIC?= =?us-ascii?q?AGlV4ExPjGKT4UoAQSMSgEBAQEBAQEDAgEXBgqEDYIKi1ILQIJDjVl0iUiBVYx?= =?us-ascii?q?EiSqFZY1yMIEOgloNEQoWgVNOAYktAQEB?= X-IronPort-AV: E=Sophos;i="5.24,537,1454976000"; d="scan'208";a="13051000" Received: from mail-io0-f175.google.com ([209.85.223.175]) by emsm-gh1-uea10.nsa.gov with ESMTP/TLS/AES128-GCM-SHA256; 26 Apr 2016 19:36:50 +0000 Received: by mail-io0-f175.google.com with SMTP id u185so30174578iod.3 for ; Tue, 26 Apr 2016 12:36:50 -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=1dSIVO74egD9bzvHFLb5rLVP0dAkHkZpfNXy4oah6MI=; b=d8yK/CGSRFYsPk7iCpNeW4Cd8oZagiqe493S5Jne6EGWre1jx3ddQDnMIXn/xuLAay Nto6zt3AcQNs22mRKaKcHV7c+BlZzv88o1Dwo9psyddtXGxpIh6DNlYo/x4+ErnG49kf QEs74PA66AOYv1kPyQnPLx/QAqJFc4l6fTIlRVYTopRfiTrzjAREVtZnORIB0M//UhfA +FG+UTaIazQyB3ZLVZ9CzdJwhmpBVfaL5F5Xkur6H6k3rLAuy1jKuO7lH9vdUvseY1Ve F2Qdi3k6Yq+3Zu2JoXVMnL648dIVza+JlWOytvUSOWrBaElQ0N3dyGXAkk1YZTJJg93G uGrQ== 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=1dSIVO74egD9bzvHFLb5rLVP0dAkHkZpfNXy4oah6MI=; b=GhLFLALja2pSWjE15Tb7imCzlFlE7Y7U3679gxapFahjuHOEU3CaUxhE5Oal4ElrJf fwMbahKDT43QQgAiYpJZ9KTtR9cljUNE9JA+/Y2tj7vDM7q9PuJtxc7f+cFNgisrgxBH Th5iDBZhZRG01+iQcYA828jgpINMseq4Jxaoj+R/qXpEdY2gJeb/XON/yCs0+YVLejtl 1XuKBXYyd3QnSaxJlth3fS1lYcucnytqBUR0YGckTaT/deSh6b444FkHvlOLI1HkoqEO a3cJR1QVZxqfCA1ma21P9Z/UK4c9iZLTsVsFpMVudl/K3sl3nLVDJm8Ee6xo3F8c775b sZHQ== X-Gm-Message-State: AOPr4FVJKUGoee/nyUyijVrNuRgUZLcio+mxO2SbiBcqAGa7TM6uwxBcTSkQznvIwzdXZZhy X-Received: by 10.107.35.3 with SMTP id j3mr6355391ioj.119.1461699410049; Tue, 26 Apr 2016 12:36:50 -0700 (PDT) Received: from localhost ([2605:a601:aab:f920:39a1:5bcf:aa:5b00]) by smtp.gmail.com with ESMTPSA id o201sm2381480ioe.15.2016.04.26.12.36.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Apr 2016 12:36:49 -0700 (PDT) From: Seth Forshee To: "Eric W. Biederman" , Alexander Viro , Greg Kroah-Hartman , Jeff Layton , "J. Bruce Fields" , Tejun Heo , Li Zefan , Johannes Weiner Subject: [PATCH v4 03/21] fs: Allow sysfs and cgroupfs to share super blocks between user namespaces Date: Tue, 26 Apr 2016 14:36:16 -0500 Message-Id: <1461699396-33000-4-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: linux-bcache@vger.kernel.org, Serge Hallyn , Seth Forshee , dm-devel@redhat.com, Miklos Szeredi , Richard Weinberger , linux-security-module@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 Both of these filesystems already have use cases for mounting the same super block from multiple user namespaces. For sysfs this happens when using criu for snapshotting a container, where sysfs is mounted in the containers network ns but the hosts user ns. The cgroup filesystem shares the same super block for all mounts of the same hierarchy regardless of the namespace. As a result, the restriction on mounting a super block from a single user namespace creates regressions for existing uses of these filesystems. For these specific filesystems this restriction isn't really necessary since the backing store is objects in kernel memory and thus the ids assigned from inodes is not subject to translation relative to s_user_ns. Add a new filesystem flag, FS_USERNS_SHARE_SB, which when set causes sget_userns() to skip the check of s_user_ns. Set this flag for the sysfs and cgroup filesystems to fix the regressions. Signed-off-by: Seth Forshee Acked-by: Serge Hallyn --- fs/super.c | 3 ++- fs/sysfs/mount.c | 3 ++- include/linux/fs.h | 1 + kernel/cgroup.c | 4 ++-- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/super.c b/fs/super.c index 092a7828442e..ead156b44bf8 100644 --- a/fs/super.c +++ b/fs/super.c @@ -472,7 +472,8 @@ retry: hlist_for_each_entry(old, &type->fs_supers, s_instances) { if (!test(old, data)) continue; - if (user_ns != old->s_user_ns) { + if (!(type->fs_flags & FS_USERNS_SHARE_SB) && + user_ns != old->s_user_ns) { spin_unlock(&sb_lock); if (s) { up_write(&s->s_umount); diff --git a/fs/sysfs/mount.c b/fs/sysfs/mount.c index f3db82071cfb..9555accd4322 100644 --- a/fs/sysfs/mount.c +++ b/fs/sysfs/mount.c @@ -59,7 +59,8 @@ static struct file_system_type sysfs_fs_type = { .name = "sysfs", .mount = sysfs_mount, .kill_sb = sysfs_kill_sb, - .fs_flags = FS_USERNS_VISIBLE | FS_USERNS_MOUNT, + .fs_flags = FS_USERNS_VISIBLE | FS_USERNS_MOUNT | + FS_USERNS_SHARE_SB, }; int __init sysfs_init(void) diff --git a/include/linux/fs.h b/include/linux/fs.h index be0f8023e28c..66a639ec1bc4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1988,6 +1988,7 @@ struct file_system_type { #define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */ #define FS_USERNS_DEV_MOUNT 16 /* A userns mount does not imply MNT_NODEV */ #define FS_USERNS_VISIBLE 32 /* FS must already be visible */ +#define FS_USERNS_SHARE_SB 64 /* Allow sharing sb between userns-es */ #define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */ struct dentry *(*mount) (struct file_system_type *, int, const char *, void *); diff --git a/kernel/cgroup.c b/kernel/cgroup.c index 671dc05c0b0f..9c9aa27e531a 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -2247,14 +2247,14 @@ static struct file_system_type cgroup_fs_type = { .name = "cgroup", .mount = cgroup_mount, .kill_sb = cgroup_kill_sb, - .fs_flags = FS_USERNS_MOUNT, + .fs_flags = FS_USERNS_MOUNT | FS_USERNS_SHARE_SB, }; static struct file_system_type cgroup2_fs_type = { .name = "cgroup2", .mount = cgroup_mount, .kill_sb = cgroup_kill_sb, - .fs_flags = FS_USERNS_MOUNT, + .fs_flags = FS_USERNS_MOUNT | FS_USERNS_SHARE_SB, }; static char *cgroup_path_ns_locked(struct cgroup *cgrp, char *buf, size_t buflen,