Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp784903ybz; Wed, 22 Apr 2020 07:59:35 -0700 (PDT) X-Google-Smtp-Source: APiQypJsty7k+rNegEjmr+EymQi/akI+RhQzaFRfCAvUECTNpv62wNifdi4AgWG0dXnzTzKy9Ui/ X-Received: by 2002:a17:906:4317:: with SMTP id j23mr25487197ejm.377.1587567575853; Wed, 22 Apr 2020 07:59:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587567575; cv=none; d=google.com; s=arc-20160816; b=qFCrLHO5iJ6uRx/62E/HLyG6Fel9UDkxm62yevV5ot3OSvnHVFVnz2kTpdMIy8SAVO mWuJ/7pCfKQBkqFIly/5k8gm63FwQuNNlJhygA8hPuNlWYAT1dK/xz7z3rqNWTacIm1+ VNf+ejWo5ZOf9dTx0K9Y3Zj/nVvVJY08EeIc4zPQXOUdWshJpAwXs9AStxdxy0N1Z0bg 8yKpXdnuI0pxyjlQVOiuzJK0XY1cCo1e7lD9DTYzLYURx8y2lw1OMRpf6wGYTbfD3M12 GdyTS3LbTFVjy4Q6tYdBVHlwHvPACZNrsU2tL+Orqw5II4SVAYfScE3tqr11YGWWApyR F+Fg== 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=yJtIf6oyCDEdAcmRIPEmpKdaF8UHaLD77F/OqB8yF4s=; b=INicOxZIBcVRyOXA5wKvay0j7MIzSAGBRGX6ApzdnAl5R8ynEWl7xyaNKzwcsBz+l7 74ZxW/ftJ2F0uX/PJ26xbOx1/U4TpJFcPoNBM73+uP43wpa5bfqajRNVGQQ5iUy2jm0R rPPZ/G0Ji0woSLn+Tgkpx6OwMr/5F4blcIJ7u/OqOepjQt/5qN98T70oQTaOb4nYQhJf XLihvWpzuW0+GmkrDLxDwXmXS18lQFAVgZxVypkyfnDD7IrGHrGw0FXqXaobmhmqjkOV bWj0xyX7SwJMA6w2b6ypzUUjHLfcQfaGMY54cO9lmfM2QlyR9L28uQ8O6fR+wrVrFsOT dVCw== 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 v28si3627073edx.335.2020.04.22.07.59.07; Wed, 22 Apr 2020 07:59:35 -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 S1728055AbgDVOz0 (ORCPT + 99 others); Wed, 22 Apr 2020 10:55:26 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:49640 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727898AbgDVOzR (ORCPT ); Wed, 22 Apr 2020 10:55:17 -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 1jRGmQ-0006CM-D9; Wed, 22 Apr 2020 14:55:14 +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 6/7] loopfs: start attaching correct namespace during loop_add() Date: Wed, 22 Apr 2020 16:54:36 +0200 Message-Id: <20200422145437.176057-7-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 Tag loop devices with the namespace the loopfs instance was mounted in. This has the consequence that loopfs devices carry the correct sysfs permissions for all their core files. All other devices files will continue to be correctly owned by the initial namespaces. Here is sample output: root@b1:~# mount -t loop loop /mnt root@b1:~# ln -sf /mnt/loop-control /dev/loop-control root@b1:~# losetup -f /dev/loop8 root@b1:~# ln -sf /mnt/loop8 /dev/loop8 root@b1:~# ls -al /sys/class/block/loop8 lrwxrwxrwx 1 root root 0 Apr 7 13:06 /sys/class/block/loop8 -> ../../devices/virtual/block/loop8 root@b1:~# ls -al /sys/class/block/loop8/ total 0 drwxr-xr-x 9 root root 0 Apr 7 13:06 . drwxr-xr-x 18 nobody nogroup 0 Apr 7 13:07 .. -r--r--r-- 1 root root 4096 Apr 7 13:06 alignment_offset lrwxrwxrwx 1 nobody nogroup 0 Apr 7 13:07 bdi -> ../../bdi/7:8 -r--r--r-- 1 root root 4096 Apr 7 13:06 capability -r--r--r-- 1 root root 4096 Apr 7 13:06 dev -r--r--r-- 1 root root 4096 Apr 7 13:06 discard_alignment -r--r--r-- 1 root root 4096 Apr 7 13:06 events -r--r--r-- 1 root root 4096 Apr 7 13:06 events_async -rw-r--r-- 1 root root 4096 Apr 7 13:06 events_poll_msecs -r--r--r-- 1 root root 4096 Apr 7 13:06 ext_range -r--r--r-- 1 root root 4096 Apr 7 13:06 hidden drwxr-xr-x 2 nobody nogroup 0 Apr 7 13:07 holders -r--r--r-- 1 root root 4096 Apr 7 13:06 inflight drwxr-xr-x 2 nobody nogroup 0 Apr 7 13:07 integrity drwxr-xr-x 3 nobody nogroup 0 Apr 7 13:07 mq drwxr-xr-x 2 root root 0 Apr 7 13:06 power drwxr-xr-x 3 nobody nogroup 0 Apr 7 13:07 queue -r--r--r-- 1 root root 4096 Apr 7 13:06 range -r--r--r-- 1 root root 4096 Apr 7 13:06 removable -r--r--r-- 1 root root 4096 Apr 7 13:06 ro -r--r--r-- 1 root root 4096 Apr 7 13:06 size drwxr-xr-x 2 nobody nogroup 0 Apr 7 13:07 slaves -r--r--r-- 1 root root 4096 Apr 7 13:06 stat lrwxrwxrwx 1 nobody nogroup 0 Apr 7 13:07 subsystem -> ../../../../class/block drwxr-xr-x 2 root root 0 Apr 7 13:06 trace -rw-r--r-- 1 root root 4096 Apr 7 13:06 uevent root@b1:~# Cc: Jens Axboe Signed-off-by: Christian Brauner --- /* v2 */ unchanged - Christian Brauner : - Adapted commit message otherwise unchanged. --- drivers/block/loop.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 8e21d4b33e01..2dc53bad4b48 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -2212,6 +2212,10 @@ static int loop_add(struct loop_device **l, int i, struct inode *inode) disk->private_data = lo; disk->queue = lo->lo_queue; sprintf(disk->disk_name, "loop%d", i); +#ifdef CONFIG_BLK_DEV_LOOPFS + if (loopfs_i_sb(inode)) + disk->user_ns = loopfs_i_sb(inode)->s_user_ns; +#endif add_disk(disk); -- 2.26.1