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 A2ADE1F63CD for ; Wed, 7 Jan 2026 07:06:51 +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=1767769611; cv=none; b=V47NEhw2xKX4lXJUsQvStWLRgLPyYi+1WuALUalmO+kP180OQ5p71WpCDs1ZepXwkjdrNW8Rk8x4nWcVq6SyCya1nmXd382gTph/pbE+S3gIDIAB/2eNhvDuF6KcZaXxIlv67dnwe9gN2EikdrXyAoFgI+1nu2XKbtyi8PJnwqI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767769611; c=relaxed/simple; bh=DnwTHxnIFNf2z/PGo16b17zIVjyMAlukpNjHRfi1YdM=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=TR7JO9wpPCrZ56W7iSob0CsgJb8tuHDP6Sf8geDhfOURJLHYRY5bRw6N+zOgiWT/Krx+vwXcEADZL5hhIa9nrX/ZQqPPbf04AkT/RgOep1lH4JhzTVDT7GYvb6OFG4HO+dLn5FyeZp67NwbwseIyErAmMlzHQpUCmhTJeV0R8QM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=owDuFknj; 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="owDuFknj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F375DC4CEF7; Wed, 7 Jan 2026 07:06:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1767769611; bh=DnwTHxnIFNf2z/PGo16b17zIVjyMAlukpNjHRfi1YdM=; h=Date:Cc:Subject:To:References:From:In-Reply-To:From; b=owDuFknjERfV4+Q1uE6k1i51sSFwUu7cGyuZuxvoqCuukmPC5j07ATkYOoXxNUFLV aLn7ixjfpQ+rpbpiQufWdU2UYRr/PWiVE3zMIyQZueCp13DMWWw6wa6aB1N1rDo4WL rGVVdFMxCltFkGbsNY0JxrZ12TIoTpZ0jRzpuLAKqmm5Jxbb/nFwwKdNEu4et+IA2r AT/O1dC0jmLDEEGRqbJvQHosm6p0OzDjFTGsi6R8XZu7Y83/dGBUyE97d606VWX1oM PDFFcHcOUwtH2pABboZ73cElPK0f6XrMp9AkaKGhrO5PNBOlEiKZLDGkVS3XUSHGKl uGf/LD9zYpIDQ== Message-ID: Date: Wed, 7 Jan 2026 15:06:57 +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 v6] f2fs: fix use-after-free in f2fs_write_end_io To: Szymon Wilczek , Jaegeuk Kim References: <20251223162823.23606-1-swilczek.lx@gmail.com> <20260106130646.15092-1-swilczek.lx@gmail.com> Content-Language: en-US From: Chao Yu In-Reply-To: <20260106130646.15092-1-swilczek.lx@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 1/6/2026 9:06 PM, 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 the bio completion callback f2fs_write_end_io() is still running > in softirq context, it may access sbi->cp_wait after sbi has been > freed, causing a use-after-free. > > Fix this by calling synchronize_rcu() 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 As I checked w/ reproduer in syzbot, the patch doesn't fix the UAF issue. https://lore.kernel.org/lkml/695e0473.050a0220.1c677c.0356.GAE@google.com Thanks, > Signed-off-by: Szymon Wilczek > --- > v6: Add comment to explain synchronize_rcu() call. > Resend as reply to original thread. > v5: Resend as reply to original thread (v4 was mistakenly sent to a new thread). > v4: Removed f2fs_wait_on_all_pages() call as pointed out by Chao Yu that > it accesses sbi->write_io which has already been freed in f2fs_put_super(). > 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..f5707591ba25 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) { > + /* wait for f2fs_write_end_io() to finish */ > + synchronize_rcu(); > destroy_device_list(sbi); > kfree(sbi); > sb->s_fs_info = NULL;