From nobody Sat Feb 7 09:30:28 2026 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 3CCD532ED30 for ; Tue, 6 Jan 2026 13:06:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767704820; cv=none; b=D7iKdye+3cbhkWy95atjC3/8pQUVeUKEILMi40s1G/hRD4UE/4riqTsDj6xxkBglzpHSb3m+15U7t0DkLzZ4+XHVACbRzeAGV2Xt7vYO0JxG3rp8iY2dau3WkvDuVAAZQFwnRDPnvsM8A2Q0Bbl7cnQSH0LY6IfMCNO4flu4yzI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767704820; c=relaxed/simple; bh=TlK1p1aCnkyPVf1EckGZ6dK6NnMs/BvI1FR9KXOkaac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bK7iEEEkH2IHCZ6+cBgnWNbiMhk+m2YShV+vUHkdn06mGvCGmVnoeBmx5J3AHoAPHLgbWh2SGPvVVWLFOslKesc39ZWy6eOauO7qSIr+MJ0UPJVSHzMj0gjd4ryYDoUZwAfE0tq0K9J/QabFx2MXYJKGXBk75pCvPIwrp8CAutQ= 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=MpGsCybc; arc=none smtp.client-ip=209.85.208.52 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="MpGsCybc" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-6505cbe47d8so1518899a12.1 for ; Tue, 06 Jan 2026 05:06:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767704816; x=1768309616; 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=u7eP+ymytmppamfCOkg0zlf3bt2ZyhgktLAKP4vbwPw=; b=MpGsCybc47YW4qtzXIx+NaqGHPD+T0gJWjuct10RONjlmxZRbYqDVmYwsIMVQGtwtn F2uf+6HTGwKDY7HmJk5Iies2Hb4Sby4F7bDLUdI1K9QYE1rb0qdrAx+aZO16R1RRi4xg ZGXpPxWM16NevHnRldUwP0Io+lnx+KVOPn5jU0TQUeRsAQ0a9uJLOjkpnGx3oaVUNkm0 xUExZJSeBZOSMpQ66Bm3GjcvGdDQTVs6sAdLmddST3SHWFfno4QDblPMSSGm0OB/x1n4 wne1ptrZnPZalYQFC+QrKuZ03fSzD8kJusSMkf+zMgLir7BZvkDCshAekqm5OacBXOn9 hF/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767704816; x=1768309616; 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=u7eP+ymytmppamfCOkg0zlf3bt2ZyhgktLAKP4vbwPw=; b=dW1SqYzy9WTmUuNV+RluPoRONm7gnmlK2HoZRSJzvw6dgoqKZ/lr83O1ZDSxFEeo5x uJOKW1uQYFOFTYiN982HGDze1a4jO3hVJG/USfT1Oj+6XgAY0gApBjmEcdnYMhb3bTgj 9/rXS4Q3SRB99EJ8nzN0mznpz0r4gKE3wWIN2VNAfVBQEWVgD63osg4qPyfnTs8Tk46C Lkb73sijQAb0+jRlvb0EaE7RShNbNG8ByqcuFGqSCum36vPBrM3hV9vW9a7D5h5w/5sq xr6zKu4G+X2MqIPYZJppZjXd7bis4kSMgN/wkFVVWAe5i7qij1RhGt8/5mUM3S2lYLu0 IisA== X-Forwarded-Encrypted: i=1; AJvYcCVSFAxQYrQOCDQaln/9BJmy2DaeCzSXLtq0GjB01YxXkGkq5C8BbnHoIDsfknCMChNYDYqxTLI9f4WVP/c=@vger.kernel.org X-Gm-Message-State: AOJu0Yy9BZAoBD+xj0aJ26zIft4sr0ioVtPMtfntUzz+wPYIU6qe8Ywn nAzCFBOyvNaB0WioEzCUxozUjDO/uqv4sINd6bF26u6ueYWBdqawGSOw X-Gm-Gg: AY/fxX54ZVPMPKs5ET1+0qgNugPO46x/BB3RYpk10MVtZarSJ+mx0UGT20K84eMxVU+ +Vyg2PhZxNfCi+EnYB1W9OghGH/gvqUgrBzcBTntc8MENF8EI9efwHcbDwr/PAl2S1VZhtoj6m2 +CtSCK3Slnyka59bSlK4s73IRmsuMaq+4jtKwu6x2XaXmcp4EoLRbkKpRJLVEzfO0oNtur0CmuP NLf0PpqXCYI56csG52TdcEiernuXHzkOq7pCwoGJNR1y90jk+j1NlvCuf49R3I8Fe2Lxq7uNsuN mtPM1LWUAof19Z8BzB2uqojHzohbdspkIaO8jNWmUErSb6um2aG7BCOALiK5L99BIT5ZjgS1eoX czuG6fsbTaQnt2CABFMP6GGFef0Kek93F2vAP8C6XpUtlgdBiwQAQG1D0GGNyJjEF6OMmkYhsrD DCbCrq0MwgoytlCw== X-Google-Smtp-Source: AGHT+IH2WIF4hphWW0XtGGA1SToKGTIqx/q3Z92fb/Q7Z8frNrC6d9JrMtsfB3KMI4GNdYnypexj5Q== X-Received: by 2002:a05:6402:1ed2:b0:647:a570:b756 with SMTP id 4fb4d7f45d1cf-6507967bd96mr2985723a12.17.1767704816290; Tue, 06 Jan 2026 05:06:56 -0800 (PST) Received: from prometheus ([85.11.110.37]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6507bf6d4acsm2079927a12.30.2026.01.06.05.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Jan 2026 05:06:56 -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 v6] f2fs: fix use-after-free in f2fs_write_end_io Date: Tue, 6 Jan 2026 14:06:46 +0100 Message-ID: <20260106130646.15092-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 --- 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 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 | 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 =3D NULL; --=20 2.52.0