Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp782886ybz; Wed, 22 Apr 2020 07:57:11 -0700 (PDT) X-Google-Smtp-Source: APiQypK8UxTjfDLUO+PvmrNkVdvEGtUPAJ21E/NxOncpmByJAZ9iWlt1kgDV6XSgKZLhzvlOnMh9 X-Received: by 2002:a50:a285:: with SMTP id 5mr22990325edm.360.1587567431667; Wed, 22 Apr 2020 07:57:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587567431; cv=none; d=google.com; s=arc-20160816; b=PhdpIGeGppqjeuR17rYc/lazIPfrx7hUb0JI7ZRBd5/VZtv+/SLYbZ9m6Q+wOt8zro ro10fz80FNIZ10r9S4YKlNcIrON7yq3GCPlNNpCUmds0h6DrzXeRwPzucFWywzN5vYUu ZTzfLDk19xPJP1dm6KbCM8O1NmwnAdRJaXck6BYcEdiCkzw1wpKm6Mi7AhkPoWTc4RY3 mTspG59iz2bKIlc0MOu5Ysq8L/7RH+dhdldzf2rQNGeeQ3sJubQjJToZ9P9kZ8ta0QPM O2blWHOB8Hru3BQYorRLbYnyKKXNRtFTbnJaYCBfUryiJqpkBgp879NmP2qZSfsHOdE3 HUeQ== 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=7C7EU5+CDf/tnX6FoftwSGls3HgQltoxEM25YxWUORo=; b=b24YsQcflFGycS265z7QP+BKEZZuV0K34A1LBSUNIi+7BIlTHTcUvrtVEKVv0QjLaD id9U0I6U66PFaWN2ttNr4k0PtPOo4Re3HV7kgzLx4o5InP8z9g45DRyQJPZoQ+kXEsr9 n24nMAHt5ZcO9eCGFrRNMAkm0c1TM4XjAdLnBncfo9k4Z9pg6vTLf+QuYYUXDfdLqgLw qn3/QSVkyoYaZrEvhSu/LtqfEKzazNmuAUCRPR8Xotrz3CzCbzPLObQ1lfaxmOPR8tIm ftm4bxdZ6ZPDqyN2pLLyO42gSh6I6LQm31yZ8JZ/s+FGYi1yoFe4f7JMm8hWTqYSVr5K 7yWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k25si3518564ejx.143.2020.04.22.07.56.48; Wed, 22 Apr 2020 07:57:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728116AbgDVOzf (ORCPT + 99 others); Wed, 22 Apr 2020 10:55:35 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:49646 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727920AbgDVOzT (ORCPT ); Wed, 22 Apr 2020 10:55:19 -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 1jRGmR-0006CM-Oh; Wed, 22 Apr 2020 14:55:15 +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, Steve Barber , Dylan Reid , Filipe Brandenburger , Kees Cook , Benjamin Elder , Akihiro Suda Subject: [PATCH v2 7/7] loopfs: only show devices in their correct instance Date: Wed, 22 Apr 2020 16:54:37 +0200 Message-Id: <20200422145437.176057-8-christian.brauner@ubuntu.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200422145437.176057-1-christian.brauner@ubuntu.com> References: <20200422145437.176057-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 --- /* v2 */ unchanged --- 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 2dc53bad4b48..5548151b9f11 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -2213,8 +2213,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 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) -- 2.26.1