From nobody Sun Feb 8 18:33:01 2026 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 98E49230BDB for ; Tue, 30 Dec 2025 14:09:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767103750; cv=none; b=KHTTjyMdh418Jsn0DduVcOVD0y+QSezGC7goxNQi3V/n1B9BDef1iKjmaMjdNNOZAmVvcTP2y/rAMUC3Be77nz3fgoqBIb4BtIP7ReHTa6p0vqtvSN1MDU9LvWaRX1/uCchhM38AnaTCJ8xspTTW1Op2mfDFfXFwFGh6hCWgKcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767103750; c=relaxed/simple; bh=v205qwm/tQGbcaWBaFodysH/VxhP2Jz8rSazI8Z2QDM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QX7ggiS35/2v021+XzF/whX+d4jjat9twG/TfQJE8ApwwYbN1pb8FTKabk2z9oAWBMRkB3kcJA15GxyU4oq6ZG0+Z4SbdW+eT47GNBc2RuZglNHcpDHfy4gmTERXyheDJLk1TJdqWumj3gyogiWK7oYst7KqCU1fWW1vCgSiptA= 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=SXwaY0Pc; arc=none smtp.client-ip=209.85.208.47 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="SXwaY0Pc" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-64bea6c5819so11678431a12.3 for ; Tue, 30 Dec 2025 06:09:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767103746; x=1767708546; 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=xNYXqFxT5QJQe5v6ruCzAN0+zABHEc4TZ+XdBbAtf84=; b=SXwaY0PcCLPlbSWX2+oxpS+sMZx3pKgTG6C4qGp/VC8m6BhQuxd7wff3Z00ImsT4UX sEuOKSHMFhmSrzuO+D2gLa3ci5c4F4zG/koWIo1t3iSrFfjgdyAs85AF4vw5Hh7EpCnv QwXEoexcPYo+zoiny2/0qhCLDJ3yokJZYBMQJbUzCdSshvXiT7ah5SlLxBkbVDs5HbFg erwZYyV9AYOT8zT8TSG1OpzxXaSOTm+7oFQJRU62Hn8Hk3RwhtPkcKWU7gdGbvJedzD1 vNDspbZrBUzYY2xLi1FjXI0l/GKAB8kI4M6yqAS+Cw6ut28tl5X2gby1x9Dnv+CNejr9 e5zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767103746; x=1767708546; 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=xNYXqFxT5QJQe5v6ruCzAN0+zABHEc4TZ+XdBbAtf84=; b=uQfeJrMNEBOHae45ZYGI3d5akcEvAxyhkyKJzd7DUhi8+VuZayZhFYpAPfrbTMAU4s ARS4+EgN/geP9q8KpgwlKfhNjJ758KiMOdKPxbP6wR+Y7yob6/PMODA8GVP/3JR4dgbV WddGgwxdP+AHPBJZHgkC+aUi6whh0I0bTXzGxctxNjRlx9kn7GFBImwfK6gx8LoR4IXr FVezp8ve9yfTUZWrV8NXzRIHGMZroXApyhVe10U4ygFWTWbEQkcxhvdBPRx8MvquoRMb QaodDsF0JCgljJn/2xm/7nvg1Q7J8eh6iMXSeh8mrNeuufYx33vZEmd7NndNH5AJZYk0 AYug== X-Forwarded-Encrypted: i=1; AJvYcCVJdcyuyD3K+pLNeBZ58HRLzmTvWZmkz7hEXnuvG+dDGqDZpEsFgBjhwyr29grgNQRyetXxJ6WXS1zGFAA=@vger.kernel.org X-Gm-Message-State: AOJu0YzKB4JM61ZCr3P55yZgTaED+uPRlqFXD0Wv++9N6YdB8G9sXUQQ /ZJIf85Ewu5uAiOyJBjUT1j+6T/EVwyHrXKsa8/49FMJCrBHtBUROqCb X-Gm-Gg: AY/fxX4Y5csYVN10rKMwi2thpton5lB7tMesmJPexcBBEwpukL9sps+w27SWI6elLAb 8TuthR4JmvAz5mZPC1ZilGC7FPQWFnFbcr7Pna4XmRSeKRFM49qn5Umhit906rP+IAWLcfyxB5/ j72F/QdPeN63YXZN8GTJI5NvomvSvAcQhP83PHbK2ZIx6+uhLq5nQ+WJRMqScQGnqBXsnrtDY5Z 0xBTIcarGylQjD6zS7K1iuQD3SHUZZ8RXInil1vnhsvMtV+5MjRq8Zt98BIS6n8DfPSbsgldv1c mFhu/ACG8/NWoqmx9QCJkC3ltCH3mG9SVO5rlbdJKHh4zVzPNK0yXQpBCQfb8K7efUpA3N+IuLg DaVn+Exp2aib7CM9fTTRVMQL+ibRQWgRMCFoH9ACNGCedSLElcc+CyFNsh4DqLWXWphwNNQXzMz x12Hb0bGgJZg+4ug== X-Google-Smtp-Source: AGHT+IEv1sil+gJKqAYQb3RZRsvLaoSinwwr92vDk32fjRdDN9cY/VRKcyT8FxU0jpny//SQWr0V4g== X-Received: by 2002:a05:6402:1ec9:b0:64b:3225:b771 with SMTP id 4fb4d7f45d1cf-64b8e82b70bmr34168484a12.6.1767103745722; Tue, 30 Dec 2025 06:09:05 -0800 (PST) Received: from prometheus ([85.11.110.37]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-64b91494c0esm34776522a12.20.2025.12.30.06.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Dec 2025 06:09:05 -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 v5] f2fs: fix use-after-free in f2fs_write_end_io Date: Tue, 30 Dec 2025 15:08:50 +0100 Message-ID: <20251230140850.70778-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 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 --- v5: Resend as reply to original thread (v4 was mistakenly sent to a new thr= ead). 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