Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2612389rdh; Mon, 30 Oct 2023 02:32:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGDhcIK5GTRXHbE39Kwmn1v8lgZjAVskRznzY4369e3B7BTcVTC1qGHvM4uUWximERNUKNC X-Received: by 2002:a05:6358:590c:b0:168:e26e:81e3 with SMTP id g12-20020a056358590c00b00168e26e81e3mr8738720rwf.6.1698658352273; Mon, 30 Oct 2023 02:32:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698658352; cv=none; d=google.com; s=arc-20160816; b=LoHT2a3F3OczMXylGj9hrUfAJbQJS0Vi5QIx1oQvLS4NXO9eUtZ9Ca2pX9Qkfwzka0 0WMzLFphEtiXBKJkbRnnSdRmv972JZAHVN8w05wc+kSsQMohxxeWI6DKeZ3sC6FKw/wH UTf+pH2db/k8q1H+Y1ewsIsUqF98evYLuJJZeR5CvRgMYqkXDL/GV1PYbTGruncwQtx7 Bo5wTGyJx0YG4mtT2LxSH+mtr6H2mu6D7FmeT54Edm1IzAr/JiJNJDINXyidQhFr8d3T 1ui8QqAQ3ys89oFxrr+7O38sXygR3Gr8QQdo4Ezp/KZNnOmgSat6yv0LH2G171AxXO+o BCpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=MlNiK/v5RlteZv765qNjlBbglFMpYtg73MTrSoC1Sow=; fh=gEcrYIHD5FhGQlEcshl6HCU1Wgi1E2xu4yJzyf5ddZQ=; b=cztkTUjOo5Wy0QsZwa+oBhxkBwvJyka6w6xzodOI3BcMST8VpgmTPsMRbah9lgLW6Q FXUjkhoB225rYuv333sLEjLzG5OnqgKy/lcZVL/OwqtdFmsjbyez2CmquZGbP5fbmSgh WMX3J5AeQce1s36E5gKhvHau+H2o05HofnvEihqJ5BHDVaOtBEbLyFSuLLingAwuurVG FBGm1/hsUZ1LL7HlTqlnt6jxfabBZ80TziGWJ+bSbXHEJJ2JyBRwNC+HRkMViVnjN7XO VhbYPIngr8QGuTEt450OJI7yrI7Iv9MnK2xPIQjBHYRULuUbLu2jLsv5H8fOMuRUDmOI 1ogQ== 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id m9-20020a654389000000b005b881a12a14si4756802pgp.226.2023.10.30.02.32.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 02:32:32 -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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id DA65D80C1121; Mon, 30 Oct 2023 02:32:30 -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 S232471AbjJ3Jc3 (ORCPT + 99 others); Mon, 30 Oct 2023 05:32:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232119AbjJ3Jc2 (ORCPT ); Mon, 30 Oct 2023 05:32:28 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20782C1; Mon, 30 Oct 2023 02:32:26 -0700 (PDT) Received: from kwepemm000002.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4SJny15KZ4zVlw4; Mon, 30 Oct 2023 17:28:25 +0800 (CST) Received: from [10.174.178.159] (10.174.178.159) by kwepemm000002.china.huawei.com (7.193.23.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Mon, 30 Oct 2023 17:32:22 +0800 Message-ID: <53e9d294-46dc-90ae-c0ef-af09c658a80e@huawei.com> Date: Mon, 30 Oct 2023 17:32:09 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH] block: Fix minor range check in device_add_disk() To: Yu Kuai , zhongjinghua , Tetsuo Handa , CC: , , , "yukuai (C)" References: <20231025084621.2338604-1-zhongjinghua@huaweicloud.com> <119b7314-10a9-4d62-b40f-19462dc68009@I-love.SAKURA.ne.jp> <26bafe93-345d-2696-8ee7-7d1baa0e7eb7@huaweicloud.com> From: zhongjinghua In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.178.159] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000002.china.huawei.com (7.193.23.144) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS 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]); Mon, 30 Oct 2023 02:32:31 -0700 (PDT) 在 2023/10/30 17:26, Yu Kuai 写道: > Hi, > > 在 2023/10/26 16:52, zhongjinghua 写道: >> >> 在 2023/10/25 18:06, Tetsuo Handa 写道: >>> On 2023/10/25 17:46, Zhong Jinghua wrote: >>>> 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. >>> What is the problem of first_minor < 0 or disk->minors < 0 ? >>> Are negative values legal/illegal ? >> >> These two values are used as the secondary device number and the >> maximum number of partitions, which is illegal if negative. Then >> first_minore and disk->minors are signed numbers, and the sum may be >> less than MINORMASK to bypass the check. > > Let me complement it, first_minor and minors can be set by driver, and > driver allow set them throuhh ioctl/sysfs from user parameters, for > example: > > If user pass in -1, and each disk support 8 partitions, driver will > usually set: > > disk->first_minor = -1 * 8 = -8; > disk->minors = 8; > > Then first_minor + minors = 0, then the following condition can't detect > this case: > > if (disk->first_minor + disk->minors > MINORMASK + 1) > > By the way, we never limit how first_minor and minors is set by driver, > and it's illegal if driver set first_minor = -4, and minors = 8. > > Thanks, > Kuai > >> >> . >> > Kuai, Thank for your explanation. Jinghua