Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1325304ybz; Wed, 22 Apr 2020 18:38:09 -0700 (PDT) X-Google-Smtp-Source: APiQypIGB8DA91YlZCZaTMvVRa4CrptM6bi2I5tZ9XveTOEjlT/JwvjM4u2FAmxPgVtRGsBVaAGS X-Received: by 2002:a17:906:9494:: with SMTP id t20mr791944ejx.51.1587605889145; Wed, 22 Apr 2020 18:38:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587605889; cv=none; d=google.com; s=arc-20160816; b=Ljupa6wO8dq+Zmv3sw46KRCEaLOJVNfMA/dgWbYWTQJpDuF23o/jbtKtmhJZitPG+B Z7TmpHTUrJtT2Zffl7uTAYNi9PvUHZwMBRyNNmv345P/IS5n3L9xpd6CaDDBsKPm522A LUIODh6uQREZZd54MIBM+/JJBto7C/jedxn6o3/2gRn3BhXdw+tiXDC2iQEI0X5wntN7 rrldBmWxYQh34TT75RrLzs9EDVo1Kafcp6z7V6oPfY9GSwcML+A+x4AiR8LSNjDLN14P gOXaFLeAVG5yRbzwgzxMSodl9XPpemrR3xhkkKw/siqR/e8U4zkJT0d1Cw3AlA3MTZdK cNYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=qjeKksYWKktt4d9JXyZmDH9HWpRVY5LONAT4vXyzwvA=; b=PY2g9UkrewlwINFUoCK+O+uPxX8VSvkPB9PvjptjDahMiBXdHUMZH2lwHjtSVmHOWV IDHA/fJ2gF7ffXtZVSP5JtF9Dh1cierLX/bNqObL4EUiQNrB7CSbXr/9jtPd/xd+bMlV w6BkulSt7HEOFL4i1c00uHWPdzH301YZQp2pH8asvNs2geDDF4lX223ELDzvZk9y3E44 dZ3wYJzbenPKQLwC44dRkXEpGxgF2qPFSZonlvlYK8FramEPOQR2PTKjBKlIl0nhyWJs 9kaX49VJ1w0uqiTWp9M0NOB4OzDQ+CuIs1ecQhTNZo9JYGYRDEnSZE2vUU/WrQ+rMhIM FN9A== 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 cw10si443061edb.54.2020.04.22.18.37.45; Wed, 22 Apr 2020 18:38:09 -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 S1726528AbgDWBgn (ORCPT + 99 others); Wed, 22 Apr 2020 21:36:43 -0400 Received: from mail.hallyn.com ([178.63.66.53]:53178 "EHLO mail.hallyn.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725961AbgDWBgm (ORCPT ); Wed, 22 Apr 2020 21:36:42 -0400 Received: by mail.hallyn.com (Postfix, from userid 1001) id AFB809D0; Wed, 22 Apr 2020 20:36:39 -0500 (CDT) Date: Wed, 22 Apr 2020 20:36:39 -0500 From: "Serge E. Hallyn" To: Christian Brauner Cc: Jens Axboe , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, linux-api@vger.kernel.org, Jonathan Corbet , Serge Hallyn , "Rafael J. Wysocki" , Tejun Heo , "David S. Miller" , Saravana Kannan , Jan Kara , David Howells , Seth Forshee , David Rheinsberg , Tom Gundersen , Christian Kellner , Dmitry Vyukov , =?iso-8859-1?Q?St=E9phane?= Graber , linux-doc@vger.kernel.org, netdev@vger.kernel.org, Steve Barber , Dylan Reid , Filipe Brandenburger , Kees Cook , Benjamin Elder , Akihiro Suda Subject: Re: [PATCH v2 6/7] loopfs: start attaching correct namespace during loop_add() Message-ID: <20200423013639.GB2982@mail.hallyn.com> References: <20200422145437.176057-1-christian.brauner@ubuntu.com> <20200422145437.176057-7-christian.brauner@ubuntu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200422145437.176057-7-christian.brauner@ubuntu.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 22, 2020 at 04:54:36PM +0200, Christian Brauner wrote: > 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 I was a *bit* worried about not taking a reference to the user namespace, but it doesn't look like the chain of loop_remove() -> del_gendisk() -> device_del() will allow any later access through sysfs, so I guess it's fine. Reviewed-by: Serge Hallyn > --- > /* 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