Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4645158ybl; Wed, 22 Jan 2020 01:57:58 -0800 (PST) X-Google-Smtp-Source: APXvYqxfL4hIrPNQ2btfKSFksfzwcRV/A041bftfQRM2HFSInoKrMyyoHrwbfJWQa/vVK2Vtvgha X-Received: by 2002:a9d:5542:: with SMTP id h2mr6279269oti.146.1579687078593; Wed, 22 Jan 2020 01:57:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579687078; cv=none; d=google.com; s=arc-20160816; b=Zx7rAEAwJNbm3RlR3mpu/BXwcUywgdqC8kaQFTDVtM8IiPz4QsVa1ZdKeq8yeqxgSO enaDYx9esU/+Sw7kiOpPpdWD3cbL+aX275o8DCTv95SKD3SJqjR86xDdDsFpOQike2lN 6ulqlmwT+MLrXiGBP3RkwhwTPIZi3q0y39sFjaZ5+kkpSIXYYc6F+KqyBxV0JscBcj2H h4DdpErZKLVp2hKM4oY2WTxipVfZGnTAm05g3k58Fy/5YrDkTSW1ENakEcYnnu465oUq BjHRvtLbTat1aHt21btIdpHkhMtaRQ9+1jbNwmE3N2R/MLNP9Uu2TOAZTXQ7emqaFcES QVQw== 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=tdQdIwIVJSyAd4kCD/YRgCNK4RwidG4Ai5C91Rn9xfA=; b=xPfqBk0cbpo36A/2hTFr9D0Rlvr1W2fDDSUJDcj5ylG2FMiet6e72+6jh9+6LKqQcP SKnb6yT2zJ8HB7Hu0nMg1VojHJaBzfiY0iNBhfBGENPn4gPMKVJSFoACAAQ/sACmQlw6 ei0WUTNkuSH/jSXAxkQWmXACNhW5J/nVV1CQTkazqXbBB0ZaNbe38eiJ3jfXtmB/+u2S BFtkNzFGxkKWlLpCpis4UT2P5CH6q4XGWmoFG97BBPtr/wZXNou0vVn8rmngSR4Mhaxy GXDu3GFx4yDemNcKA55ZiTIzlGWPEDSsXJNIkJenQmuBuGhVAUZxDzN/EszOYGnS4qmF +mUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0eYIDu07; 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 f4si20407781oij.133.2020.01.22.01.57.47; Wed, 22 Jan 2020 01:57:58 -0800 (PST) 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=0eYIDu07; 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 S1729279AbgAVJbr (ORCPT + 99 others); Wed, 22 Jan 2020 04:31:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:44122 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729098AbgAVJbq (ORCPT ); Wed, 22 Jan 2020 04:31:46 -0500 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 F052C24673; Wed, 22 Jan 2020 09:31:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579685505; bh=62CaeQJ0JUcbdrdg2jERlWMrIGsf4S0C9dn2NIYUVJw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0eYIDu0772dN7XVE0gDLRAay8Dyoe+39FDf2b6M50aPTqIZDZDAKko8TWw6G5KHX5 LygkX3DS8GvF/1m14rwxSjt5yHarWv3+wLOO4fSSpxhkZFSo0X2ZJfQyE6I8GrQ6z/ pfgXncyGE7E2JCddWCO20ba0eHguI9hF7ub3MdZ0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Martin K. Petersen" , Ming Lei , Mikulas Patocka , Jens Axboe Subject: [PATCH 4.4 42/76] block: fix an integer overflow in logical block size Date: Wed, 22 Jan 2020 10:28:58 +0100 Message-Id: <20200122092756.771105594@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092751.587775548@linuxfoundation.org> References: <20200122092751.587775548@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: Mikulas Patocka commit ad6bf88a6c19a39fb3b0045d78ea880325dfcf15 upstream. Logical block size has type unsigned short. That means that it can be at most 32768. However, there are architectures that can run with 64k pages (for example arm64) and on these architectures, it may be possible to create block devices with 64k block size. For exmaple (run this on an architecture with 64k pages): Mount will fail with this error because it tries to read the superblock using 2-sector access: device-mapper: writecache: I/O is not aligned, sector 2, size 1024, block size 65536 EXT4-fs (dm-0): unable to read superblock This patch changes the logical block size from unsigned short to unsigned int to avoid the overflow. Cc: stable@vger.kernel.org Reviewed-by: Martin K. Petersen Reviewed-by: Ming Lei Signed-off-by: Mikulas Patocka Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- block/blk-settings.c | 2 +- drivers/md/dm-snap-persistent.c | 2 +- drivers/md/raid0.c | 2 +- include/linux/blkdev.h | 8 ++++---- 4 files changed, 7 insertions(+), 7 deletions(-) --- a/block/blk-settings.c +++ b/block/blk-settings.c @@ -349,7 +349,7 @@ EXPORT_SYMBOL(blk_queue_max_segment_size * storage device can address. The default of 512 covers most * hardware. **/ -void blk_queue_logical_block_size(struct request_queue *q, unsigned short size) +void blk_queue_logical_block_size(struct request_queue *q, unsigned int size) { q->limits.logical_block_size = size; --- a/drivers/md/dm-snap-persistent.c +++ b/drivers/md/dm-snap-persistent.c @@ -17,7 +17,7 @@ #include "dm-bufio.h" #define DM_MSG_PREFIX "persistent snapshot" -#define DM_CHUNK_SIZE_DEFAULT_SECTORS 32 /* 16KB */ +#define DM_CHUNK_SIZE_DEFAULT_SECTORS 32U /* 16KB */ #define DM_PREFETCH_CHUNKS 12 --- a/drivers/md/raid0.c +++ b/drivers/md/raid0.c @@ -83,7 +83,7 @@ static int create_strip_zones(struct mdd char b[BDEVNAME_SIZE]; char b2[BDEVNAME_SIZE]; struct r0conf *conf = kzalloc(sizeof(*conf), GFP_KERNEL); - unsigned short blksize = 512; + unsigned blksize = 512; if (!conf) return -ENOMEM; --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -264,6 +264,7 @@ struct queue_limits { unsigned int max_sectors; unsigned int max_segment_size; unsigned int physical_block_size; + unsigned int logical_block_size; unsigned int alignment_offset; unsigned int io_min; unsigned int io_opt; @@ -273,7 +274,6 @@ struct queue_limits { unsigned int discard_granularity; unsigned int discard_alignment; - unsigned short logical_block_size; unsigned short max_segments; unsigned short max_integrity_segments; @@ -975,7 +975,7 @@ extern void blk_queue_max_discard_sector unsigned int max_discard_sectors); extern void blk_queue_max_write_same_sectors(struct request_queue *q, unsigned int max_write_same_sectors); -extern void blk_queue_logical_block_size(struct request_queue *, unsigned short); +extern void blk_queue_logical_block_size(struct request_queue *, unsigned int); extern void blk_queue_physical_block_size(struct request_queue *, unsigned int); extern void blk_queue_alignment_offset(struct request_queue *q, unsigned int alignment); @@ -1193,7 +1193,7 @@ static inline unsigned int queue_max_seg return q->limits.max_segment_size; } -static inline unsigned short queue_logical_block_size(struct request_queue *q) +static inline unsigned queue_logical_block_size(struct request_queue *q) { int retval = 512; @@ -1203,7 +1203,7 @@ static inline unsigned short queue_logic return retval; } -static inline unsigned short bdev_logical_block_size(struct block_device *bdev) +static inline unsigned int bdev_logical_block_size(struct block_device *bdev) { return queue_logical_block_size(bdev_get_queue(bdev)); }