From patchwork Wed Oct 10 01:52:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Damien Le Moal X-Patchwork-Id: 10633799 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C8415CAF for ; Wed, 10 Oct 2018 01:52:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D504298B6 for ; Wed, 10 Oct 2018 01:52:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 51533298DB; Wed, 10 Oct 2018 01:52:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F426298B6 for ; Wed, 10 Oct 2018 01:52:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727016AbeJJJMg (ORCPT ); Wed, 10 Oct 2018 05:12:36 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:39878 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbeJJJMg (ORCPT ); Wed, 10 Oct 2018 05:12:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1539136369; x=1570672369; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=ndrTa/IXM525AUNBZqItGuSykDBoYk26UYCrJbDRMjw=; b=pkm+W01A/oslNpXbIViPPPOMh3B0J77CM85aLRIV7nxlIxeOOCtiRZsE 4VzCDfVg6Qd4H1vMT0G1WSt6mJF2hWGxpT9XjA14IjIbSnkJsxZS8S3LW qYgdlkwypltGkoNIJzQgspTcNQRDwgVYakQm0Qur8DFjmjZCfd5fKyfV9 wEckcJ+CUALyiaNxT5MO+Df+j3q1wGLGOzj7CxNU7vbAmT4ygrcfMCQgR h25w0Q38w5f/xOoGkBAIqSLffKEOnm0OaaeP5LNzvCvO4CLTECc31t++p 8dZzm5KvGOzMUuzyuYkyV53X9BQH/I6kyb8AESSkw8A7UEyIBu6I723Jk Q==; X-IronPort-AV: E=Sophos;i="5.54,362,1534780800"; d="scan'208";a="92692971" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 10 Oct 2018 09:52:49 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 09 Oct 2018 18:38:14 -0700 Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Oct 2018 18:52:47 -0700 From: Damien Le Moal To: linux-block@vger.kernel.org, Jens Axboe , linux-scsi@vger.kernel.org, "Martin K . Petersen" , dm-devel@redhat.com, Mike Snitzer Cc: Christoph Hellwig , Matias Bjorling Subject: [PATCH 05/11] block: Limit allocation of zone descriptors for report zones Date: Wed, 10 Oct 2018 10:52:33 +0900 Message-Id: <20181010015239.24930-6-damien.lemoal@wdc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181010015239.24930-1-damien.lemoal@wdc.com> References: <20181010015239.24930-1-damien.lemoal@wdc.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP There is no point in allocating more zone descriptors than the number of zones a block device has for doing a zone report. Avoid doing that in blkdev_report_zones_ioctl() by limiting the number of zone decriptors allocated internally to process the user request. Signed-off-by: Damien Le Moal Reviewed-by: Christoph Hellwig --- block/blk-zoned.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 32e377f755d8..f2c8b859fc18 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -334,6 +334,7 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, struct request_queue *q; struct blk_zone_report rep; struct blk_zone *zones; + unsigned int nr_zones; int ret; if (!argp) @@ -355,8 +356,9 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, if (!rep.nr_zones) return -EINVAL; - if (rep.nr_zones > INT_MAX / sizeof(struct blk_zone)) - return -ERANGE; + nr_zones = blkdev_nr_zones(bdev); + if (rep.nr_zones > nr_zones) + rep.nr_zones = nr_zones; zones = kvmalloc_array(rep.nr_zones, sizeof(struct blk_zone), GFP_KERNEL | __GFP_ZERO);