Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3932110pxb; Tue, 2 Mar 2021 02:12:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJyXvzDIgMsX6YdBKOGBmiXZOfAoGy2TFGrRV6u5XYaEozcgVQMEODuTdiGBhF431aEmVMIB X-Received: by 2002:a05:6402:8c2:: with SMTP id d2mr19052194edz.4.1614679940348; Tue, 02 Mar 2021 02:12:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614679940; cv=none; d=google.com; s=arc-20160816; b=U2ee0dbAjCkZ3nKmKsnXdMKJbD3+btHW89yhcO22Ra7y832j4Wa6OYkW34TpHM/tHS ACKaEAMZZZnoDKBMhODt7WU/8Qh3YkEABuSQRKLXbH61UY3TSwauUMoGfB11GvNruH3y cnMN48qU58sGcxhAEqg85IKrj3Zybo4ISwwhmYgfcqzdL1OWnsR8IGWBRzKh3OGtQgmH CVNJYvUSntrg5RG6QOfb3/PWI7TL+FU830D/GbCXd4+7753aPDMHj5H5laMLp8GdVIQp ymn2e994jFkQ/16qIUR3St+vsiNTZSdWgYzeO3aZrWD9qPoboDFPiuvF39lP5UnEi9z8 IqTQ== 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=QO1NuwZozuya/3uhP8E3FAriPMAvWC/CgfHD6wyt1Os=; b=MAFSlfrMgd03Wc+xNmXPkkyNDhL+rEHM+2qkuGLFRuWUssNtXH5oFJBAczmv23s5LU wpFRvhm2kADj6Y3vx6o9zAQnXJ7YRkVqlzRQWldPbSxvsriPmNqdKTJVE1dMomejMBDK Ptr6RqY/lXMsyN/lU2xA3AcJchzielFct/u/RdJ3ozKF6jZMOmaaYW1CLGFNlcsJtwvw wKk+y81p9ZsZVuzdhM0uj9/6jD+6wsGGtv2Q3jMuFIC+5vlwji4pXU/9hKYAJ/IMzvH8 wTpgXSPFv5vY2S9DQGq80gqj0IVdduby0k4q0Cs17PG62DqmUf9urYPdl8wJiswf8qB5 ve9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EwUmbxsA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e6si14203876edz.98.2021.03.02.02.11.57; Tue, 02 Mar 2021 02:12:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EwUmbxsA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1379433AbhCBB2e (ORCPT + 99 others); Mon, 1 Mar 2021 20:28:34 -0500 Received: from mail.kernel.org ([198.145.29.99]:43774 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241186AbhCATPS (ORCPT ); Mon, 1 Mar 2021 14:15:18 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id B468A65027; Mon, 1 Mar 2021 17:14:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614618878; bh=+nZLZ+8DU1bB546hofKiUfN1z70R/SeU+DeYtpUD6Us=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EwUmbxsAq7oJzvtZ2XSCPM40bCbjPXjOgu/Rk1455s+9YSmGxFttl/5xDPZlWtPuf lEXeOIKMCvBIPfBea2HHBxpLu44/F6ve7GG6RJv1C8gwOH0mBYl4z5CwscMc1dAGMj 5YUtHJ1ubnB73nT7oqwdsUf40WEB8uE0+hO4WJ3M= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tom Rix , Nathan Chancellor , Richard Weinberger , Sasha Levin Subject: [PATCH 5.10 250/663] jffs2: fix use after free in jffs2_sum_write_data() Date: Mon, 1 Mar 2021 17:08:18 +0100 Message-Id: <20210301161154.192983205@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161141.760350206@linuxfoundation.org> References: <20210301161141.760350206@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tom Rix [ Upstream commit 19646447ad3a680d2ab08c097585b7d96a66126b ] clang static analysis reports this problem fs/jffs2/summary.c:794:31: warning: Use of memory after it is freed c->summary->sum_list_head = temp->u.next; ^~~~~~~~~~~~ In jffs2_sum_write_data(), in a loop summary data is handles a node at a time. When it has written out the node it is removed the summary list, and the node is deleted. In the corner case when a JFFS2_FEATURE_RWCOMPAT_COPY is seen, a call is made to jffs2_sum_disable_collecting(). jffs2_sum_disable_collecting() deletes the whole list which conflicts with the loop's deleting the list by parts. To preserve the old behavior of stopping the write midway, bail out of the loop after disabling summary collection. Fixes: 6171586a7ae5 ("[JFFS2] Correct handling of JFFS2_FEATURE_RWCOMPAT_COPY nodes.") Signed-off-by: Tom Rix Reviewed-by: Nathan Chancellor Signed-off-by: Richard Weinberger Signed-off-by: Sasha Levin --- fs/jffs2/summary.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/jffs2/summary.c b/fs/jffs2/summary.c index be7c8a6a57480..4fe64519870f1 100644 --- a/fs/jffs2/summary.c +++ b/fs/jffs2/summary.c @@ -783,6 +783,8 @@ static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock dbg_summary("Writing unknown RWCOMPAT_COPY node type %x\n", je16_to_cpu(temp->u.nodetype)); jffs2_sum_disable_collecting(c->summary); + /* The above call removes the list, nothing more to do */ + goto bail_rwcompat; } else { BUG(); /* unknown node in summary information */ } @@ -794,6 +796,7 @@ static int jffs2_sum_write_data(struct jffs2_sb_info *c, struct jffs2_eraseblock c->summary->sum_num--; } + bail_rwcompat: jffs2_sum_reset_collected(c->summary); -- 2.27.0