Message ID | 20230506012315.3370489-2-linan666@huaweicloud.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp796461vqo; Fri, 5 May 2023 18:33:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Ery3EttPAJBwD5SbvfmTQfNaDiZQgLfqVaTe/s2OkSodYZ73UATRcGMLPTJaR4BUdguwP X-Received: by 2002:a17:90b:3609:b0:247:2437:d5c4 with SMTP id ml9-20020a17090b360900b002472437d5c4mr3523936pjb.13.1683336793596; Fri, 05 May 2023 18:33:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683336793; cv=none; d=google.com; s=arc-20160816; b=EprFYZ1nvdPhAqUDZgV5mhaFwMSOcnK6WO/PJq4FP/O4AmeNqIw0OAmpQj54y5Cife SBgxw9i9gygbco3zvpASMoTYXcH/4+vc6BUvpxp1wbZobWOALzMHgws8oSehQv3YSVlx F00uzgWjEd8zmgv6jxgwy+MQ7rf9dFXOOsCO1E+fqt5vJur7tn48wXtK9biUtmFMSY2Z 4/j//kAk7PVzGE5A1o0o1Jm8A+0JqSErJ35fXCy8BFFrLpNvNXt5GqeeHake6Mt0QSZH pXIjIQ8BYp4QPvfkqB2LZqj8Xk0Z97yRK9dC4V9mF7jpI3tTeH4fJb6ywIPyz80m8eNR MCbg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=MDAApK1+Bape1Mbk3b7UpgmvTNkB6dN/EwU0JL93pQs=; b=0g0ljJySoGiVwhu6bfcruTQKw43c/Bi5Wl5L9/NAPrQWk1Ty3GQ5YlICLECauWtPqm kOhNSEntOe/VfivTIw1f4DChy/PTS3b0KiffxapA4T20AUSdv5pv5q31i3vBabTTiEcp w2qq0NGk+yPbWBinOi1FrERJIuQ7mNSgv4FhZFnjYGFNA69kWs42Ub7+JF4y0On0CfHg XUUBas7MiRvD5ryK045fwSQe/x6kTGIMNjWnlIza3Ccp05h/GFDUd+Z/ddO6GzS3peGV CPJ3Jr9I/xKuppA2k88lw4xjjkzCtku02bwkL8PY+uTw+uBLHlUo+o1ChloLgtATmcUL UAUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b133-20020a63348b000000b0051802927ee1si3427656pga.330.2023.05.05.18.33.00; Fri, 05 May 2023 18:33:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231940AbjEFBYl (ORCPT <rfc822;baris.duru.linux@gmail.com> + 99 others); Fri, 5 May 2023 21:24:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231428AbjEFBY3 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 5 May 2023 21:24:29 -0400 Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E98547293; Fri, 5 May 2023 18:24:27 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4QCqbC4dFjz4f3pxk; Sat, 6 May 2023 09:24:23 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.127.227]) by APP4 (Coremail) with SMTP id gCh0CgD3X7NHrFVkfh1lIw--.56086S5; Sat, 06 May 2023 09:24:24 +0800 (CST) From: linan666@huaweicloud.com To: song@kernel.org, neilb@suse.de, Rob.Becker@riverbed.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, linan122@huawei.com, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Subject: [PATCH v2 1/4] md/raid10: fix slab-out-of-bounds in md_bitmap_get_counter Date: Sat, 6 May 2023 09:23:12 +0800 Message-Id: <20230506012315.3370489-2-linan666@huaweicloud.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20230506012315.3370489-1-linan666@huaweicloud.com> References: <20230506012315.3370489-1-linan666@huaweicloud.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgD3X7NHrFVkfh1lIw--.56086S5 X-Coremail-Antispam: 1UD129KBjvdXoWrur48urW5XF4UKw4rZFy7Jrb_yoWDXrc_Ca 4FqFyxJrW7CFy3AwnxXw4xZrWjyw4Du3ZruFsaqrySvF18u343WrWvyrnxt3WxGrWj9345 Jryjgayrur4YkjkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbk8YFVCjjxCrM7AC8VAFwI0_Xr0_Wr1l1xkIjI8I6I8E6xAIw20E Y4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jr0_Jr4l82xGYIkIc2x26280x7IE14v26r18M2 8IrcIa0xkI8VCY1x0267AKxVWUCVW8JwA2ocxC64kIII0Yj41l84x0c7CEw4AK67xGY2AK 021l84ACjcxK6xIIjxv20xvE14v26w1j6s0DM28EF7xvwVC0I7IYx2IY6xkF7I0E14v26r 4UJVWxJr1l84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ GcCE3s1lnxkEFVAIw20F6cxK64vIFxWle2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64 xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j 6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwACI402YVCY1x02628vn2 kIc2xKxwAKzVCY07xG64k0F24l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_ Gr1lx2IqxVAqx4xG67AKxVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17 CE14v26r1q6r43MIIYrxkI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Jr0_JF4lIxAIcVC0 I7IYx2IY6xkF7I0E14v26r4j6F4UMIIF0xvE42xK8VAvwI8IcIk0rVWUJVWUCwCI42IY6I 8E87Iv67AKxVWUJVW8JwCI42IY6I8E87Iv6xkF7I0E14v26r4j6r4UJbIYCTnIWIevJa73 UjIFyTuYvjxUwkucDUUUU X-CM-SenderInfo: polqt0awwwqx5xdzvxpfor3voofrz/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765106561314571619?= X-GMAIL-MSGID: =?utf-8?q?1765106561314571619?= |
Series |
md: bugfix of writing raid sysfs
|
|
Commit Message
Li Nan
May 6, 2023, 1:23 a.m. UTC
From: Li Nan <linan122@huawei.com> If we write a large number to md/bitmap_set_bits, md_bitmap_checkpage() will return -EINVAL because "page >= bitmap->pages", but the return value was not checked immediately in md_bitmap_get_counter() in order to set *blocks value and slab-out-of-bounds occurs. Return directly if err is -EINVAL. Fixes: ef4256733506 ("md/bitmap: optimise scanning of empty bitmaps.") Signed-off-by: Li Nan <linan122@huawei.com> Reviewed-by: Yu Kuai <yukuai3@huawei.com> --- drivers/md/md-bitmap.c | 2 ++ 1 file changed, 2 insertions(+)
Comments
On Fri, May 5, 2023 at 6:24 PM <linan666@huaweicloud.com> wrote: > > From: Li Nan <linan122@huawei.com> > > If we write a large number to md/bitmap_set_bits, md_bitmap_checkpage() > will return -EINVAL because "page >= bitmap->pages", but the return value > was not checked immediately in md_bitmap_get_counter() in order to set > *blocks value and slab-out-of-bounds occurs. > > Return directly if err is -EINVAL. > > Fixes: ef4256733506 ("md/bitmap: optimise scanning of empty bitmaps.") > Signed-off-by: Li Nan <linan122@huawei.com> > Reviewed-by: Yu Kuai <yukuai3@huawei.com> > --- > drivers/md/md-bitmap.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c > index 920bb68156d2..0b41ef422da7 100644 > --- a/drivers/md/md-bitmap.c > +++ b/drivers/md/md-bitmap.c > @@ -1388,6 +1388,8 @@ __acquires(bitmap->lock) > int err; > > err = md_bitmap_checkpage(bitmap, page, create, 0); > + if (err == -EINVAL) > + return NULL; This logic is error prone. Since we are on it, let's fix it better. Specifically, we can move "page >= bitmap->pages" check out of md_bitmap_checkpage(). (and fix the call site in md_bitmap_resize for clustered md). Also, could you please add a mdadm test for this issue? Thanks, Song > > if (bitmap->bp[page].hijacked || > bitmap->bp[page].map == NULL) > -- > 2.31.1 >
在 2023/5/13 9:05, Song Liu 写道: > On Fri, May 5, 2023 at 6:24 PM <linan666@huaweicloud.com> wrote: >> >> From: Li Nan <linan122@huawei.com> >> >> If we write a large number to md/bitmap_set_bits, md_bitmap_checkpage() >> will return -EINVAL because "page >= bitmap->pages", but the return value >> was not checked immediately in md_bitmap_get_counter() in order to set >> *blocks value and slab-out-of-bounds occurs. >> >> Return directly if err is -EINVAL. >> >> Fixes: ef4256733506 ("md/bitmap: optimise scanning of empty bitmaps.") >> Signed-off-by: Li Nan <linan122@huawei.com> >> Reviewed-by: Yu Kuai <yukuai3@huawei.com> >> --- >> drivers/md/md-bitmap.c | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c >> index 920bb68156d2..0b41ef422da7 100644 >> --- a/drivers/md/md-bitmap.c >> +++ b/drivers/md/md-bitmap.c >> @@ -1388,6 +1388,8 @@ __acquires(bitmap->lock) >> int err; >> >> err = md_bitmap_checkpage(bitmap, page, create, 0); >> + if (err == -EINVAL) >> + return NULL; > > This logic is error prone. Since we are on it, let's fix it better. > Specifically, we can move "page >= bitmap->pages" check out I will check out it in v3. > of md_bitmap_checkpage(). (and fix the call site in md_bitmap_resize > for clustered md). > In md_bitmap_resize(), incoming parameters "page < bitmap->counts.page" and do not have this problem. > Also, could you please add a mdadm test for this issue? > It's my pleasure. > Thanks, > Song > >> >> if (bitmap->bp[page].hijacked || >> bitmap->bp[page].map == NULL) >> -- >> 2.31.1 >> > . Thanks for your suggesion.
diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index 920bb68156d2..0b41ef422da7 100644 --- a/drivers/md/md-bitmap.c +++ b/drivers/md/md-bitmap.c @@ -1388,6 +1388,8 @@ __acquires(bitmap->lock) int err; err = md_bitmap_checkpage(bitmap, page, create, 0); + if (err == -EINVAL) + return NULL; if (bitmap->bp[page].hijacked || bitmap->bp[page].map == NULL)