Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp2621661rwo; Sun, 23 Jul 2023 20:42:15 -0700 (PDT) X-Google-Smtp-Source: APBJJlEqbVpgCiiKaI68HhOCx93JJBxvrWvcXiwWhA1wO7nUfAZc1Y7umSMrBSNLgPUq6tWa1Tmt X-Received: by 2002:a17:907:7759:b0:992:630f:98b6 with SMTP id kx25-20020a170907775900b00992630f98b6mr8950470ejc.37.1690170135513; Sun, 23 Jul 2023 20:42:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690170135; cv=none; d=google.com; s=arc-20160816; b=DOejRYKlrIJoJkwA67IOIMGWwUHi0sDcUNq5weOjjTRItOj5pkUs+0qFng6lHWDGVB J6YyOCUkgTE5Lh/6MvLmG6Dl4xUb6wwdW3P6Koy7DsP5nZcRYhtCIouylymUUvN1jcTt GoCaxfP7V9TyK7N2/Vg3zB8G0VSMOEqRa6Naa98DqzNfKpjj30gHjXFI+MGOnS/W7PsN Cdz7ITDFw2Nft0zZty9pg+gjSb17xUAR4BikRmXyZeRelh+N7/+J7ymNGCyBJpKdvBTq t1773RDYpw9lD5vXLdtRlXfkeYdUkluAVbD9ZPRodzXLkT7NShhwZwZIqvqqbSrz0qpk YsRw== 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 :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=5oulm+l0zzAQxfTdTaaD6NjaEpendlfz/EezECExxjA=; fh=Fs3Fw3RKWzvw+oB1l/dXbq1n6HOFdU/3MUGmpf4Jwi4=; b=iwyifCfHFjwh4H2v6ZXGvrEylmnv0DUWxDxEUkNbYdemVXSoUURpWcw103GjY6oBCO JJn+GUmgmeKIHwxtrIYCy4pDhlHdXWMNpBPgnLL3cgpGL1VEPXjNE7/SRbpzPADz8Bk+ LZBLTEkd5W6DvXMUFidddyYcoj6s+MCz7THER0tF+aoZSeOMol8MgZ1ybOgCzxmP1sxP CPU15b2S6laoseacumPmaesFIrdygLbd92Ka5VCBNwa1eAXsLa/bFx+9crSyIy7qt+u2 tss1XESA9NiTQ4syxV+Eu9/GODJS7GlRPOSZBf6+Oji4nR5nxLlOWNl3UNByL9C0aOlT m+RQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a170906050d00b00992e23ef220si5923214eja.567.2023.07.23.20.41.50; Sun, 23 Jul 2023 20:42:15 -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 S230022AbjGXC3f (ORCPT + 99 others); Sun, 23 Jul 2023 22:29:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230178AbjGXC3d (ORCPT ); Sun, 23 Jul 2023 22:29:33 -0400 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 163D6180; Sun, 23 Jul 2023 19:29:24 -0700 (PDT) Received: from mail02.huawei.com (unknown [172.30.67.143]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4R8NvS0qN1z4f3jq6; Mon, 24 Jul 2023 10:11:48 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP4 (Coremail) with SMTP id gCh0CgAHoZTj3b1kkguwOg--.21875S3; Mon, 24 Jul 2023 10:11:48 +0800 (CST) Subject: Re: [PATCH v2] md: raid1: fix potential OOB in raid1_remove_disk() To: Zhang Shurong , song@kernel.org, yukuai1@huaweicloud.com Cc: linux-raid@vger.kernel.org, linux-kernel@vger.kernel.org, "yukuai (C)" References: From: Yu Kuai Message-ID: Date: Mon, 24 Jul 2023 10:11:46 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=gbk; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID: gCh0CgAHoZTj3b1kkguwOg--.21875S3 X-Coremail-Antispam: 1UD129KBjvdXoW7XrWfJw15Ww47KFykWryrCrg_yoWktrcE9F yjva4rXF4IqryIkw47Ww1fZr9Ika4kWa1rZayFgF98Wa4Duw4Fgryku348XasxKryaqr17 Ar1DW348Ars3ujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUb4xFF20E14v26r4j6ryUM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8w A2z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j 6F4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oV Cq3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0 I7IYx2IY67AKxVWUJVWUGwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r 4UM4x0Y48IcVAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwCYjI0SjxkI62AI1cAE67vI Y487MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI 0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y 0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxV WUJVW8JwCI42IY6xAIw20EY4v20xvaj40_WFyUJVCq3wCI42IY6I8E87Iv67AKxVWUJVW8 JwCI42IY6I8E87Iv6xkF7I0E14v26r1j6r4UYxBIdaVFxhVjvjDU0xZFpf9x0JUdHUDUUU UU= X-CM-SenderInfo: 51xn3trlr6x35dzhxuhorxvhhfrp/ X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.0 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, MAY_BE_FORGED,NICE_REPLY_A,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 ?? 2023/07/22 15:53, Zhang Shurong ะด??: > If rddev->raid_disk is greater than mddev->raid_disks, there will be > an out-of-bounds in raid1_remove_disk(). We have already found > similar reports as follows: > > 1) commit d17f744e883b ("md-raid10: fix KASAN warning") > 2) commit 1ebc2cec0b7d ("dm raid: fix KASAN warning in raid5_remove_disk") > > Fix this bug by checking whether the "number" variable is > valid. LGTM Reviewed-by: Yu Kuai > > Signed-off-by: Zhang Shurong > --- > Changes in v2: > - Using conf->raid_disks instead of mddev->raid_disks. > > drivers/md/raid1.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c > index dd25832eb045..80aeee63dfb7 100644 > --- a/drivers/md/raid1.c > +++ b/drivers/md/raid1.c > @@ -1829,6 +1829,10 @@ static int raid1_remove_disk(struct mddev *mddev, struct md_rdev *rdev) > struct r1conf *conf = mddev->private; > int err = 0; > int number = rdev->raid_disk; > + > + if (unlikely(number >= conf->raid_disks)) > + goto abort; > + > struct raid1_info *p = conf->mirrors + number; > > if (rdev != p->rdev) >