Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3321548rwa; Tue, 23 Aug 2022 02:48:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR54uyj2xniJr6euxMhOqUXXHKqLRYcROLXtLlelxflWdIKDbNEnVlpij2fs11nG0A7CRSF6 X-Received: by 2002:a17:906:58c9:b0:730:bc01:fd5f with SMTP id e9-20020a17090658c900b00730bc01fd5fmr15239614ejs.504.1661248081730; Tue, 23 Aug 2022 02:48:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248081; cv=none; d=google.com; s=arc-20160816; b=OUPbSZAR9PhydRFOd+U/urwXnF+QGTOywPhpUm1Zj2Hyp3MOJCDzFUoFPS3ggGwRxG mAzifalHAeDR/+L84ZCMF02Gc2zgpWtoNIX9IAHcXi0moYHdUlmxfVuLKq+Kt9JS/F3p TZ1oAWMJwSq9kJ7Q22AqFERasVbWdvVsXE3+SsJO8M6dyJmIIeHg+ipriEzGUKAc7L9d u05xcXnYaQ2zIc9851LaO2/SO9Qz3O6l0NeXT6BD6SifhVL+Brhx3D/DEULQdTFyfhcb KperUe2MiT2sm3uOBgUAQ5NIrYKqXSgcdk3FKbTt4ogWjJAwjUo7yWZ+zT1EcVpV9/Q2 mtqQ== 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=yJx7nxRbfdmiSpuoijkBzWyJ1SKougaaft4IKfVdyQc=; b=Z+lNz3ALfAeMgnW8FbXOh9978WNcy1it9j+M4XRfoa1XA/Bhq8T9E0sq5aDmjUfaRz BnNYhN/xf9bypNaN72TVAEscPX60v6fdPbeMpuhKIG3VZwVVfggdTML1gyJSr/WfIxTL o3Zt1lFJkbt+TR9zA1zB3seP7m5pKM5sAUzWJYDcRFvIR1ixgV0iBhpDc4s1l335UsVX Rb2G82tHtOOF9mt8St5PCWDsVk5p0/7dHeNdIDAo0zcKUPOfAcz8+LIc6pXC3cOM3wBq jTPfn7fPQ0ZmZFRLJDe5Rh7xwFUDOHZiJu84wHTHXjC6YwJ9YZuR8m5VuKRHKXLlfOKR n4fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Hy4h0ydB; 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 hz2-20020a1709072ce200b0073174501deesi10890898ejc.24.2022.08.23.02.47.36; Tue, 23 Aug 2022 02:48:01 -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=Hy4h0ydB; 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 S232388AbiHWJTD (ORCPT + 99 others); Tue, 23 Aug 2022 05:19:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350022AbiHWJQc (ORCPT ); Tue, 23 Aug 2022 05:16:32 -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 5DF0A883FE; Tue, 23 Aug 2022 01:32:48 -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 2BB67614C2; Tue, 23 Aug 2022 08:32:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 300ABC433C1; Tue, 23 Aug 2022 08:32:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661243554; bh=LKYTZ8t1r7PSDOsdZvV9qIXBrHrd4WElWZNqWkPgLvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Hy4h0ydBBsYpJOJh6NdZjJYUrdoA4vlFPIomvQo8AFtZXqV732F5zQWY5HBd+oMNH vKQN/1dSJL/1jp9wG9AKHqJ4e8Tegp69bW1FfM4EWhbQHtH0qUeGXsS1Q/bbgDlcvv nlsp8MK7pJx3Q3D7siEn9eiz/dGELZorXhx/C+AY= 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.19 314/365] drivers:md:fix a potential use-after-free bug Date: Tue, 23 Aug 2022 10:03:35 +0200 Message-Id: <20220823080131.317193450@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@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 45482cebacdb..1c1310d539f2 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -2881,10 +2881,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