Received: by 2002:a05:6a10:c604:0:0:0:0 with SMTP id y4csp432172pxt; Thu, 12 Aug 2021 01:42:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHyK+rLkO0GRfxDCUUKSDMPmKfWxKc7RopRQYW72W8nWVt2x/nTa28wbmcYXKxCHaghR0X X-Received: by 2002:a05:6402:3481:: with SMTP id v1mr4104568edc.60.1628757768406; Thu, 12 Aug 2021 01:42:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628757768; cv=none; d=google.com; s=arc-20160816; b=BwTvbu+un2aSWTNzgIb0W0zJf7vCYQTuK4bUOYm/CXbbSqlPL+7DPrnz0Qezvw8IcX M90Fv1ETFYjfJq75d3Gmdv98bzVy9tc2Mm8eCAfZ5etXiysmWV9ckixAUAGcoHo0V44a jQfjEIPo+4Odi8IyjuCyJlr3jyZq984qlM+tz9/WtcBLa199qvVa3E3fDAXIJS/5Chbj HHbBF1OOI1WaVZesibkjDUUo1re9XDEZ6KwLsYL87c0WwjOJ//NeD/h99zcNIZvRygv3 CGVC1xYbBAqZeb/0zXCmHUMCu9SuCLun7W/QEW+rnAfmEOtCsQA2rkun5pO3SuPz8yZk YKOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=n6cWVVIy3iMBqrtAUXp+jl7KTERUu2A3VxrbhkcBN0s=; b=NMt5znX+p81Hyd853vBKbwLKzZ0Mnr6qJuwmOrdZnOf1x6wc/eaWaNYcq1xMu3kYEW UIXzLaqh9ADFKuK9l6scI5FhGAl/1wgUBSFFA7/rLPKlR/C3xspSx1NG0iRxtEaoXf09 88djf6nKWsEwh6ltd3Ps7mEQIguiQ39qMS166uRi8fRNMbQITC1V5YJf8S506qsPLmm5 JJt7iCFuEpdSbHXqHdZbVXnF9Mve9yHGVSyP9Z9QT5otNaCnGTAew1+FyVk+TdPtHC/8 VSWP3/dCH/ksx4l9h+se4Ygnpvi4zv1/mTvZ6d82uSwifKrvkY5f+eK3s4sV0L7tOJ/K Fwig== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q15si2135964edr.337.2021.08.12.01.42.25; Thu, 12 Aug 2021 01:42:48 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235128AbhHLIWb (ORCPT + 99 others); Thu, 12 Aug 2021 04:22:31 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:17007 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234199AbhHLIWb (ORCPT ); Thu, 12 Aug 2021 04:22:31 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Glfhb3gDkzb17L; Thu, 12 Aug 2021 16:18:23 +0800 (CST) Received: from dggpemm500004.china.huawei.com (7.185.36.219) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 12 Aug 2021 16:22:00 +0800 Received: from huawei.com (10.175.124.27) by dggpemm500004.china.huawei.com (7.185.36.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 12 Aug 2021 16:22:00 +0800 From: Laibin Qiu To: CC: , , , Subject: [PATCH -next] loop: fix loop_validate_block_size() can't make sense Date: Thu, 12 Aug 2021 16:34:53 +0800 Message-ID: <20210812083453.761319-1-qiulaibin@huawei.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.124.27] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500004.china.huawei.com (7.185.36.219) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We config the block size of a loop device throuth the following process: lo_ioctl(..., unsigned long arg) | ^^^^ lo_simple_ioctl(..., unsigned long arg) | ^^^^ loop_set_block_size(..., unsigned long arg) | ^^^^ loop_validate_block_size(unsigned short bsize) | ^^^^^ blk_queue_logical_block_size(..., unsigned int size) { ''' limits->logical_block_size = size; ^^^^ int ''' } loop_validate_block_size() will check the validity of bsize. But long to short will be truncated(eg arg=1049600 and it becomes 1024 after truncation by short. The block size must within the range of 512 ~ PAGE_SZIE, This truncation will turn illegal block szie to legal). The wrong of block size will raise other errors. Fixes: 3448914e8cc55 ("loop: Add LOOP_CONFIGURE ioctl") Signed-off-by: Laibin Qiu --- drivers/block/loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index fa1c298a8cfb..8fd551c00a9b 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -277,7 +277,7 @@ static void __loop_update_dio(struct loop_device *lo, bool dio) * @bsize: size to validate */ static int -loop_validate_block_size(unsigned short bsize) +loop_validate_block_size(unsigned long bsize) { if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize)) return -EINVAL; -- 2.22.0