Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10409139ybi; Wed, 24 Jul 2019 22:41:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqygiLlUVbwfOYDbMtrvpeuedcUqr/PsNriLpTHado50MlrKIfDJsjeWjgtRaCldtLDDQbP4 X-Received: by 2002:a62:642:: with SMTP id 63mr15012631pfg.257.1564033319259; Wed, 24 Jul 2019 22:41:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564033319; cv=none; d=google.com; s=arc-20160816; b=zNegnguUkK0Sw4/iTzDSTF7dOl7uU2s9tO2ytupygF1A3tgsvs6XVHphOm0mveNAhv tI/v2Ak7+POuLY56Z6tTGEqc+dAYtkATbSeC/IODkLDLybyk7T1wL7TZJELiPFSms1Um sZBJBaNr0tRRbS61msl9KjaLwT9jVOL9HCv1Jp1KAzTw+yv4fDMDl1k8/goIk9qZTjvk A72xUSkeUsS2V4NZaNWS0YV4rrtjZLLP577v4eifD4WYNqVyXd9p9a0ch/mZFopiEKWR Zat9m5OahdopMgR3XOvsNYNwvcjp9Ph20dl2t9nzZMOZQjPlmSrnR/F7hPxY+HXQE1KI NOGw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6cJel+uslLeMNhDOtSgKEOlJqdDw4eUr7u9CbfGQULM=; b=rqWkLsEvIYCjHhNF9sqItAAVU6GAiBcVJcFI7qW6fXbjHMga+0khX691qqHlpdc1or TCbwD4VU0W9Bb+EJ0Af4CYKgm52ig3gdACC4o/nbvNkvrPsk1qePcQlT8HcV1D02KgqW QdMVP1638jnwyz5wZYgruqWmMqPZoQHSfygYQ/y+0v3u+ejgZ5I2kSfB2aNgoK0StmxY Ehu3rjmKteXksnxzqOZCbE4r2CmSYNV/nrBOOyeHcTQ+Y0iqe0GYIvu3OjsActxBFRZH j2BEo4m1l/4DxAwqE5b0M/G6QZ/iwMR3iamiQuWS96Qgeac5ABDxYiCilF9GjVRY4M7G JdRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZkcyJyub; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t15si15040658ply.162.2019.07.24.22.41.44; Wed, 24 Jul 2019 22:41:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ZkcyJyub; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405164AbfGXUKm (ORCPT + 99 others); Wed, 24 Jul 2019 16:10:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:45754 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2405008AbfGXT6v (ORCPT ); Wed, 24 Jul 2019 15:58:51 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CD4F021873; Wed, 24 Jul 2019 19:58:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563998330; bh=+l/JtDVZXE7La4+a5A8W23d/csoG77VgDQf98Ngqo68=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZkcyJyubaQ46EazFId6nUeGV1F/ngL0qr3mA7tm/p4Qzd7qTBgtESLkxys6q1pqU8 /Mol3eOIqJBYgxmygh7HZJvFigZ4hoAyJ+LZKzeUrVYHvU1CBOWUO3xCS2QsuPE/Ph +6lKtPKrhsAJ65EEXFiK7OjNQz4+Lk7BgFZlTydU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Damien Le Moal , Jens Axboe Subject: [PATCH 5.1 327/371] block: Fix potential overflow in blk_report_zones() Date: Wed, 24 Jul 2019 21:21:19 +0200 Message-Id: <20190724191748.443843713@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191724.382593077@linuxfoundation.org> References: <20190724191724.382593077@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Damien Le Moal commit 113ab72ed4794c193509a97d7c6d32a6886e1682 upstream. For large values of the number of zones reported and/or large zone sizes, the sector increment calculated with blk_queue_zone_sectors(q) * n in blk_report_zones() loop can overflow the unsigned int type used for the calculation as both "n" and blk_queue_zone_sectors() value are unsigned int. E.g. for a device with 256 MB zones (524288 sectors), overflow happens with 8192 or more zones reported. Changing the return type of blk_queue_zone_sectors() to sector_t, fixes this problem and avoids overflow problem for all other callers of this helper too. The same change is also applied to the bdev_zone_sectors() helper. Fixes: e76239a3748c ("block: add a report_zones method") Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-zoned.c | 2 +- include/linux/blkdev.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -69,7 +69,7 @@ EXPORT_SYMBOL_GPL(__blk_req_zone_write_u static inline unsigned int __blkdev_nr_zones(struct request_queue *q, sector_t nr_sectors) { - unsigned long zone_sectors = blk_queue_zone_sectors(q); + sector_t zone_sectors = blk_queue_zone_sectors(q); return (nr_sectors + zone_sectors - 1) >> ilog2(zone_sectors); } --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -662,7 +662,7 @@ static inline bool blk_queue_is_zoned(st } } -static inline unsigned int blk_queue_zone_sectors(struct request_queue *q) +static inline sector_t blk_queue_zone_sectors(struct request_queue *q) { return blk_queue_is_zoned(q) ? q->limits.chunk_sectors : 0; } @@ -1400,7 +1400,7 @@ static inline bool bdev_is_zoned(struct return false; } -static inline unsigned int bdev_zone_sectors(struct block_device *bdev) +static inline sector_t bdev_zone_sectors(struct block_device *bdev) { struct request_queue *q = bdev_get_queue(bdev);