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 5FFA1CA6B for ; Tue, 30 Dec 2025 04:18:36 +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=1767068316; cv=none; b=b2mCQy4arLTR25sUoRdH7cYYq3NrwbxYdN9RNLXP1Kna5/TSnEDaHcr7yQFDauku63kz1s7XfLxwaFqBP1cTUJ+uNoZXyKrDAO8dMmvyr2A7rqDX/jXtit17tW/XxUhzyTet4tfZgGH/fEwltyPK0q29tmc7Rf7R73l/VgWAXT4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767068316; c=relaxed/simple; bh=6uCCxoj8rZJVTzxBhnh/CGa97qrwyugjvKNQZgQ0mkg=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=FgEXTpqhXHXAkbUuZV0L1H+JhukW/X+JIqzh8frywHNSW2Ri3blelLKgFzM3zQaZ5Dqgw/CTxyOQG8W0HFnz+UO1Kq5OzrFqgyIYCf66mlIm0exqJnrUS87bVba6L8YzW95mjBCMMOskqCl4s1AH7/JEFW4UsIQ8iqQP0EBFGpc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oPswZhgz; 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="oPswZhgz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1C94C4CEFB; Tue, 30 Dec 2025 04:18:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767068315; bh=6uCCxoj8rZJVTzxBhnh/CGa97qrwyugjvKNQZgQ0mkg=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=oPswZhgzwrKILos6lUa0FGDyl77LptpLc1zfHKl17XtY2uiWXFc3FzR5jwCcOOrV9 KmVXfGCbHOya/8rWeeAcqC5wkJ/UhAazyDj9QzK2BR6k2YkqJjgIBwkc5j73Ev7HQG l/IXKgW91QTwUwBgRbUM5kVdbXzYOX00pEuGOpxlOrTTixJKh8Zxaq3/msoJgTb8pJ hurNVJHrJgVYRSWXilYtzxDHrxdcixeCZ12QQk58R9GpAKoI76Dkwx/gzIlzM7/9pF nmAXD0Ae+GtbuKRYO1z+mLO3z/HD7bra4aNpGcu4vFmZU/XWBoFkIPMyPkFbMzfEJ9 5nQQKodsExfpQ== Message-ID: <0a61c069-93e9-49b4-af8b-e592cb8cae81@kernel.org> Date: Tue, 30 Dec 2025 12:18:32 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, syzbot+b4444e3c972a7a124187@syzkaller.appspotmail.com Subject: Re: [PATCH v3] f2fs: fix use-after-free in f2fs_write_end_io To: Szymon Wilczek , jaegeuk@kernel.org References: <20251223162823.23606-1-swilczek.lx@gmail.com> <20251227024944.8612-1-swilczek.lx@gmail.com> Content-Language: en-US From: Chao Yu In-Reply-To: <20251227024944.8612-1-swilczek.lx@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/27/2025 10:49 AM, Szymon Wilczek wrote: > Syzbot reported a slab-use-after-free issue in f2fs_write_end_io(): > > BUG: KASAN: slab-use-after-free in f2fs_write_end_io+0x9b9/0xb60 > Read of size 4 at addr ffff88804357d170 by task kworker/u4:4/45 > > The race condition occurs between the filesystem unmount path > (kill_f2fs_super) and the asynchronous I/O completion handler > (f2fs_write_end_io). > > When unmounting, kill_f2fs_super() frees the sbi structure. However, if > there are pending CP_DATA writes, the f2fs_write_end_io() callback might > still be running in softirq context and attempt to access sbi->cp_wait, > causing a use-after-free. > > Fix this by calling synchronize_rcu() after f2fs_wait_on_all_pages() > but before kfree(sbi). Since bio completion callbacks run in softirq > context, which is an implicit RCU read-side critical section, > synchronize_rcu() ensures all in-flight callbacks have completed > before we free sbi. > > Reported-by: syzbot+b4444e3c972a7a124187@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=b4444e3c972a7a124187 > Signed-off-by: Szymon Wilczek > --- > v3: Simplified to minimal fix - only super.c change with synchronize_rcu(), > as pointed out by Chao Yu that data.c changes are not necessary since > synchronize_rcu() alone guarantees sbi won't be freed before callbacks > complete. > v2: Add synchronize_rcu() to wait for softirq bio callbacks to complete. > --- > fs/f2fs/super.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c > index c4c225e09dc4..924bc30d08b6 100644 > --- a/fs/f2fs/super.c > +++ b/fs/f2fs/super.c > @@ -5454,6 +5454,8 @@ static void kill_f2fs_super(struct super_block *sb) > kill_block_super(sb); > /* Release block devices last, after fscrypt_destroy_keyring(). */ > if (sbi) { > + f2fs_wait_on_all_pages(sbi, F2FS_WB_CP_DATA); f2fs_wait_on_all_pages() -> f2fs_submit_merged_write() will access sbi->write_io which should has been released in f2fs_put_super()? Thanks, > + synchronize_rcu(); > destroy_device_list(sbi); > kfree(sbi); > sb->s_fs_info = NULL;