Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp2410127rda; Wed, 25 Oct 2023 01:41:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDTlwb4sf4K+fooIS/TuwfzTLqNqh5H4NecgpJx0OlFxBhWMHE1DKzCz7cw82X598Oiz+F X-Received: by 2002:a25:a2cf:0:b0:da0:46fa:cabe with SMTP id c15-20020a25a2cf000000b00da046facabemr3593691ybn.7.1698223310838; Wed, 25 Oct 2023 01:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698223310; cv=none; d=google.com; s=arc-20160816; b=iQnJU2eahE7wDwz3FpoQO0vJPAorFHICfT3NHtKFs5i0eQQ+LCIhdgJkfG0/W0pO+h EW1xQgfYwitGK9GkG1uiLg/2f23GYVuPSN9Rq53YeK4ladpGI+TfaBojTaxYI1b2z+fE sh1E+OPySZww3nqFULuYsdWREc2CHMrEMg+G7exPUNJB+t+gj44anbLDI3uTIgvGVjcx tJ2axZaN86VhUlcXmDBpULWSjaz+7PdJYHx39ayVqzFQHA8YTOT9+ndswOIOvltMQ4zQ EQLeaaPBZ9PRbggr1MSrtPdbAjSa6lXNOjoydHHxKUma05WGirliENw8fTuAvAEqNhO7 9QBw== 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=V/a/wka1VWzkFibLT8CIZpQJ2KvdzAeiggt2PSW1Rx4=; fh=L3+K76KI5tA2UtFnKS7JQ52SiXny7FyjD9pAColV6jE=; b=p/AqptR091cs27BHtWnGRk+h/zkaO+Rv+V2MbHkhKnhE8BcUqbgbTh5XPuuNVuPoek uK5Da67znSy8k3obLtI7T1fGJeAyaMEsOvD+o+oylhYmFtvDYGPAehDwJUBa/ndBZP4n CXOnWZTioBC2p5vAflYkfQchalqG+RqRnnlx9E6WoHxDVD4+oEJlRHnIi2CUrl8SOBfS mv8LbvLXpHs/s8gTJMKOTe/RNKtr+RFmMOe0sdSk0DfdzXcTAgM0xxJa5WRy59kxRqlq BhcV87C7QkmgrpXB26QdyZBW0QGH3OlELZ0N7Ed1FO04CXoTqjziTeJxEoX7fnQcbmcM 2mmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id 8-20020a251908000000b00da086d7a8b0si355741ybz.339.2023.10.25.01.41.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 01:41:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 89C26801BE5E; Wed, 25 Oct 2023 01:41:49 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232897AbjJYIlr (ORCPT + 99 others); Wed, 25 Oct 2023 04:41:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230217AbjJYIlr (ORCPT ); Wed, 25 Oct 2023 04:41:47 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 192C39C; Wed, 25 Oct 2023 01:41:45 -0700 (PDT) Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4SFj8N0lhxz4f3prr; Wed, 25 Oct 2023 16:41:40 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 06C941A016E; Wed, 25 Oct 2023 16:41:42 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgDHXd3E1DhlVE+YDw--.27079S4; Wed, 25 Oct 2023 16:41:41 +0800 (CST) From: Zhong Jinghua To: axboe@kernel.dk, penguin-kernel@i-love.sakura.ne.jp Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, zhongjinghua@huawei.com, yi.zhang@huawei.com, yukuai3@huawei.com Subject: [PATCH] block: Fix minor range check in device_add_disk() Date: Wed, 25 Oct 2023 16:46:21 +0800 Message-Id: <20231025084621.2338604-1-zhongjinghua@huaweicloud.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgDHXd3E1DhlVE+YDw--.27079S4 X-Coremail-Antispam: 1UD129KBjvdXoWrur4rKF4kJw1rCF4rtFW3Awb_yoWDCFX_Gr y5Xr95Wr1rWr1rCrn8urnFyry0yr95Way8CFy0vFZxXayxCF9Fq34DKr1FgF1DWFyjkFW5 ur1UZrn8tr4IkjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbr8YFVCjjxCrM7AC8VAFwI0_Gr0_Xr1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwV A0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVWDJVCq3wA2z4x0Y4vE2Ix0cI8IcVCY1x02 67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I 0E14v26rxl6s0DM2AIxVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40E x7xfMcIj6xIIjxv20xvE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x 0Yz7v_Jr0_Gr1lF7xvr2IYc2Ij64vIr41l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Y z7v_Jr0_Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zV AF1VAY17CE14v26r126r1DMIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4l IxAIcVC0I7IYx2IY6xkF7I0E14v26r1j6r4UMIIF0xvE42xK8VAvwI8IcIk0rVWrJr0_WF yUJwCI42IY6I8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIY CTnIWIevJa73UjIFyTuYvjxUrR6zUUUUU X-CM-SenderInfo: x2kr0wpmlqwxtxd6x35dzhxuhorxvhhfrp/ X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 25 Oct 2023 01:41:49 -0700 (PDT) From: Zhong Jinghua Checks added in patch: commit e338924bd05d ("block: check minor range in device_add_disk()") ignore the problem of first_minore < 0 and disk->minors < 0. Fix it by adding first_minore < 0 and disk->minors < 0 check. Fixes: e338924bd05d ("block: check minor range in device_add_disk()") Signed-off-by: Zhong Jinghua --- block/genhd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/genhd.c b/block/genhd.c index 736215e9ddc3..8292a1e265cf 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -432,7 +432,9 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, DISK_MAX_PARTS); disk->minors = DISK_MAX_PARTS; } - if (disk->first_minor + disk->minors > MINORMASK + 1) + if (disk->first_minor > MINORMASK || + disk->minors > (1U << MINORBITS) || + disk->first_minor + disk->minors > MINORMASK + 1) goto out_exit_elevator; } else { if (WARN_ON(disk->minors)) -- 2.31.1