From patchwork Fri Oct 12 02:30:06 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: 10637779 X-Patchwork-Delegate: snitzer@redhat.com 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 8FBE5157A for ; Fri, 12 Oct 2018 02:31:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7791F2C259 for ; Fri, 12 Oct 2018 02:31:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6998C2C261; Fri, 12 Oct 2018 02:31:30 +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=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1581F2C259 for ; Fri, 12 Oct 2018 02:31:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 181D43DBD8; Fri, 12 Oct 2018 02:31:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CF8B228D2E; Fri, 12 Oct 2018 02:31:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 70FA54CA95; Fri, 12 Oct 2018 02:31:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9C2VRV5018428 for ; Thu, 11 Oct 2018 22:31:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2B7881057056; Fri, 12 Oct 2018 02:31:27 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx01.extmail.prod.ext.phx2.redhat.com [10.5.110.25]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 333711042557; Fri, 12 Oct 2018 02:31:23 +0000 (UTC) Received: from esa6.hgst.iphmx.com (esa6.hgst.iphmx.com [216.71.154.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 293C081DEC; Fri, 12 Oct 2018 02:30:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1539311472; x=1570847472; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=TO9/d2tST9vnaD05TIZjJa0QPE0wX3n1RaGQVyoHWb4=; b=O0EmbXfpDLLVZnbMeZBsLxm6Tep8NhXZOoiep40MG1yC1eXzEM80mamp mxt3WJqNHFkBf1patqnV5OsU2jdOGzBj0ZkpTKCkzd8M8MSTC0Q8XEnU4 Bp4/kBqHMKScrnX5huhnGlw48XiGIp0mD0S3TzhS1pBpxARo7nnPvw/aQ h0u8hewV8a+TqzWwG7b6Agq/AomSlSfG9ez4eFZpOKTExYEXBATYCfBsn Kdg7N/fHq3HN41IJt96UAO6+63aV8HAWA2q2fWMNpbHW6jNGfjsPwIGds TSHk6IFMt4pE17qOFqWgpO9CeS0EjAi/5EhG8+U6F2JS+yoABJQ+8C1S9 w==; X-IronPort-AV: E=Sophos;i="5.54,370,1534780800"; d="scan'208";a="93471107" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 12 Oct 2018 10:30:22 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP; 11 Oct 2018 19:15:40 -0700 Received: from washi.fujisawa.hgst.com ([10.149.53.254]) by uls-op-cesaip02.wdc.com with ESMTP; 11 Oct 2018 19:30:20 -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 Date: Fri, 12 Oct 2018 11:30:06 +0900 Message-Id: <20181012023012.29923-6-damien.lemoal@wdc.com> In-Reply-To: <20181012023012.29923-1-damien.lemoal@wdc.com> References: <20181012023012.29923-1-damien.lemoal@wdc.com> X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 12 Oct 2018 02:31:11 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 12 Oct 2018 02:31:11 +0000 (UTC) for IP:'216.71.154.45' DOMAIN:'esa6.hgst.iphmx.com' HELO:'esa6.hgst.iphmx.com' FROM:'damien.lemoal@wdc.com' RCPT:'' X-RedHat-Spam-Score: -0.8 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW) 216.71.154.45 esa6.hgst.iphmx.com 216.71.154.45 esa6.hgst.iphmx.com X-Scanned-By: MIMEDefang 2.83 on 10.5.110.25 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: dm-devel@redhat.com Cc: Christoph Hellwig , Matias Bjorling Subject: [dm-devel] [PATCH v3 05/11] block: Limit allocation of zone descriptors for report zones X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 12 Oct 2018 02:31:29 +0000 (UTC) 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 Reviewed-by: Hannes Reinecke --- block/blk-zoned.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 32e377f755d8..bb4ed69f917f 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -355,8 +355,7 @@ 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; + rep.nr_zones = min(blkdev_nr_zones(bdev), rep.nr_zones); zones = kvmalloc_array(rep.nr_zones, sizeof(struct blk_zone), GFP_KERNEL | __GFP_ZERO);