From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 432DDEC01CC for ; Mon, 23 Mar 2026 11:06:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type:Cc: Reply-To:From:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:Subject:In-Reply-To:References:To:MIME-Version:Date: Message-ID:Sender:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qTR4AUv33p0dDRpIawdgavx6HgfjAfckuHDwrwlvABE=; b=IAhz1LpDhqj68RRpfeWlK+gPqH BwXw/woLSRN+qYxdHWuxzt/K/mvd45nfMzszEPw5Z5S8+e6BjQ3nmIuBpjxBdBeukMlLz1auB5Wla 79LMrC0kI+lxLNhsid4MNJZZZIPFBEEvTSALqPyAjCXfbFY82LOXdCWxslUbbtV3HNJI=; Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1w4d7I-0000oh-7R; Mon, 23 Mar 2026 11:06:40 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1w4d7G-0000oZ-WC for linux-f2fs-devel@lists.sourceforge.net; Mon, 23 Mar 2026 11:06:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: From:References:To:Subject:Cc:MIME-Version:Date:Message-ID:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=BJBaTZf/06TRXxXaST7RBzJ222B4Xp9nomsF7IDpA5s=; b=i9wx3hCWCn21VesRF4xXobxXv0 iA1Bzptgt2cIRKZIvPGr93oBkShiTmotz/ay6B5Y1g2PoI63ri32NxXCgaWaR4B5nEChMIRbhFB3z jaKHYl8EC49oRJ/BOhp0V9LFCJC3V6J6xJCnBcn1iQi/lWA/+rtjzDddiIR2ImXqg3uM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:To: Subject:Cc:MIME-Version:Date:Message-ID:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=BJBaTZf/06TRXxXaST7RBzJ222B4Xp9nomsF7IDpA5s=; b=gClvipwYrBymEyruxkgDE8q7sm aXnLo0R6AyWvlp4wazRSdowBlz7DiMAAeoG4230dH+rq//dDr+uRXs7hKW+gGC2ngcR+06oZjzbP+ s4N4BKyhMOHZBklRcgknX/1YsNMNn9sZz1cobzFb+TeazzgpVnKVTeUohJdJQpPY1Gs0=; Received: from tor.source.kernel.org ([172.105.4.254]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1w4d7G-0007pI-5r for linux-f2fs-devel@lists.sourceforge.net; Mon, 23 Mar 2026 11:06:38 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 87B62600AC; Mon, 23 Mar 2026 11:06:32 +0000 (UTC) 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 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: George Saad , Greg KH References: <2026032354-country-saddlebag-5331@gregkh> <20260323104425.780693-1-geoo115@gmail.com> Content-Language: en-US In-Reply-To: <20260323104425.780693-1-geoo115@gmail.com> X-Headers-End: 1w4d7G-0007pI-5r Subject: Re: [f2fs-dev] [PATCH v3] f2fs: fix use-after-free of sbi in f2fs_compress_write_end_io() X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Chao Yu via Linux-f2fs-devel Reply-To: Chao Yu Cc: Jaegeuk Kim , stable@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 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); > } > _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel