Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp618621ybh; Tue, 21 Jul 2020 03:54:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzVAobvN+eZda+Bzj4bfq5EhWQrGlsiAay2CZ+qQjaC7sQbgQkFXHBPIvk0onS1ifGv4Bvz X-Received: by 2002:a05:6402:94f:: with SMTP id h15mr25860913edz.313.1595328886576; Tue, 21 Jul 2020 03:54:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595328886; cv=none; d=google.com; s=arc-20160816; b=kzRYxScaP2V8ae7QgU0bH8EE0YzfxBZYs7K0GWCzcONZg+D9nAhjAVIC73z3zpaw+K 2hc/Hzx2NVldphu6814X+l1/uMtq2adEcyL4PXJ0lUPObCaIlqJrvXMVEI4ycLK91/L2 e9gsL2SMOF84Wu17kCOrFYaHXxFuiL2ocqjI4Bm8u4SWTPkFAOkUacPCso9i7X7ioUxv JykdKCF7RvzekPTqE4HFWRSWDi0ZHqjO6R+0ukXOdjz2QM1ofTZuVnCv1/kDjyKz4PrD h5M48XcYH0VP1zYSBfx+SkXVF5XDyaLZC47qW7e770ysLGZmJ6GsGdB/RY5Vm4IkIav+ 2Gpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4gteU3EGNoUKPt8oYOM7d1sSCLxaOHL3O+rsdN+CvQ8=; b=q8c/peatADxZDE6+yGsTkCZROh67RfwHID22bjHhBDYdTN6U24PerIhahe9ou3xLhf FySXUvqCbc7UDDHXAsr33QmqEMk/tMzpYCEFI7k6g/M99TyC/QSaxTlKVi58gxvQBAI6 ONJf/v7uOL9CMJNdD254LXutJsYWW8XtITXExkid94n/xo6veits83weFTVUmRRuURxa 0Z1k7Q77hX3BFnhdcD8aohQpJ2uVwmfyxpxjmd5mlGVPn/KW+SKAaTYIuk1FzxWLXmUN YqRccXuAGcjVOJqwCxfTWMM+fpqlaHXmL5onC5HoPsTdfzXk9Xzfqi89zdPJfFURU7ZK hq9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OL5vP3xB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qk1si11652668ejb.15.2020.07.21.03.54.24; Tue, 21 Jul 2020 03:54:46 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=OL5vP3xB; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728210AbgGUKyK (ORCPT + 99 others); Tue, 21 Jul 2020 06:54:10 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:51586 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729356AbgGUKyJ (ORCPT ); Tue, 21 Jul 2020 06:54:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1595328848; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4gteU3EGNoUKPt8oYOM7d1sSCLxaOHL3O+rsdN+CvQ8=; b=OL5vP3xBzb2Jb48dKiAbakVaWoMp8FpFFY2ky8PUhkfkZTHePO7WB4CotKJsVFAEAvgMiI zy0wsdckQEUwo6Izggp8m5UbObQT6dVbECNOC+1XDiUxtW1LP3Rdu/oTQymLQAVUlVfjEO Rhwd4hG8sJrQBuX5Y9xhAkVJKoVqvY4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-63-QTw1zjUEPNq-t8eTeL3FpQ-1; Tue, 21 Jul 2020 06:54:04 -0400 X-MC-Unique: QTw1zjUEPNq-t8eTeL3FpQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5DC681009625; Tue, 21 Jul 2020 10:54:01 +0000 (UTC) Received: from localhost.localdomain (unknown [10.35.206.163]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA0CD1C4; Tue, 21 Jul 2020 10:53:26 +0000 (UTC) From: Maxim Levitsky To: linux-kernel@vger.kernel.org Cc: Keith Busch , Josef Bacik , linux-block@vger.kernel.org (open list:BLOCK LAYER), Sagi Grimberg , Jens Axboe , linux-nvme@lists.infradead.org (open list:NVM EXPRESS DRIVER), linux-scsi@vger.kernel.org (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 , linux-mmc@vger.kernel.org (open list:SONY MEMORYSTICK SUBSYSTEM), Christoph Hellwig , Satya Tangirala , nbd@other.debian.org (open list:NETWORK BLOCK DEVICE (NBD)), Hou Tao , Jens Axboe , virtualization@lists.linux-foundation.org (open list:VIRTIO CORE AND NET DRIVERS), "James E.J. Bottomley" , Alex Dubov , Maxim Levitsky Subject: [PATCH 02/10] block: virtio-blk: check logical block size Date: Tue, 21 Jul 2020 13:52:31 +0300 Message-Id: <20200721105239.8270-3-mlevitsk@redhat.com> In-Reply-To: <20200721105239.8270-1-mlevitsk@redhat.com> References: <20200721105239.8270-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); - else + } else { blk_size = queue_logical_block_size(q); + } /* Use topology information if available */ err = virtio_cread_feature(vdev, VIRTIO_BLK_F_TOPOLOGY, @@ -872,6 +880,9 @@ static int virtblk_probe(struct virtio_device *vdev) device_add_disk(&vdev->dev, vblk->disk, virtblk_attr_groups); return 0; +out_cleanup_queue: + blk_cleanup_queue(vblk->disk->queue); + vblk->disk->queue = NULL; out_free_tags: blk_mq_free_tag_set(&vblk->tag_set); out_put_disk: -- 2.26.2