Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp815049ybb; Wed, 8 Apr 2020 10:24:04 -0700 (PDT) X-Google-Smtp-Source: APiQypLew6WyZzNbDtSsrumRlMtCQvbJpJeZV0cWLSO09WSb1KPVBp6wL2R4kWpOiQ8gy6PvwrjB X-Received: by 2002:aca:7213:: with SMTP id p19mr3393400oic.159.1586366644332; Wed, 08 Apr 2020 10:24:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586366644; cv=none; d=google.com; s=arc-20160816; b=YGTH188kK82kgtguyDR0FJ4banWPG43dPIySYR5JKqOPWl1gRZXqWIoY8KKUBUF9GA 1Paf/Kq4qoyxoxb7OvoDnSTDXEbhWZfisZPmpu4F8hkmt6sgV49F2g/te/Lhe+7w/AjD 82CMWmMbSW7FuGmDmJtPUl3aUHkEZHAlAglnh8ZDBKcqtpdAKbsGSZjmLWGrRQ1L3FA6 UvWOqSx0b7nxFDsPVymB2f1ZJIleeAyCv8wA8JfmVmumuLFyWMHTYGQYjnrX5Vw3r2e6 Hvxhym7tObAtn7jvFLuwW7ATTtC4fo8G00zhptnP771t40rscIwh5VpDH8xrOeG1eTDh LMEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0Ih7mpWRaSdssaSLAzVGXH/6SE5Lwu3TUkVzazjjd2I=; b=F1R7UmaYzOlw9+8+pBw2rPcg3TJLdncQ5MMZOPBL6tYEuhdbd5DG9BMcdO9zYSjvbH ycwW6I6TL8Q77D9LndLfpf4u19Yvk2ImlcrJJGiYr0HVDN5GOhiayl+VRPTn/7jHmmJS euDwnU7vPLvxqq1ztDv5WAOD9ysaS10Bc7NZ+E+mtYHOP/CySatSX7pnqlCROvKiVUHY AWqZQs1WqssoHxZOhuxyv+FlBOGUAQK4EGymgtRsS/ISZ/7K1ZVzGna9UwvzkXFh0FMV /u7Au3yG5MhTo23GWoT0WDExFzwq0oLbq+t45mhtgQOjKIuLEwgAUjBtM9TgysfZN70j tnzA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 109si2928602otv.36.2020.04.08.10.23.51; Wed, 08 Apr 2020 10:24:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729508AbgDHPWu (ORCPT + 99 others); Wed, 8 Apr 2020 11:22:50 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:39143 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729540AbgDHPWs (ORCPT ); Wed, 8 Apr 2020 11:22:48 -0400 Received: from ip5f5bd698.dynamic.kabel-deutschland.de ([95.91.214.152] 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 1jMCXM-0001BO-Rr; Wed, 08 Apr 2020 15:22:44 +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=20Graber?= , linux-doc@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 8/8] loopfs: only show devices in their correct instance Date: Wed, 8 Apr 2020 17:21:51 +0200 Message-Id: <20200408152151.5780-9-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200408152151.5780-1-christian.brauner@ubuntu.com> References: <20200408152151.5780-1-christian.brauner@ubuntu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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 Signed-off-by: Christian Brauner --- drivers/base/devtmpfs.c | 4 ++-- drivers/block/loop.c | 4 +++- include/linux/device.h | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) 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/loop.c b/drivers/block/loop.c index 7a14fd3e4329..df75ca4ac040 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -2155,8 +2155,10 @@ static int loop_add(struct loop_device **l, int i, struct inode *inode) disk->queue = lo->lo_queue; sprintf(disk->disk_name, "loop%d", i); #ifdef CONFIG_BLK_DEV_LOOPFS - 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; + } #endif add_disk(disk); diff --git a/include/linux/device.h b/include/linux/device.h index fa04dfd22bbc..9fa438e3e4ca 100644 --- a/include/linux/device.h +++ b/include/linux/device.h @@ -525,6 +525,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 @@ -625,6 +627,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) -- 2.26.0