Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3414420rwa; Tue, 23 Aug 2022 04:30:36 -0700 (PDT) X-Google-Smtp-Source: AA6agR6+zldeaOv9twva9e55CzDWa2PUoOLI0gor2msqi6si5b2Kq3XtoNInt7xCz5Wi2gb2bcJv X-Received: by 2002:a17:907:d8d:b0:73d:538a:cb87 with SMTP id go13-20020a1709070d8d00b0073d538acb87mr12479551ejc.368.1661254236589; Tue, 23 Aug 2022 04:30:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254236; cv=none; d=google.com; s=arc-20160816; b=nwAY6nChZ/FAfZEM5cNsGbVldApssGGA5o65B7ZemYxjgBY/Y/z+VlwEjy6uo7MOvU X/SF/XfDGzbgSrjO5y9gMtu/LPN9NbNCPVg+CUJZstU8n5GiPt42kX+T11vRtnI+RhIq BxsIg+DtB+Z6AVXkSSFl+6bgrcL/0XsqockGC9efkJ7rccZnRnac17i4CVEc/wKFSh7s IPlrwLYIePo0nJuYHicWeDj4hAr+mOdwMyKYwq9D6DilX+JUDPOv2zXZvI7YFS2q1WIr N5j7JshWoPxFc8vfrXt5FHweU5qLKaxJxWkGW9ahwJ00jVgRpngkmGFM6CJSIMl9E1wq M1/A== 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=zz0oE8TaB4ehzm7aq6GM8YMJa6mTu3+TkAxtnWY2rBE=; b=fXg12lJYRBkY4rkTLQnaZDNjFBcvJIqPb8aoJvAkaJo1Lyw3CuGXfmDwChIwmlpiX3 1kN1eYXS92cyXGnlag8IbnvC/c8QxFi2VYg8P41OPeLjciBLpKDVUrNtblwyLkq3eaxo pgqu3Tp66bpIV9EBhNjo96iHiOYqwK8y/u+VshEbnvNkGelTBFxMKz5tYJiytzyQjNTz wi4jyMVFW19m/4VvTTrNUpFxC8gRZuEAFSACxvRkrlWz7LRZrKnFG5AB9zfhH7Eioxon 27B6vFjTsF79XgewGCGzC+g1YWUgkvKPq7N8n4iCxIgB+WRY/aAdElP9Vg24i6lZTgXl muKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=yBMFzK0m; 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 m22-20020a509316000000b0043c77b9ca58si1909510eda.82.2022.08.23.04.30.11; Tue, 23 Aug 2022 04:30:36 -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=yBMFzK0m; 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 S240358AbiHWLEK (ORCPT + 99 others); Tue, 23 Aug 2022 07:04:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356576AbiHWK74 (ORCPT ); Tue, 23 Aug 2022 06:59:56 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B251786C09; Tue, 23 Aug 2022 02:14:03 -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 BCBC161226; Tue, 23 Aug 2022 09:13:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACF21C433D6; Tue, 23 Aug 2022 09:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661246035; bh=PpYQ9sWEw42NyUlX2lft+LxP0PilRZHReFOoNyV3Z/o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yBMFzK0mzGzmgmX72pQXGFs/3upNyk3QnZLTY4uhRMjtgWQvv66iMXVpS90vhXZ9I OgR+o0W+RAtfDuVlpSPgT1e2LWB/YOHMG+48Zj8J4qG9IST2/eLvEEZpP/Vce+aPCT G3ihooX7EMYIr0Dj6U0sojuujK9Ojdj44auOONKs= 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.19 267/287] drivers:md:fix a potential use-after-free bug Date: Tue, 23 Aug 2022 10:27:16 +0200 Message-Id: <20220823080110.340175238@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 dad426cc0f90..6f04473f0838 100644 --- a/drivers/md/raid5.c +++ b/drivers/md/raid5.c @@ -2670,10 +2670,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