Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3409695rwa; Tue, 23 Aug 2022 04:25:34 -0700 (PDT) X-Google-Smtp-Source: AA6agR413Fjn6yp0goYs5Htn+Q8TcgvbZOUQVu2BDarGCzEFwYESKTwC/47+BtdUwB++rum5ded5 X-Received: by 2002:a17:906:9bf3:b0:73d:8112:624b with SMTP id de51-20020a1709069bf300b0073d8112624bmr6419154ejc.155.1661253934207; Tue, 23 Aug 2022 04:25:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661253934; cv=none; d=google.com; s=arc-20160816; b=j3YI32wUBPeA2QdDPQdlEEplQfugkVHwyKyEr6v09qBXyhSOjJsU6kJHPaGV6oyyq+ 5PZSGlBIuRws7rsX+I1AipxYqVgMrPQBhEz4am2ep/KlUOMZkkFRVHxxGgdHwcDzSQf5 aV/2f/yLRJLnd+kndRvBFPoieqa9cadNfZrBGfKqhG52i9FRzGRMQAEmhERn5qa03u+n pfmQwdvKQjj4Z2xRKZeawIIHHLplBBIW/pzE/2Y5qh39z9vampPg61Dq01mIqMaTEXFI SpkrqVWLc214YtzbgCg7FG1FHlsZzTpqlzUk5IoeocdI9h9WR1DBbx6RF5cH/jpMVa4z nFig== 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=gSkc9FJa9ARKM1QJnjj4WZlOqIL/KUYjEUYOvMU/FCU=; b=KzLb5AK+3OubQF7lvXAF1pGa0+oCDaEOzEnGi0fBwhX/RiDMWMREsRfhxb1bLpulAG tiLK2oqeMOfOb0GzZvN1l9kYRKkMG++FG/6lLAaZBD5N0n5PXSDHqJLAinVpIfMaK+kq ttM9cMxOGmVZ4bhifdIF0gfmQGvRsdnNozl7BQUM0UG9KXJV2gIUb3byPs81Pr4lqtX5 9wIifaPdAhHURl6DS2k58ZkZQiOA0P4fZ92uBlUR8FjVUM0e8VC+IY/enoI7FuNqWAdO tmVcpiY9ltktAFxbYTZ0Vtn63dmmj68Hj1ey1BXWQQSyH47s6j98jXUaKPjXLnb0n6Nb CI0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t2ToNMwa; 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 qb34-20020a1709077ea200b0073d80c9dc85si4630589ejc.459.2022.08.23.04.25.07; Tue, 23 Aug 2022 04:25:34 -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=t2ToNMwa; 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 S1354825AbiHWKWS (ORCPT + 99 others); Tue, 23 Aug 2022 06:22:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352717AbiHWKJz (ORCPT ); Tue, 23 Aug 2022 06:09:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 076927E022; Tue, 23 Aug 2022 01:56:05 -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 ams.source.kernel.org (Postfix) with ESMTPS id 7D74AB81C28; Tue, 23 Aug 2022 08:56:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0F94C433D6; Tue, 23 Aug 2022 08:56:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244963; bh=9+9TAGae0fTA/X972osI2oujsoHgyW6Ylmjy3Vai+/w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t2ToNMwaudLlzle8Ttqe+SCy0YjY1gvdsO4HghECzGttD4lRoB93c7KNcFsi4Wzru 4lGtfCdNdbVxGyHtvI3w0dccKg1plvKDuaYhteCt9qdo4jFE+Ii7SMw05YhDYODmFz XgazA3jAu2x6Y5lb89qt7z3Go3QEcoKLMYLXcw9s= 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 4.14 218/229] drivers:md:fix a potential use-after-free bug Date: Tue, 23 Aug 2022 10:26:19 +0200 Message-Id: <20220823080101.432971186@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080053.202747790@linuxfoundation.org> References: <20220823080053.202747790@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 1e52443f3aca..866ba1743f9f 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -2668,10 +2668,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