From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A2FA3328FA for ; Mon, 23 Mar 2026 11:06:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774263992; cv=none; b=AXpyqAM5OCgd5aS5SJS5vcZEE9L60TK/b4j2etbofs2xOtEB8JzRg8xG+Myg4Pmma70lINfraeswSaUFYRF30dljJQCe22J1+ATWPM6Xj2dDiCqEg+EEKFpwNaLlbuAyH90Pyi5KjINkMojW8lnK524qHtapp5hrcY/qPgzurRU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774263992; c=relaxed/simple; bh=eZt29KyQXd3NrSDSkRLSRVVGIq5fT7OnarGlrAFYGrk=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=uIKqc5uUmvY+U3Si7RNB0oT63ReAI/EpJ42LbcpYZi26CTzs9XO//jxAIdLhdBmww2oT1mQhs5aFGXH+QY1I7kzbA0pCXo6m5+qEhbjJI8Ctub8PfuPLYILSZ0c7rpw3uWwWLox052esJ7WIhmFCWJO9yHcmNm5SNt9Q+v57kP0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=opD1lgWS; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="opD1lgWS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB977C4CEF7; Mon, 23 Mar 2026 11:06:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774263992; bh=eZt29KyQXd3NrSDSkRLSRVVGIq5fT7OnarGlrAFYGrk=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=opD1lgWSAnk2iyt7Wa7X+UVO5+t9ztJr23x5L4EMfopaIrTggB+WvfWdiwcetFnUi WWhsQbHF9LAMSfNFo4nuBuRIfiBzZNpboQf7qWuzjyXBvk9lngIagV587jDKgS73pe qZVYZ3vjANNAjl3YcWaX0Lx0ohnXyh0nzMpWQ5glyNWbtvlo54xDhnUJlwsndery1Y SArRf3sFwzFNtuBZuFTWsL+3iuqc82JMEfv/LtTxlMRSnG7zuryAruA07y7tatsTn6 I/c8ZjCV9qHTGDJLHJ+4YrS76qC1txmRZyDge2vmSU0MlVScifniW8/SihZLF+N8kt HEMg0OGxnl7xg== Message-ID: Date: Mon, 23 Mar 2026 19:06:25 +0800 Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, Jaegeuk Kim , stable@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Subject: Re: [f2fs-dev] [PATCH v3] f2fs: fix use-after-free of sbi in f2fs_compress_write_end_io() To: George Saad , Greg KH References: <2026032354-country-saddlebag-5331@gregkh> <20260323104425.780693-1-geoo115@gmail.com> Content-Language: en-US From: Chao Yu In-Reply-To: <20260323104425.780693-1-geoo115@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 3/23/26 18:44, George Saad wrote: > In f2fs_compress_write_end_io(), dec_page_count(sbi, type) at line 1492 > can bring the F2FS_WB_CP_DATA counter to zero, unblocking > f2fs_wait_on_all_pages() in f2fs_put_super() on a concurrent unmount > CPU. The unmount path then proceeds to call > f2fs_destroy_page_array_cache(sbi) and kfree(sbi). Meanwhile, the bio > completion callback is still executing: when it reaches > page_array_free(sbi, ...), it dereferences sbi->page_array_slab_size > and sbi->page_array_slab within the now-freed f2fs_sb_info structure. > > This is the same class of bug as CVE-2026-23234 (which fixed the > equivalent race in f2fs_write_end_io() in data.c), but in the > compressed writeback completion path that was not covered by that fix. > > Fix this by caching sbi->page_array_slab and sbi->page_array_slab_size > into local variables at function entry, before dec_page_count(). At > function entry, sbi is guaranteed valid because the F2FS_WB_CP_DATA > counter is still nonzero (this invocation has not yet decremented it), > preventing the unmount path from proceeding past > f2fs_wait_on_all_pages(). The cached values are then used in place of > the post-decrement sbi dereference. > > Fixes: 4c8ff7095bef ("f2fs: support data compression") > Cc: stable@vger.kernel.org > Signed-off-by: George Saad > --- > Changes in v3: > - Add Cc: stable@vger.kernel.org for backport to affected stable kernels > > Changes in v2: > - Fix Fixes: tag commit hash (4c8ff7095bef, verified in Linus's tree) > > fs/f2fs/compress.c | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/fs/f2fs/compress.c b/fs/f2fs/compress.c > index 7b68bf229..c3d837df3 100644 > --- a/fs/f2fs/compress.c > +++ b/fs/f2fs/compress.c > @@ -1479,11 +1479,20 @@ void f2fs_compress_write_end_io(struct bio *bio, struct folio *folio) > { > struct page *page = &folio->page; > struct f2fs_sb_info *sbi = bio->bi_private; > + struct kmem_cache *pa_slab = sbi->page_array_slab; > + unsigned int pa_slab_size = sbi->page_array_slab_size; > struct compress_io_ctx *cic = folio->private; > enum count_type type = WB_DATA_TYPE(folio, > f2fs_is_compressed_page(folio)); > int i; > > + /* > + * Cache sbi fields before dec_page_count(), which may unblock > + * f2fs_wait_on_all_pages() in the unmount path, allowing > + * f2fs_put_super() to free sbi. At this point sbi is still > + * valid because the F2FS_WB_CP_DATA counter is nonzero. > + */ > + > if (unlikely(bio->bi_status != BLK_STS_OK)) > mapping_set_error(cic->inode->i_mapping, -EIO); > > @@ -1500,7 +1509,10 @@ void f2fs_compress_write_end_io(struct bio *bio, struct folio *folio) > end_page_writeback(cic->rpages[i]); > } > > - page_array_free(sbi, cic->rpages, cic->nr_rpages); > + if (likely(sizeof(struct page *) * cic->nr_rpages <= pa_slab_size)) > + kmem_cache_free(pa_slab, cic->rpages); After sbi is freed, sbi->page_array_slab should be destroyed as well, so pa_slab points to a freed memory, right? Thanks, > + else > + kfree(cic->rpages); > kmem_cache_free(cic_entry_slab, cic); > } >