Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1679894ybz; Thu, 16 Apr 2020 13:32:57 -0700 (PDT) X-Google-Smtp-Source: APiQypI3+GUpP7iGF5WkFC4RUV3ugnY/cpGMVRjvonhOJ0QX/t+AFo1UVHdfETwLUMP6K5VvSzEF X-Received: by 2002:a50:c042:: with SMTP id u2mr31076edd.250.1587069177516; Thu, 16 Apr 2020 13:32:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587069177; cv=none; d=google.com; s=arc-20160816; b=U0z0PFHTYBsblNao9m7iQmT9rIMyyLLethvhLKFj+AJnWACTyRdIOye90wZayFmKMU YT4meAtltcdwafMCFvBJkFrCxg/1bZMd9COCvWxaYEbO0MPdbwm0IgRGRbHM6dxPj8Hh zU9ySu5rbxC8Z/MbDfNRuRexKOPgPM0LoZbhsX9ph7Bgsd7/4gXNzSiIGVQI6DxhgWY4 dshMng/cpqBVjMi8rqUmzdEW3MUUpF7WXm+J3GSjj0DI7nL5Jvr+q5EvLI37IGeittvk rI/wQ8EDYA21LOKyWrZwjy44guKoV5RpQoSO5rfsCkXwKtxEDoSXhfg8R9CgALF0snYd wE/g== 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=lpu2DlpHjMx/hPEkEBoVppfoRiRkxgE+tP5mVupwZTY=; b=o1AGoRXsQ3zicrgNLWD+DQ8c0ikGonygnxG4gtkhbLfxlRMH2Pk/oBkDQ7QpK/tpDo 9kav6SkoADJ0xHzoaO7EEXwuiCMFME8icDb43AqamlPn/TzpBoq0X9Z8WeCnMipX4CYh ze0zj+WQ79x/ePzALpFjYlZ38YS0O0q2T+CaEZzEPUJAVL22d7MOlZ78TKVcW/8NjN8T K82/XsxztZruW0kmf0XQGH1H/oBNuUDitma8KQ6o6ZiyxvxBIaqxsWgC6PDiluvujZN4 FYTcm7MpaQPogGyIqgiF4jvDs8jXH8EKYsSnQExHZfYNv5dVQsv+fqAvyk7/shY5+alJ V9gg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=XZOvYfnr; 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 a11si13075649edf.265.2020.04.16.13.32.35; Thu, 16 Apr 2020 13:32:57 -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=@kernel.org header.s=default header.b=XZOvYfnr; 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 S2440595AbgDPPCP (ORCPT + 99 others); Thu, 16 Apr 2020 11:02:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:40530 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2897768AbgDPNyA (ORCPT ); Thu, 16 Apr 2020 09:54:00 -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 F29D62076D; Thu, 16 Apr 2020 13:53:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587045239; bh=Szm+1rgDnYEAet5MAJnily9gGMqOJMGUuLDtS4pC0Vc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XZOvYfnrbGtwwRAPxHIbDCq7DCITo8QZYzSHGP3KZkvzrmYt5RqmSl9a3afXvKM12 Z4/r7voQaNDfTn5/cyZRcWpT1bAXUWXRnO2f9lkFzkt5+yhgJyl+Fc4DS4EJkiHKCK 4ZKYpzbUH8prvCLRVZBb6RMJQrTHxsROohrYs8qE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , "Alexey Dobriyan (SK hynix)" , Jens Axboe , Sasha Levin Subject: [PATCH 5.6 051/254] block, zoned: fix integer overflow with BLKRESETZONE et al Date: Thu, 16 Apr 2020 15:22:20 +0200 Message-Id: <20200416131332.264664702@linuxfoundation.org> X-Mailer: git-send-email 2.26.1 In-Reply-To: <20200416131325.804095985@linuxfoundation.org> References: <20200416131325.804095985@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: Alexey Dobriyan [ Upstream commit 11bde986002c0af67eb92d73321d06baefae7128 ] Check for overflow in addition before checking for end-of-block-device. Steps to reproduce: #define _GNU_SOURCE 1 #include #include #include #include typedef unsigned long long __u64; struct blk_zone_range { __u64 sector; __u64 nr_sectors; }; #define BLKRESETZONE _IOW(0x12, 131, struct blk_zone_range) int main(void) { int fd = open("/dev/nullb0", O_RDWR|O_DIRECT); struct blk_zone_range zr = {4096, 0xfffffffffffff000ULL}; ioctl(fd, BLKRESETZONE, &zr); return 0; } BUG: KASAN: null-ptr-deref in submit_bio_wait+0x74/0xe0 Write of size 8 at addr 0000000000000040 by task a.out/1590 CPU: 8 PID: 1590 Comm: a.out Not tainted 5.6.0-rc1-00019-g359c92c02bfa #2 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20190711_202441-buildvm-armv7-10.arm.fedoraproject.org-2.fc31 04/01/2014 Call Trace: dump_stack+0x76/0xa0 __kasan_report.cold+0x5/0x3e kasan_report+0xe/0x20 submit_bio_wait+0x74/0xe0 blkdev_zone_mgmt+0x26f/0x2a0 blkdev_zone_mgmt_ioctl+0x14b/0x1b0 blkdev_ioctl+0xb28/0xe60 block_ioctl+0x69/0x80 ksys_ioctl+0x3af/0xa50 Reviewed-by: Christoph Hellwig Signed-off-by: Alexey Dobriyan (SK hynix) Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-zoned.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 05741c6f618be..6b442ae96499a 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -173,7 +173,7 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op, if (!op_is_zone_mgmt(op)) return -EOPNOTSUPP; - if (!nr_sectors || end_sector > capacity) + if (end_sector <= sector || end_sector > capacity) /* Out of range */ return -EINVAL; -- 2.20.1