From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A72A1865F for ; Wed, 20 Sep 2023 12:42:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3262C433C9; Wed, 20 Sep 2023 12:42:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1695213760; bh=VUZMGl6F3/61KOFwk0MQ9esFYYV/gvnwuE5fL357IVQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OG6WWQHdhWEzBRjax62czIZgNqUur5l/STtow1K9kGtA6dSc4QOaKtYQR22kewfav x6vfCokiUE2Y6Jzn1tUGeZFbMISHwt+b2PqmWLrqDB4VwhdoLahLEIgj8K+OhRaTGf ZZJs2j9JJ+ybe6+uKpWZy5j3LNRpwXxdATegaaz4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhang Shurong , Yu Kuai , Song Liu , Sasha Levin Subject: [PATCH 5.4 329/367] md: raid1: fix potential OOB in raid1_remove_disk() Date: Wed, 20 Sep 2023 13:31:46 +0200 Message-ID: <20230920112907.047346156@linuxfoundation.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20230920112858.471730572@linuxfoundation.org> References: <20230920112858.471730572@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhang Shurong [ Upstream commit 8b0472b50bcf0f19a5119b00a53b63579c8e1e4d ] 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. Signed-off-by: Zhang Shurong Reviewed-by: Yu Kuai Link: https://lore.kernel.org/r/tencent_0D24426FAC6A21B69AC0C03CE4143A508F09@qq.com Signed-off-by: Song Liu Signed-off-by: Sasha Levin --- drivers/md/raid1.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 1919de4c8c12d..f96e079454700 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -1808,6 +1808,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) -- 2.40.1