From patchwork Fri Apr 24 16:20:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 1276481 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ubuntu.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 497zwC5VkZz9sSY for ; Sat, 25 Apr 2020 02:22:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728757AbgDXQWS (ORCPT ); Fri, 24 Apr 2020 12:22:18 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:58670 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728561AbgDXQWH (ORCPT ); Fri, 24 Apr 2020 12:22:07 -0400 Received: from ip5f5af183.dynamic.kabel-deutschland.de ([95.90.241.131] helo=wittgenstein.fritz.box) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jS15Y-0004dV-8F; Fri, 24 Apr 2020 16:22:04 +0000 From: Christian Brauner To: Jens Axboe , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-api@vger.kernel.org Cc: Jonathan Corbet , Serge Hallyn , "Rafael J. Wysocki" , Tejun Heo , "David S. Miller" , Christian Brauner , Saravana Kannan , Jan Kara , David Howells , Seth Forshee , David Rheinsberg , Tom Gundersen , Christian Kellner , Dmitry Vyukov , =?utf-8?q?St=C3=A9phane_Graber?= , linux-doc@vger.kernel.org, netdev@vger.kernel.org, Steve Barber , Dylan Reid , Filipe Brandenburger , Kees Cook , Benjamin Elder , Akihiro Suda Subject: [PATCH v3 7/7] loopfs: only show devices in their correct instance Date: Fri, 24 Apr 2020 18:20:52 +0200 Message-Id: <20200424162052.441452-8-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200424162052.441452-1-christian.brauner@ubuntu.com> References: <20200424162052.441452-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Since loopfs devices belong to a loopfs instance they have no business polluting the host's devtmpfs mount and should not propagate out of the namespace they belong to. Cc: Jens Axboe Cc: Greg Kroah-Hartman Reviewed-by: Serge Hallyn Signed-off-by: Christian Brauner --- /* v2 */ unchanged /* v3 */ unchanged --- block/partitions/core.c | 1 + drivers/base/devtmpfs.c | 4 ++-- drivers/block/loopfs/loopfs.c | 4 +++- include/linux/device.h | 3 +++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/block/partitions/core.c b/block/partitions/core.c index bc1ded1331b1..5761f5c38588 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -416,6 +416,7 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno, pdev->class = &block_class; pdev->type = &part_type; pdev->parent = ddev; + pdev->no_devnode = ddev->no_devnode; err = blk_alloc_devt(p, &devt); if (err) diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c index c9017e0584c0..77371ceb88fa 100644 --- a/drivers/base/devtmpfs.c +++ b/drivers/base/devtmpfs.c @@ -111,7 +111,7 @@ int devtmpfs_create_node(struct device *dev) const char *tmp = NULL; struct req req; - if (!thread) + if (!thread || dev->no_devnode) return 0; req.mode = 0; @@ -138,7 +138,7 @@ int devtmpfs_delete_node(struct device *dev) const char *tmp = NULL; struct req req; - if (!thread) + if (!thread || dev->no_devnode) return 0; req.name = device_get_devnode(dev, NULL, NULL, NULL, &tmp); diff --git a/drivers/block/loopfs/loopfs.c b/drivers/block/loopfs/loopfs.c index 9fa60c1bcc05..1bcb0b44c910 100644 --- a/drivers/block/loopfs/loopfs.c +++ b/drivers/block/loopfs/loopfs.c @@ -76,8 +76,10 @@ bool loopfs_wants_remove(const struct loop_device *lo) void loopfs_init(struct gendisk *disk, struct inode *inode) { - if (loopfs_i_sb(inode)) + if (loopfs_i_sb(inode)) { disk->user_ns = loopfs_i_sb(inode)->s_user_ns; + disk_to_dev(disk)->no_devnode = true; + } } /** diff --git a/include/linux/device.h b/include/linux/device.h index ac8e37cd716a..c69ef1c5a0ef 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -523,6 +523,8 @@ struct dev_links_info { * sync_state() callback. * @dma_coherent: this particular device is dma coherent, even if the * architecture supports non-coherent devices. + * @no_devnode: whether device nodes associated with this device are kept out + * of devtmpfs (e.g. due to separate filesystem) * * At the lowest level, every device in a Linux system is represented by an * instance of struct device. The device structure contains the information @@ -622,6 +624,7 @@ struct device { defined(CONFIG_ARCH_HAS_SYNC_DMA_FOR_CPU_ALL) bool dma_coherent:1; #endif + bool no_devnode:1; }; static inline struct device *kobj_to_dev(struct kobject *kobj)