From nobody Sat Feb 7 09:46:37 2026 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DDDF3A1E7E for ; Tue, 30 Dec 2025 14:02:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767103375; cv=none; b=bIpsyd7qj04nbf42GF1A+7bA9QTImD5CLUS41BTCAe3pRe+LETRkZLpus11X6fWPxpFNxB3EcdcdTCTmlSqKNoQTqOxjNwvVGxtyGsF8kaXZgQWThGtKol0sEs/AFWXGYYXqBVd37LXyTrUb4YCBDg3P9Zq5w9fJYVtwmCFATWk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767103375; c=relaxed/simple; bh=zOgJvVhV+08/7oRyUniI4CrreYVwXmPx938Sv+oZ+HU=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=MStFNW0ISrtul0f8DNNrspqOGxE+dlHZc1wY2P4ubUz2vKOCYGOmrXj8kfYO3fGTE/o6xVyKKuSyDIob/KTC/xv1+p4JJ3oO5/iKwaKKRDviI2Ft2nExaIZTNX61BS9G8qGh/DFAOV4rfm5xNeTDoaa1E7BsJzKRCkWh15f57fg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m2MV8LU7; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m2MV8LU7" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-64b4f730a02so16631323a12.0 for ; Tue, 30 Dec 2025 06:02:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767103372; x=1767708172; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xjvvj0Zp85j/nukQaHBLs/CSvYPHaBwiCii1GR1u7Rc=; b=m2MV8LU7FIn084DpnNHd39FdPKUm069/cd+BNPLyUZtTxBA2pDKObFFHwyKnCaoEDl 2qvv58CJMKp1qQ7c6WSzJTUqpTPAuIS+9wj2/E9kryLB056Tqhs6Kvcnr1hYeNRbyog7 cSZTAMI/vO4wxYycPx71JpRvX7bPrXh7by+TYcKG5KKx1zL7qMDxt5mYOecUL87bFNTL qqHJwkR/1BjbSYnFSKm8/zsi0Wyk70PUbvJeryRwJu9g+9JkESpzhIPjGwlPuNDAk1Ok yc+au2A4BsMBqKx43sXRE/5WH1Onn4H2Ek0xxI8cdjlhtFydmM23nJhWGOMpjwdeuu+e H30g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767103372; x=1767708172; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=xjvvj0Zp85j/nukQaHBLs/CSvYPHaBwiCii1GR1u7Rc=; b=BpPISBBxRzCVYn1WY0lt9l5sDP1Ot5pjtqh+9RleagKp7Lg32wmD7Eluu2FmRxyAfy hmgbXxinYcwiIDIXlahJ6nRydLyag1qPammx0KCoa55VW96ahbRNdSavIoqoRU7fnLi0 L3QnKweijTcsP+OSF4SBVXxo9AHXxjvPMEISqBuRq7ARYGHV+LplJR++2OTQScWhC07B TLG3mwW3toaSErxQIBLCNUAcC/psRa2w9ej29MHOP7rNsK5IRspWJvOaMlef9wUgbi8c bFt7LqAQ9L7GH0bW69/IOEePiEKAhTu7L8JH5Fn3u7Cne21vWHPoZoTQINLvLsODg+O2 iAwg== X-Forwarded-Encrypted: i=1; AJvYcCVTdbGaxYHiUB5M/t1wkTFER1+/Q2Sh4tubQqxCvGrmKPshrL9DHRBnMVYbknjmmT3QvK2JAeOo/rspff4=@vger.kernel.org X-Gm-Message-State: AOJu0YwmZebrj5RiL8DPVbRtTSFv77GPYuxKTFqcn+5epPFc86EYybJo VCjAUN4kLXSB0nU0Ap2onqjablES+M5hxSGOModK1KDYTI3/XE4YpfN5 X-Gm-Gg: AY/fxX6YQl+TsOj8pqUTxHYZsN/cZoHeRWmsNwPtSVSPyHxHCsORzPj5Vpd4IDQKzjN y4fP3KxcPOt7LNoRdMQ7QZQB9FCBkV6Tkz0V/EP5ZCsM64Jb5wchW99t5zBUgEc3QnNy18RrTGr APXdfKKekENKgeCkjQIYsWAT3KQqpynv+N64g8p0+q1jZbCT7zqD8gcHcwl+jdWE9yqapyv8j/M YS+Wt8LhsCQqaRqEkOpiHEmkYYqYoYiiv0KpUIQIy2vi3ZSLH0DXq74pTsKEOQr/Ra8s9tXOIQc th/QkK1GQ/sDMhv/EYH4XgI6wtX/n09wjhxa2sSEZv8hBGhlXsM9Db71PC4XVt03qrK3tkbVvY4 yuVnge4dZ5NAwrwLhAiG2I4CYo6/1YUsQ/iC5+EmLgFasogWZxkr822+XX2tMHdPNAballqwGRD 4G3SraPR5I6pLoGQ== X-Google-Smtp-Source: AGHT+IFi5P/pn2AAVbkj5zoscY/l1HzUz7YnghG1nuIjHfS+KuthtLkcD+u3Lf3LyTmn3ZFVGyXtsQ== X-Received: by 2002:a05:6402:1474:b0:64b:588b:4375 with SMTP id 4fb4d7f45d1cf-64b8eb62574mr32408947a12.2.1767103371599; Tue, 30 Dec 2025 06:02:51 -0800 (PST) Received: from prometheus ([85.11.110.37]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b9ef904bcsm34374444a12.22.2025.12.30.06.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Dec 2025 06:02:51 -0800 (PST) From: Szymon Wilczek To: Jaegeuk Kim , Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, syzbot+b4444e3c972a7a124187@syzkaller.appspotmail.com, Szymon Wilczek Subject: [PATCH v4] f2fs: fix use-after-free in f2fs_write_end_io Date: Tue, 30 Dec 2025 15:02:41 +0100 Message-ID: <20251230140241.65820-1-swilczek.lx@gmail.com> X-Mailer: git-send-email 2.52.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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\=3Db4444e3c972a7a124187 Signed-off-by: Szymon Wilczek --- 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_supe= r(). 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index c4c225e09dc4..dfa3c76c6f2a 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -5454,6 +5454,7 @@ static void kill_f2fs_super(struct super_block *sb) kill_block_super(sb); /* Release block devices last, after fscrypt_destroy_keyring(). */ if (sbi) { + synchronize_rcu(); destroy_device_list(sbi); kfree(sbi); sb->s_fs_info =3D NULL; --=20 2.52.0