Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp327840pxf; Thu, 1 Apr 2021 02:08:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyvGWhUt24zyCcRu5qtRN3HcPL/qMF26wOnFebbuaFTTd4viR3HBTgnqOlrs2cRWQK8SC1I X-Received: by 2002:a17:906:2b46:: with SMTP id b6mr7904031ejg.521.1617268112264; Thu, 01 Apr 2021 02:08:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617268112; cv=none; d=google.com; s=arc-20160816; b=osMNjCBRXP8KqqNsaiclYSYu5R8TzVOhp8EuAuyl71d/dqQlbxArOVgh7yTPjnY6b3 smr7C83McRWJ8DHD4NibfcFOhCUiONK+yZTQyyTm/VQiuD1TZXcRYN49IyFoBuk+VHQb GWWeZDarlX71TOzzn7xK+reifN0iO9aIeWvrJkr6OI1PXrVLljMJ6jmB+xqrG542xWRO oG8/9aA4juNU7D/kARkosXc55upGURskNtLFltXBrQ8wLTthw599DyO8+oSqoGHh+J/m fpKPuQn3L7vggdfxfgTsZFJWwUQAcTANZqzPfgs5ryoAi8Fm3RHQTwxA0ht3TdlRmYEO SGGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=ReHrEfTp3kP25DHRgTl+1yb05oO1E2LBrpNQKz86mGU=; b=n35ecMpXQIFFK5efye6sm9+PkbE2EhKemcgpdr3/uYnQICYrqIU+AZrs3xT1MmGp35 uE+xWttnTHndEUnz5hQsnULmCMpkWhyxys7Xv3xLaja3pp8aEI8DqP48431ofzUYbTQX C9gzLovw4meSXRE5insPhr5fhKUdMofA/Wsqhm5Qqy8lkgGi6DMJx7rbDKhOQDdblGfZ Nv1dGjBMc0vL+HYKBhwLxme0HuFD476qcJc0R+88pqio629AA9rDX1h1W2IYGS85De1B LQmwf0SXU1CU9XUOXW77EdmI3DBgYnthccDZ7P4GXeJ02XipPao5NMy5TIytoJ4bzEgo eiTg== 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 bm6si3738026edb.554.2021.04.01.02.08.10; Thu, 01 Apr 2021 02:08:32 -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 S233327AbhDAJHN (ORCPT + 99 others); Thu, 1 Apr 2021 05:07:13 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:14665 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233496AbhDAJHI (ORCPT ); Thu, 1 Apr 2021 05:07:08 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4F9y116pjhznXBy; Thu, 1 Apr 2021 17:04:21 +0800 (CST) Received: from [127.0.0.1] (10.174.176.117) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.498.0; Thu, 1 Apr 2021 17:06:52 +0800 Subject: Re: [PATCH] brd: fix integer overflow in brd_check_and_reset_par To: lixiaokeng , , , CC: linfeilong References: <99e9da32-9372-ada2-8197-26602fe242c8@huawei.com> From: Zhiqiang Liu Message-ID: Date: Thu, 1 Apr 2021 17:06:52 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <99e9da32-9372-ada2-8197-26602fe242c8@huawei.com> Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Language: en-US X-Originating-IP: [10.174.176.117] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org friendly ping. On 2021/3/25 19:45, lixiaokeng wrote: > The max_part may overflow. For example, > > modprobe brd rd_nr=3 rd_size=102400 max_part=1073741824(2^30) > > Expected result > NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT > ram0 1:0 0 100M 0 disk > ram1 1:256 0 100M 0 disk > ram2 1:512 0 100M 0 disk > > Actual result > NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT > ram0 259:0 0 100M 0 disk > ram1 259:1 0 100M 0 disk > ram2 259:2 0 100M 0 disk > > Fix it. > > Signed-off-by: Lixiaokeng > Signed-off-by: Zhiqiang Liu > --- > drivers/block/brd.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/drivers/block/brd.c b/drivers/block/brd.c > index c43a6ab4b1f3..c91831cd5d2a 100644 > --- a/drivers/block/brd.c > +++ b/drivers/block/brd.c > @@ -457,21 +457,19 @@ static void brd_del_one(struct brd_device *brd) > > static inline void brd_check_and_reset_par(void) > { > - if (unlikely(!max_part)) > + if (unlikely(max_part <= 0)) > max_part = 1; > > /* > * make sure 'max_part' can be divided exactly by (1U << MINORBITS), > * otherwise, it is possiable to get same dev_t when adding partitions. > */ > - if ((1U << MINORBITS) % max_part != 0) > - max_part = 1UL << fls(max_part); > - > if (max_part > DISK_MAX_PARTS) { > pr_info("brd: max_part can't be larger than %d, reset max_part = %d.\n", > DISK_MAX_PARTS, DISK_MAX_PARTS); > max_part = DISK_MAX_PARTS; > - } > + } else if ((1U << MINORBITS) % max_part != 0) > + max_part = 1UL << fls(max_part); > } > > static int __init brd_init(void)