Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp395435pxb; Wed, 3 Mar 2021 06:08:01 -0800 (PST) X-Google-Smtp-Source: ABdhPJyRbhac+haMAaoXNUBuGpwwrPDTYCC4Az2KXk94cr4hgzi93VrTMp3IIUaQQ2FBDfaCE39I X-Received: by 2002:a17:906:ae88:: with SMTP id md8mr25215024ejb.264.1614780481282; Wed, 03 Mar 2021 06:08:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614780481; cv=none; d=google.com; s=arc-20160816; b=Hz++zyawzQYw564P/jz5dKDRYlXTaP8nnKo8fM6J9yd734Ke7Y9u6WljOz+1yd3pvZ Ssj+/4yCaJLJpOc5cRUnb5Kk6jpHLUKyXQTFPAvDFSloEh9OmBrj0SgmrY/V+zeYmIYs G8DKY0CTgkzd+ZYzWg2V5CGsw1vEK59YleRoYCUH7Rts3Nw11YuAjBx06gukuttrZWcM qybjd2h0905HlrYyOb7KqPVJ7khq8H+GwPaysjFfhQ2MwQV/+lKl3Pe91m8DDnJ/eZEk JFdh/d/BM0h7C5lTlIV/DAPe7bedWrFkftYcId2aYlzKKKZZJv01KNvKtaT1UHSgKKrR C/5A== 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=qgW3jIDFo5H/dI7bQTgnbzGbTf/+AgH7U8lrNXDT5W2Cneuc5+t61KFFyBa0Xbu6/v c1Yyi1gCrtPfVpKmz/1QuOIxyrbKwSlkg/6PocRlmri5cW+PftMOyitg16Hfoms3lsfx oQ34uEaLVbvgf5SMjfSqZUBViNI4T0p073wOA+LFHmSwSVrU0PK8dVoCEFGiPD7c+2UQ z4eTsbUJmJboF0wLcOz9lk5dFZz6b5D9NyobhdfH+kIprsD//od1quuvM7w+cWjvN6pt iqbg67sRfCw1t6xfX6Pz6esZBWAVqLjP1RqXAgKy5E/0HkeIYWREA8KfzkUjl2uqv45M c1gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=m0TYM7Op; 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 lr3si15454052ejb.514.2021.03.03.06.07.01; Wed, 03 Mar 2021 06:08:01 -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=m0TYM7Op; 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 S243420AbhCAU2o (ORCPT + 99 others); Mon, 1 Mar 2021 15:28:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:35318 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237043AbhCARGm (ORCPT ); Mon, 1 Mar 2021 12:06:42 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 45C0065002; Mon, 1 Mar 2021 16:40:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614616815; bh=+nZLZ+8DU1bB546hofKiUfN1z70R/SeU+DeYtpUD6Us=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m0TYM7Opn+pnwOcylusISD2CerY750+bEPEQXn/AQqr/oBGEZIYgp9PyQoxw2w3Yj dcM5mIkcfiNMrfpTZeE+/nmjTaT0a2SjQpbLfexti+PhhWmlh01//MZ0lJ0LYQWiWO 0eaEzVWxPl0C57+utgf+xzCPGGBEirK+Q39mTWz8= 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 4.19 106/247] jffs2: fix use after free in jffs2_sum_write_data() Date: Mon, 1 Mar 2021 17:12:06 +0100 Message-Id: <20210301161036.861294995@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@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