Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3403524rwa; Tue, 23 Aug 2022 04:19:19 -0700 (PDT) X-Google-Smtp-Source: AA6agR621+PPKN/ObgJDVN1gwI9UIXmOCBAkgH5iWalw5RF9Ldvws25Ra8Mh8rinLU8plAaVFyFZ X-Received: by 2002:a63:1cf:0:b0:429:889f:4e60 with SMTP id 198-20020a6301cf000000b00429889f4e60mr20545124pgb.410.1661253559343; Tue, 23 Aug 2022 04:19:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253559; cv=none; d=google.com; s=arc-20160816; b=qNOdrv2P0ISaqJP6RbDphWQ/G1wvsmAYTMxEXCALSiFU5wKp7fQz7fc9/E/qYSf7PE zQFBtaHxL807WzqpvvNRCm6m3loeoaH80XCHemTjLAtpFHQIdHv7Qllqd4gjj/Reprbd iBkXJt8p8KJlD9uHcKFG8PkjdbTitPHjAc7SeQcNfGEEEl0OFTN01SoiWolTWSgFzDrX IYJ87GXWWuJM5WfVVi35tm4z+ho0PRAiL25kDwIqYxSKuJDJpFluLqTnR9xyNQu/m1Ly O9lfxG7WwesQoDpO7F8Fbcl/LAX/wPRHw5GjtnA7VIJ/BDbKEKidTb8mwc8DwN/A9uAx ahyQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kFHdfUmEelu8cvOEtWkjEHkSg5NPNl6b+RmvUhx561k=; b=R2wYT+4qYU1p0U1Uob18a6wufWvqKO3GTyKhDYKVdNpWlSxqosSUpvGWP+d/n6O3qa TjRH3a3ljatIFQGuqOJRqY6daz1pWQrqdK9t6VXOIZVELRhLPxvV89jzzgAhrwkiZDZV c9GgzEdtfAvkJRs+QNAvRpIC6zAyyAtt+oqAPR+qTNROxudqtHea9gpXSBqDBTxS4Pbb elYc9cpAunPtF8segZjhuWHn/2ub7KqXG2223AThu7GS52lvH4ijOGywrQO3uPnb/Glm zVpjrsryd1Qb/Y9Lz673yqYB9DHnZsX5jgJzGAllBmvOYCU9awi1lP1B3SWoqeS39S7N 3S7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WKiyxVG+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ca17-20020a17090af31100b001fae2cf9cb9si11884123pjb.149.2022.08.23.04.19.08; Tue, 23 Aug 2022 04:19:19 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=WKiyxVG+; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354496AbiHWKZr (ORCPT + 99 others); Tue, 23 Aug 2022 06:25:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353609AbiHWKLn (ORCPT ); Tue, 23 Aug 2022 06:11:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CACD8B2; Tue, 23 Aug 2022 01:57:46 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6741C6123D; Tue, 23 Aug 2022 08:57:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F9AEC433C1; Tue, 23 Aug 2022 08:57:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245065; bh=aD74N/hsr51I4dViwIJ6uB1M3qdYNTympSCUrh97GdU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WKiyxVG+FJKu7P0DTkdQ96JBZc5QuKRSYXba2xUymlnLVDWGVrhQxKTKwyxcIAV7c CKxgAu2se2lg5bwH3gsoCJ6ORmLbWuK3sQGhW7pKN7jw2dH5iS2t/hbwGFwM8XtCvW z9EqhbQ3pNy+HQqglikEyG6FWT1S/9KCV5O12YSo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wentao_Liang , Song Liu , Jens Axboe , Sasha Levin Subject: [PATCH 5.15 203/244] drivers:md:fix a potential use-after-free bug Date: Tue, 23 Aug 2022 10:26:02 +0200 Message-Id: <20220823080106.268223829@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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: X-Mailing-List: linux-kernel@vger.kernel.org From: Wentao_Liang [ Upstream commit 104212471b1c1817b311771d817fb692af983173 ] In line 2884, "raid5_release_stripe(sh);" drops the reference to sh and may cause sh to be released. However, sh is subsequently used in lines 2886 "if (sh->batch_head && sh != sh->batch_head)". This may result in an use-after-free bug. It can be fixed by moving "raid5_release_stripe(sh);" to the bottom of the function. Signed-off-by: Wentao_Liang Signed-off-by: Song Liu Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/md/raid5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c index b58984ddca13..19e497a7e747 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -2864,10 +2864,10 @@ static void raid5_end_write_request(struct bio *bi) if (!test_and_clear_bit(R5_DOUBLE_LOCKED, &sh->dev[i].flags)) clear_bit(R5_LOCKED, &sh->dev[i].flags); set_bit(STRIPE_HANDLE, &sh->state); - raid5_release_stripe(sh); if (sh->batch_head && sh != sh->batch_head) raid5_release_stripe(sh->batch_head); + raid5_release_stripe(sh); } static void raid5_error(struct mddev *mddev, struct md_rdev *rdev) -- 2.35.1