Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp801942ybh; Tue, 21 Jul 2020 08:15:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYQUoOXI9hfvFxG5+mL8Tw75XOR0+qv+IjAnC0PbMzVkbO4ErBOsuWVGCiRaIo8THdY0hM X-Received: by 2002:a17:907:94c9:: with SMTP id dn9mr22174589ejc.355.1595344525135; Tue, 21 Jul 2020 08:15:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595344525; cv=none; d=google.com; s=arc-20160816; b=MBAqkkSqGI+16qStOmkgPQBuE1keA5Joz6cYz7gLgPWxGjnDY2scS8eJe0ake1zx5C kWNEDMbKbw1WPmjZx9QEmAg2K5FZtgZxPp16XQroKZbmDuUl7y8i261+OtWScXrnRLgi 50+e0nRJRtF6R9YQsbUP3b7xhK+MbyNwNrO6vOw7d4f2TGyKM+oA9KTU6dpxyPX8ZfGY ue62f2TbUE4Y3yx/Kn85GWK1q1pbYiOgGy72gSXUMBXezMU5ABrgJAU90CZ1Wj2et2IG yuGw5vgF44wwu0BFaLTWhbqgxgokIJRsbZ9fmaAukzaSGkOx7b+UweBWiII62QTdZaZa X9mQ== 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=2sYrLW1oMA8u3UDpR4Laj42nAs8IPYvIXMeW4lhT8Ew=; b=ZBo5P8bO+8g78dGZaUsNCHiX6i+X/W3S+R0f+gDZtqjUbSWpBV/cmGVwEGXUptGF1F rlUnE+aDD+YOfq/RJ0ceGHXBBM3V4PMAQUd1fxPfFphBcyVKXJBrGE13plmXv/iKf3Pe X2phLoDzol85iC6aojYxbo6JlhyXu9eioacTVnA8Jl/DCUp1V7kS7ASfK4IM1K0txt1B yRrRF1ul3CkCyF1IKBnFm1/7KIsmq2g1jeYvkYQLC+0viJxiPfLbpqECcIGfxBJv+ZAj ZxL0U67GuJxLIObUziAPmewR1m6QjVmOpwF6CNYIBzjn+JiAngdMLDt6x++hTYMO16JR La6g== 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 x94si14573717ede.416.2020.07.21.08.15.01; Tue, 21 Jul 2020 08:15:25 -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 S1729952AbgGUPOl (ORCPT + 99 others); Tue, 21 Jul 2020 11:14:41 -0400 Received: from verein.lst.de ([213.95.11.211]:52627 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728089AbgGUPOk (ORCPT ); Tue, 21 Jul 2020 11:14:40 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id 9AD7268B05; Tue, 21 Jul 2020 17:14:37 +0200 (CEST) Date: Tue, 21 Jul 2020 17:14:37 +0200 From: Christoph Hellwig To: Maxim Levitsky Cc: linux-kernel@vger.kernel.org, Keith Busch , Josef Bacik , "open list:BLOCK LAYER" , Sagi Grimberg , Jens Axboe , "open list:NVM EXPRESS DRIVER" , "open list:SCSI CDROM DRIVER" , Tejun Heo , Bart Van Assche , "Martin K. Petersen" , Damien Le Moal , Jason Wang , Maxim Levitsky , Stefan Hajnoczi , Colin Ian King , "Michael S. Tsirkin" , Paolo Bonzini , Ulf Hansson , Ajay Joshi , Ming Lei , "open list:SONY MEMORYSTICK SUBSYSTEM" , Christoph Hellwig , Satya Tangirala , "open list:NETWORK BLOCK DEVICE (NBD)" , Hou Tao , Jens Axboe , "open list:VIRTIO CORE AND NET DRIVERS" , "James E.J. Bottomley" , Alex Dubov Subject: Re: [PATCH 02/10] block: virtio-blk: check logical block size Message-ID: <20200721151437.GB10620@lst.de> References: <20200721105239.8270-1-mlevitsk@redhat.com> <20200721105239.8270-3-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200721105239.8270-3-mlevitsk@redhat.com> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 21, 2020 at 01:52:31PM +0300, Maxim Levitsky wrote: > Linux kernel only supports logical block sizes which are power of two, > at least 512 bytes and no more that PAGE_SIZE. > > Check this instead of crashing later on. > > Note that there is no need to check physical block size since it is > only a hint, and virtio-blk already only supports power of two values. > > Bugzilla link: https://bugzilla.redhat.com/show_bug.cgi?id=1664619 > > Signed-off-by: Maxim Levitsky > --- > drivers/block/virtio_blk.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c > index 980df853ee497..b5ee87cba00ed 100644 > --- a/drivers/block/virtio_blk.c > +++ b/drivers/block/virtio_blk.c > @@ -809,10 +809,18 @@ static int virtblk_probe(struct virtio_device *vdev) > err = virtio_cread_feature(vdev, VIRTIO_BLK_F_BLK_SIZE, > struct virtio_blk_config, blk_size, > &blk_size); > - if (!err) > + if (!err) { > + if (!blk_is_valid_logical_block_size(blk_size)) { > + dev_err(&vdev->dev, > + "%s failure: invalid logical block size %d\n", > + __func__, blk_size); > + err = -EINVAL; > + goto out_cleanup_queue; > + } > blk_queue_logical_block_size(q, blk_size); Hmm, I wonder if we should simply add the check and warning to blk_queue_logical_block_size and add an error in that case. Then drivers only have to check the error return, which might add a lot less boiler plate code.