From nobody Sun Feb 8 07:22:04 2026 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 3A4EE2F872 for ; Sat, 27 Dec 2025 02:49:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766803794; cv=none; b=abPRhYZU/hbtG8H7+P6qpS+3ACQTQrPidAKOmjLZ3655Uhg3kVZx4ouoRm2KPoNzaZxbzFXPnDmQCyzlChGzT2+a5xQ1SqVXmyLWR4jYOKxCOQszFANHeKCV69stloLU2GLWCS9dGEpAxT4lfp8cgcVORhVD/LT1f8BoOxjmQss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766803794; c=relaxed/simple; bh=ZkXCncpo+pJDYX+4cmpC510gzWTOEI8x9/2XUmpoWMI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NGMy5Ai5T8CYy+7B3EPXNEioIQnLuVSdzpUGVpr3mSUE3IKGoWgTAe+P95fRI0/emRMIRDF8j7HrUSfLav7ra5KTt0W69gCo70QTXSFS4YbSkFGIni/jjY2wlNmAGVpbzzhE3b+441Ssf/nkgMFyCuRa9sSh69wr2G0dFmgu/dk= 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=jzPm69cW; arc=none smtp.client-ip=209.85.218.42 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="jzPm69cW" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-b73161849e1so1479378666b.2 for ; Fri, 26 Dec 2025 18:49:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766803791; x=1767408591; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C8FvaxPfkdTbzDfTdRg9piurLhOQti4nRuT6u8LkRaE=; b=jzPm69cWkDc+FbsbXo5ue3K2D0UY0kMEqVc1q91NRvSAsJZnQuM9sdk5p6W0ozdUJY GTP5Zp0D1GE2qAwvtkhbOxTZ3rOOiTI5SJVk6UMZnoDPryXMGdKdvKPRXvhAcbpHf2jK VUQyHypFOogz8CxLf5+Ccn5HS2y+4ZeejmqIA/1HWCiykg8DsVVW9JbHBu/M/qrh6g34 6saVMfSHA5IG+YVmhQPUte6MwZPchDLAGABMoxTXNAqjfRtF6ymcBvfXAd3q4HaIPUnE H4EKAzfKdkl9OMyo39fU2Gycv6JZSR8gz/2xYxkHWnWptJ99xPvIz8G9Tg5KTM/idSF4 h4uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766803791; x=1767408591; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=C8FvaxPfkdTbzDfTdRg9piurLhOQti4nRuT6u8LkRaE=; b=MZCjeoAaOa/YvT3gBj+5C7Hi8xU/Hb5ycgIF+DIy4ebeAjb8Pd1DlExrK8KZChIqSt GcRcSgomGNevhNlxPOUWb+xJZ7WQECwyJX+W5VwP3g13N+Q8yYHu6Wgi6/dKxKOBKKxb utfm7v5/jS+CPhX0tqSX0O1hActBk3MJjVSYLBj6O2Q2C76kYKDI+YlK/TJQtLtXkug8 ODMipBRUGX/1Onho/NLdqRJ1a7Ez1W2vXVb2m8b7Yotl0yjKNkz6AUNaN7fZJdU3pn/z Geka7wBEAZSK65fIARvOYwwrbSrJdkeAVAEtQLAPQ0BeYhtr/duzNMHgv1thI3aKmFXv XCQw== X-Forwarded-Encrypted: i=1; AJvYcCUw0X5r5u94vxRtFE9s/p6ggYLDDDuUK+4KPCr8tg2Yst11hwTazgf/N1uqOsMkGpT9Dxyu+XW5AimQoV0=@vger.kernel.org X-Gm-Message-State: AOJu0YyaytsGY8GbQMGc1DDlKqXN3s0WPYr4wqUGEWy3nbJTZzS5aRpw CitVhxEib1XTFeOTwxQlJs8wN+t29YJn6JhbUH1pAMg1b5Ad0xfA7tPJ X-Gm-Gg: AY/fxX51gNOopuG0B3xr+A8v9nj/rBlyLk/vVEt230ZXfP/tXNzx97V48BeeBl/rd/c MDnYjVztSHFfAUdzzGfi2eJQwJUeAPgw/W1Qi88CNMPkrE9r0SjKc+vtTn3OBp7yKUcnTdOuvq6 eKuxGpEla4iU559kn2B8WMNiTUmQhEoK2ieGbKkgxnL54NTspFgY5lkIvceqiLi6yc3TubXqcuF S/wNzI+0wloP132MPqZ0UHafUzCVVfF2ns4UzAUnZqlyQMSl2CGhnjJO1r/70D8egtd4gQGfbNv jqU5yLjKJdcpHrSfPsTeNf8FHgJq4dGXZDfNlOjhmnoyr9+ujbiB0d1L2+L1NBCCIkPXuVotXhZ LhC+/iG2MA2lEX8kjhr7znL0A3s1cS8iYrdD7QLAjvVo8+Ou62VZi2rIUwQq9LfFcG8N2l0XMao 4w17htnB5qw2DiYQ== X-Google-Smtp-Source: AGHT+IHnRlEIWh4A48IFGDdJ3VKRi3+KxNdacL2i/9LpMwsvHQe70ec1dSmW1Nw/BRJunQ/58888kA== X-Received: by 2002:a17:907:75c3:b0:b80:3fb7:f3a8 with SMTP id a640c23a62f3a-b803fb7f6f6mr1762351966b.63.1766803791391; Fri, 26 Dec 2025 18:49:51 -0800 (PST) Received: from prometheus ([85.11.110.37]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b90f5400bsm24497533a12.4.2025.12.26.18.49.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Dec 2025 18:49:51 -0800 (PST) From: Szymon Wilczek To: jaegeuk@kernel.org, chao@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, syzbot+b4444e3c972a7a124187@syzkaller.appspotmail.com, Szymon Wilczek Subject: [PATCH v3] f2fs: fix use-after-free in f2fs_write_end_io Date: Sat, 27 Dec 2025 03:49:44 +0100 Message-ID: <20251227024944.8612-1-swilczek.lx@gmail.com> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251223162823.23606-1-swilczek.lx@gmail.com> References: <20251223162823.23606-1-swilczek.lx@gmail.com> 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 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=3Db4444e3c972a7a124187 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); + synchronize_rcu(); destroy_device_list(sbi); kfree(sbi); sb->s_fs_info =3D NULL; --=20 2.52.0