Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1118879ybz; Wed, 22 Apr 2020 13:58:58 -0700 (PDT) X-Google-Smtp-Source: APiQypL1F2EPKVT5UbmAFW5gbpUgdjSvodoxHtCqToIKvIgT9VkxTYqgfWkzeeajBiV01ARLc4qx X-Received: by 2002:a17:906:33d4:: with SMTP id w20mr213245eja.284.1587589138805; Wed, 22 Apr 2020 13:58:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587589138; cv=none; d=google.com; s=arc-20160816; b=VXNrfYsRLmbfNk9GHC7k1EPY/veCqYEw28sYSRRGTFUPshY7cuHrHkx+ES/Zs1T54n 7nRpG6QnoWa592vN01N8GCaPcy/V4qOrDVux42r0/c7locdYqMtIiaPUJy0wsAgOcFgh fjy386sXOE/tI8YBho/vnHiruIvnFYWRxXIcy+DNg0Maz2TWGFou82F1iJlWCfxQBjfT eqCDAWIax0A32JW6JsbXXbvJ1a299EJob6FYWqG7lcJATxWkBcp8DmB5mQRt9YXX5/Uo kDhhNCwbFMJoNPRYA1GVqEmyKXlgpbMGmlhHzxLMrSTXyi1mwDg6zg7OsJzinoZrFhIh FfnQ== 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=x753J/JEwbbkPgMvehNepwbfPr8kH1lOG02A1t/cxlY=; b=MO1RknSLiJYn0FOis5juxqdPZbMcYlEk0uU1q9qGat9HCJP7dF9bTzS6rDwvyK36Pw RzIqZ2oWrW362JBY+QyPJpqqCQkK1o4f9IhORY2s7dCWlZo+iHqZhGHWl5p1d7MX1QKH XVZ8xThCFn3ubeDYjkjXRMz8BHnEU9qrk6Idxf6d7K0lTJV32pCEgffUqy7+YjBcia36 xwTrAmuV/QKsssX3o6GqkH3k3hJaepIEUVHifl/Q6BEPqXBjqaDkxvUIKLsHJL2Q+aEM v1AeWXTLv8Jdu1QeYr4mS7we8oTpaW3KJ3JyIKqxO9DCh8FnQ/O47Z694z6VNzDqdgxE RNjg== 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 w20si164039ejk.464.2020.04.22.13.58.35; Wed, 22 Apr 2020 13:58:58 -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 S1726489AbgDVU5Z (ORCPT + 99 others); Wed, 22 Apr 2020 16:57:25 -0400 Received: from mail.hallyn.com ([178.63.66.53]:45876 "EHLO mail.hallyn.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726105AbgDVU5Z (ORCPT ); Wed, 22 Apr 2020 16:57:25 -0400 X-Greylist: delayed 391 seconds by postgrey-1.27 at vger.kernel.org; Wed, 22 Apr 2020 16:57:22 EDT Received: by mail.hallyn.com (Postfix, from userid 1001) id 2555C9A3; Wed, 22 Apr 2020 15:50:51 -0500 (CDT) Date: Wed, 22 Apr 2020 15:50:51 -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 3/7] loop: use ns_capable for some loop operations Message-ID: <20200422205051.GA31944@mail.hallyn.com> References: <20200422145437.176057-1-christian.brauner@ubuntu.com> <20200422145437.176057-4-christian.brauner@ubuntu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200422145437.176057-4-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:33PM +0200, Christian Brauner wrote: > The following LOOP_GET_STATUS, LOOP_SET_STATUS, and LOOP_SET_BLOCK_SIZE > operations are now allowed in non-initial namespaces. Most other > operations were already possible before. > > Cc: Jens Axboe > Cc: Seth Forshee > Cc: Tom Gundersen > Cc: Tejun Heo > Cc: Christian Kellner > Cc: Greg Kroah-Hartman > Cc: "David S. Miller" > Cc: David Rheinsberg > Cc: Dmitry Vyukov > Cc: "Rafael J. Wysocki" > Signed-off-by: Christian Brauner Reviewed-by: Serge Hallyn > --- > /* v2 */ > - Christian Brauner : > - Adapated loop_capable() based on changes in the loopfs > implementation patchset. Otherwise it is functionally equivalent to > the v1 version. > --- > drivers/block/loop.c | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/drivers/block/loop.c b/drivers/block/loop.c > index 52f7583dd17d..8e21d4b33e01 100644 > --- a/drivers/block/loop.c > +++ b/drivers/block/loop.c > @@ -1352,6 +1352,16 @@ void loopfs_evict_locked(struct loop_device *lo) > } > mutex_unlock(&loop_ctl_mutex); > } > + > +static bool loop_capable(const struct loop_device *lo, int cap) > +{ > + return ns_capable(loopfs_ns(lo), cap); > +} > +#else /* !CONFIG_BLK_DEV_LOOPFS */ > +static inline bool loop_capable(const struct loop_device *lo, int cap) > +{ > + return capable(cap); > +} > #endif /* CONFIG_BLK_DEV_LOOPFS */ > > static int > @@ -1368,7 +1378,7 @@ loop_set_status(struct loop_device *lo, const struct loop_info64 *info) > return err; > if (lo->lo_encrypt_key_size && > !uid_eq(lo->lo_key_owner, uid) && > - !capable(CAP_SYS_ADMIN)) { > + !loop_capable(lo, CAP_SYS_ADMIN)) { > err = -EPERM; > goto out_unlock; > } > @@ -1499,7 +1509,7 @@ loop_get_status(struct loop_device *lo, struct loop_info64 *info) > memcpy(info->lo_crypt_name, lo->lo_crypt_name, LO_NAME_SIZE); > info->lo_encrypt_type = > lo->lo_encryption ? lo->lo_encryption->number : 0; > - if (lo->lo_encrypt_key_size && capable(CAP_SYS_ADMIN)) { > + if (lo->lo_encrypt_key_size && loop_capable(lo, CAP_SYS_ADMIN)) { > info->lo_encrypt_key_size = lo->lo_encrypt_key_size; > memcpy(info->lo_encrypt_key, lo->lo_encrypt_key, > lo->lo_encrypt_key_size); > @@ -1723,7 +1733,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode, > return loop_clr_fd(lo); > case LOOP_SET_STATUS: > err = -EPERM; > - if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) { > + if ((mode & FMODE_WRITE) || loop_capable(lo, CAP_SYS_ADMIN)) { > err = loop_set_status_old(lo, > (struct loop_info __user *)arg); > } > @@ -1732,7 +1742,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode, > return loop_get_status_old(lo, (struct loop_info __user *) arg); > case LOOP_SET_STATUS64: > err = -EPERM; > - if ((mode & FMODE_WRITE) || capable(CAP_SYS_ADMIN)) { > + if ((mode & FMODE_WRITE) || loop_capable(lo, CAP_SYS_ADMIN)) { > err = loop_set_status64(lo, > (struct loop_info64 __user *) arg); > } > @@ -1742,7 +1752,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode, > case LOOP_SET_CAPACITY: > case LOOP_SET_DIRECT_IO: > case LOOP_SET_BLOCK_SIZE: > - if (!(mode & FMODE_WRITE) && !capable(CAP_SYS_ADMIN)) > + if (!(mode & FMODE_WRITE) && !loop_capable(lo, CAP_SYS_ADMIN)) > return -EPERM; > /* Fall through */ > default: > -- > 2.26.1