From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7DCBC4167D for ; Mon, 30 Oct 2023 09:32:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232476AbjJ3Jc3 (ORCPT ); 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 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