All of lore.kernel.org
 help / color / mirror / Atom feed
From: Damien Le Moal <Damien.LeMoal@wdc.com>
To: Johannes Thumshirn <Johannes.Thumshirn@wdc.com>,
	Jens Axboe <axboe@kernel.dk>
Cc: "linux-block @ vger . kernel . org" <linux-block@vger.kernel.org>,
	Christoph Hellwig <hch@lst.de>, Coly Li <colyli@suse.de>
Subject: Re: [PATCH] block: deny zone management ioctl on mounted fs
Date: Fri, 15 May 2020 04:52:27 +0000	[thread overview]
Message-ID: <BY5PR04MB69006DE86D1050620B5EDAA4E7BD0@BY5PR04MB6900.namprd04.prod.outlook.com> (raw)
In-Reply-To: 20200514162643.11880-1-johannes.thumshirn@wdc.com

On 2020/05/15 1:26, Johannes Thumshirn wrote:
> If a user submits a zone management ioctl from user-space, like a zone
> reset and a file-system (like zonefs or f2fs) is mounted on the zoned
> block device, the zone will get reset and the file-system's cached value
> of the zone's write-pointer becomes invalid.
> 
> Subsequent writes to this zone from the file-system will result in
> unaligned writes and the drive will error out.
> 
> Deny zone management ioctls when a super_block is found on the block
> device.

Zone management ioctls can only be executed by users that have SYS_CAP_ADMIN
capabilities. If these start doing stupid things, the system is probably in for
a lot of troubles beyond what this patch is trying to prevent.

In addition, there are so many other ways that a mounted zoned block device can
be corrupted beyond these ioctls that I am not sure this patch is very useful.
E.g. any raw block device write in a zone would also cause the FS to see
unaligned writes, and any other raw block device access is also possible for
SYS_CAP_ADMIN users. Preventing only these ioctls does not really improve
anything I think. That may even be harmful has that would prevent things like
inline file system check utilities to run.


> 
> Reported-by: Coly Li <colyli@suse.de>
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> 
> Is there a better way to check for a mounted FS than get_super()/drop_super()?
> 
>  block/blk-zoned.c | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/block/blk-zoned.c b/block/blk-zoned.c
> index 23831fa8701d..6923695ec414 100644
> --- a/block/blk-zoned.c
> +++ b/block/blk-zoned.c
> @@ -325,6 +325,7 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode,
>  			   unsigned int cmd, unsigned long arg)
>  {
>  	void __user *argp = (void __user *)arg;
> +	struct super_block *sb;
>  	struct request_queue *q;
>  	struct blk_zone_range zrange;
>  	enum req_opf op;
> @@ -345,6 +346,12 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode,
>  	if (!(mode & FMODE_WRITE))
>  		return -EBADF;
>  
> +	sb = get_super(bdev);
> +	if (sb) {
> +		drop_super(sb);
> +		return -EINVAL;
> +	}
> +
>  	if (copy_from_user(&zrange, argp, sizeof(struct blk_zone_range)))
>  		return -EFAULT;
>  
> 


-- 
Damien Le Moal
Western Digital Research

  reply	other threads:[~2020-05-15  4:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-14 16:26 [PATCH] block: deny zone management ioctl on mounted fs Johannes Thumshirn
2020-05-15  4:52 ` Damien Le Moal [this message]
2020-05-15  5:09   ` Coly Li
2020-05-15  5:25     ` Damien Le Moal
2020-05-15  5:34       ` Coly Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BY5PR04MB69006DE86D1050620B5EDAA4E7BD0@BY5PR04MB6900.namprd04.prod.outlook.com \
    --to=damien.lemoal@wdc.com \
    --cc=Johannes.Thumshirn@wdc.com \
    --cc=axboe@kernel.dk \
    --cc=colyli@suse.de \
    --cc=hch@lst.de \
    --cc=linux-block@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.