From patchwork Fri Apr 24 16:20:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Brauner X-Patchwork-Id: 220602 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E2643C5519A for ; Fri, 24 Apr 2020 16:22:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CD49F20700 for ; Fri, 24 Apr 2020 16:22:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728671AbgDXQWO (ORCPT ); Fri, 24 Apr 2020 12:22:14 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:58648 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728538AbgDXQWF (ORCPT ); Fri, 24 Apr 2020 12:22:05 -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 1jS15W-0004dV-Nd; Fri, 24 Apr 2020 16:22:02 +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_Gr?= =?utf-8?q?aber?= , linux-doc@vger.kernel.org, netdev@vger.kernel.org, Steve Barber , Dylan Reid , Filipe Brandenburger , Kees Cook , Benjamin Elder , Akihiro Suda Subject: [PATCH v3 6/7] loopfs: start attaching correct namespace during loop_add() Date: Fri, 24 Apr 2020 18:20:51 +0200 Message-Id: <20200424162052.441452-7-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 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 Reviewed-by: Serge Hallyn Signed-off-by: Christian Brauner --- /* v2 */ unchanged - Christian Brauner : - Adapted commit message otherwise unchanged. /* v3 */ unchanged --- drivers/block/loop.c | 3 +++ drivers/block/loopfs/loopfs.c | 6 ++++++ drivers/block/loopfs/loopfs.h | 1 + 3 files changed, 10 insertions(+) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 40705f5aeabd..a5fe05cba896 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -2207,6 +2207,9 @@ 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 + loopfs_init(disk, inode); +#endif add_disk(disk); diff --git a/drivers/block/loopfs/loopfs.c b/drivers/block/loopfs/loopfs.c index 09cd5a919ea2..9fa60c1bcc05 100644 --- a/drivers/block/loopfs/loopfs.c +++ b/drivers/block/loopfs/loopfs.c @@ -74,6 +74,12 @@ bool loopfs_wants_remove(const struct loop_device *lo) (lo->lo_info->lo_flags & LOOPFS_FLAGS_INACTIVE); } +void loopfs_init(struct gendisk *disk, struct inode *inode) +{ + if (loopfs_i_sb(inode)) + disk->user_ns = loopfs_i_sb(inode)->s_user_ns; +} + /** * loopfs_add - allocate inode from super block of a loopfs mount * @lo: loop device for which we are creating a new device entry diff --git a/drivers/block/loopfs/loopfs.h b/drivers/block/loopfs/loopfs.h index 225d844f5a01..7ca1b872b36e 100644 --- a/drivers/block/loopfs/loopfs.h +++ b/drivers/block/loopfs/loopfs.h @@ -31,6 +31,7 @@ extern void loopfs_remove(struct loop_device *lo); extern bool loopfs_wants_remove(const struct loop_device *lo); extern void loopfs_evict_locked(struct loop_device *lo); extern int loopfs_rundown_locked(struct loop_device *lo); +extern void loopfs_init(struct gendisk *disk, struct inode *inode); #endif