{"id":"CVE-2026-99570","summary":"f2fs: fix to invalidate curseg if change_curseg() fails","details":"In the Linux kernel, the following vulnerability has been resolved:\n\nf2fs: fix to invalidate curseg if change_curseg() fails\n\nOur consistency stress test (fsstress + fio + atomic write workers +\n\"f2fs_io shutdown 1\") triggers below kernel BUG:\n\n F2FS-fs (vdd): Stopped filesystem due to reason: 0\n ------------[ cut here ]------------\n kernel BUG at fs/f2fs/segment.c:3989!\n Oops: invalid opcode: 0000 [#1] SMP KASAN PTI\n Workqueue: writeback wb_workfn (flush-253:48)\n RIP: 0010:f2fs_allocate_data_block+0x257a/0x38e0\n Call Trace:\n  \u003cTASK\u003e\n  do_write_block+0x155/0xc10\n  f2fs_outplace_write_data+0x192/0x340\n  f2fs_do_write_data_page+0xc57/0x1880\n  f2fs_write_single_data_page+0xda9/0x15a0\n  f2fs_write_cache_pages+0x973/0x1f20\n  __f2fs_write_data_pages+0x6c4/0x1890\n  do_writepages+0x21e/0x560\n  __writeback_single_inode+0x119/0x11b0\n  writeback_sb_inodes+0x67d/0x17a0\n  wb_writeback+0x207/0x820\n  wb_workfn+0x128/0xc30\n  process_one_work+0x925/0x1600\n  worker_thread+0x60a/0xff0\n  kthread+0x35f/0x460\n  ret_from_fork+0x474/0x7e0\n  ret_from_fork_asm+0x1a/0x30\n  \u003c/TASK\u003e\n\nThe BUG is f2fs_bug_on(sbi, curseg-\u003enext_blkoff \u003e= BLKS_PER_SEG(sbi))\nin f2fs_allocate_data_block(), next_blkoff was 512.\n\nThe root cause is a race in between atomic write commit and shutdown\nas below:\n\nThread A (commit atomic write)  Thread B (shutdown)        Thread C (writeback)\n- f2fs_ioc_commit_atomic_write\n - f2fs_commit_atomic_write\n  - __f2fs_commit_atomic_write\n   - __replace_atomic_write_block\n    - f2fs_replace_block\n     - __f2fs_replace_block\n                                - f2fs_ioc_shutdown\n                                 - f2fs_do_shutdown\n                                 : F2FS_GOING_DOWN_METASYNC\n                                  - f2fs_sync_fs\n                                                           - f2fs_write_single_data_page\n                                                           : pass f2fs_cp_error() check\n                                  - f2fs_stop_checkpoint\n                                  : set CP_ERROR_FLAG\n      - change_curseg\n       - reset_curseg\n       : curseg-\u003esegno = new_segno\n       : curseg-\u003ealloc_type = SSR\n       : curseg-\u003enext_blkoff = __next_free_blkoff()\n         which is BLKS_PER_SEG if there is no free\n         slot in new_segno\n       - f2fs_get_sum_cache\n       : return -EIO due to f2fs_cp_error()\n      : return error w/o restoring curseg\n     : goto out_unlock, skip restoring\n       old segno, blkoff and alloc_type\n                                                            - f2fs_do_write_data_page\n                                                             - f2fs_outplace_write_data\n                                                              - do_write_block\n                                                               - f2fs_allocate_data_block\n                                                               : curseg-\u003esegno is valid\n                                                               : f2fs_bug_on(next_blkoff \u003e=\n                                                                 BLKS_PER_SEG)\n\nSince commit 86f33603f8c5 (\"f2fs: handle errors of\nf2fs_get_meta_page_nofail\"), change_curseg() can fail after the curseg\nhas already been switched to the new segment, then the curseg is left\nin an inconsistent state: it points to a segment which may have no\nfree slot, its summary block is zeroed, and the caller can not restore\nit. Subsequent block allocation on the curseg will trigger the BUG.\nMoreover, the writeback thread dies with curseg_lock, curseg_mutex and\nsentry_lock held, so the commit, shutdown and other I/O threads hang\nin D state.\n\nSince change_curseg() only fails once CP_ERROR_FLAG is set, no\ncheckpoint will be committed afterward, let's invalidate the curseg via\nreset_curseg_fields() on failure, as new_curseg() does for -ENOSPC,\nthen f2fs_allocate_data_block() will fail with -ENOSPC on the curseg\ninstead of triggering BUG, and do_write_block() can handle the error\nsince CP_ERROR_FLA\n---truncated---","modified":"2026-11-20T07:00:41.573245174Z","published":"2026-11-20T05:49:05.202Z","database_specific":{"osv_generated_from":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/99xxx/CVE-2026-99570.json","cna_assigner":"Linux"},"references":[{"type":"PACKAGE","url":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git"},{"type":"WEB","url":"https://git.kernel.org/stable/c/1c9ccd9eadf1707a2149c3237b85f1f82ce92702"},{"type":"WEB","url":"https://git.kernel.org/stable/c/c2de116785396df236e311e7643913212fe9fe50"},{"type":"WEB","url":"https://git.kernel.org/stable/c/c8e6c10f95643dd88e73e7daa8ceb1041631920c"},{"type":"WEB","url":"https://git.kernel.org/stable/c/e74476ad8162c1facc74b74ce2d1372492df872e"},{"type":"ADVISORY","url":"https://github.com/CVEProject/cvelistV5/tree/main/cves/2026/99xxx/CVE-2026-99570.json"},{"type":"ADVISORY","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-99570"}],"affected":[{"ranges":[{"type":"GIT","repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","events":[{"introduced":"86f33603f8c51537265ff7ac0320638fd2cbdb1b"},{"fixed":"1c9ccd9eadf1707a2149c3237b85f1f82ce92702"},{"fixed":"c8e6c10f95643dd88e73e7daa8ceb1041631920c"},{"fixed":"c2de116785396df236e311e7643913212fe9fe50"},{"fixed":"e74476ad8162c1facc74b74ce2d1372492df872e"}]},{"type":"GIT","repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","events":[{"introduced":"df5b07f2172a159a4d9f0c280e6ecddba992ba35"}]},{"type":"GIT","repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","events":[{"introduced":"6b67737f2dde60fbad8ddac37c8653e3c3bf0855"}]}],"versions":["v5.4.302","v5.4.301","v5.4.300","v5.4.299","v5.4.298","v5.4.297","v5.4.296","v5.4.295","v5.4.294","v5.4.293","v5.4.292","v5.4.291","v5.4.290","v5.4.289","v5.4.288","v5.4.287","v5.4.286","v5.4.285","v5.4.284","v5.4.283","v5.4.282","v5.4.281","v5.4.280","v5.4.279","v5.4.278","v5.4.277","v5.4.276","v5.4.275","v5.4.274","v5.4.273","v5.4.272","v5.4.271","v5.4.270","v5.4.269","v5.4.268","v5.4.267","v5.4.266","v5.4.265","v5.4.264","v5.4.263","v5.4.262","v5.4.261","v5.4.260","v5.4.259","v5.4.258","v5.4.257","v5.4.256","v5.4.255","v5.4.254","v5.4.253","v5.4.252","v5.4.251","v5.4.250","v5.4.249","v5.4.248","v5.4.247","v5.4.246","v5.4.245","v5.4.244","v5.4.243","v5.4.242","v5.4.241","v5.4.240","v5.4.239","v5.4.238","v5.4.237","v5.4.236","v5.4.235","v5.4.234","v5.4.233","v5.4.232","v5.4.231","v5.4.230","v5.4.229","v5.4.228","v5.4.227","v5.4.226","v5.4.225","v5.4.224","v5.4.223","v5.4.222","v5.4.221","v5.4.220","v5.4.219","v5.4.218","v5.4.217","v5.4.216","v5.4.215","v5.4.214","v5.4.213","v5.4.212","v5.4.211","v5.4.210","v5.4.209","v5.4.208","v5.4.207","v5.4.206","v5.4.205","v5.4.204","v5.4.203","v5.4.202","v5.4.201","v5.4.200","v5.4.199","v5.4.198","v5.4.197","v5.4.196","v5.4.195","v5.4.194","v5.4.193","v5.4.192","v5.4.191","v5.4.190","v5.4.189","v5.4.188","v5.4.187","v5.4.186","v5.4.185","v5.4.184","v5.4.183","v5.4.182","v5.4.181","v5.4.180","v5.4.179","v5.4.178","v5.4.177","v5.4.176","v5.4.175","v5.4.174","v5.4.173","v5.4.172","v5.4.171","v5.4.170","v5.4.169","v5.4.168","v5.4.167","v5.4.166","v5.4.165","v5.4.164","v5.4.163","v5.4.162","v5.4.161","v5.4.160","v5.4.159","v5.4.158","v5.4.157","v5.4.156","v5.4.155","v5.4.154","v5.4.153","v5.4.152","v5.4.151","v5.4.150","v5.4.149","v5.4.148","v5.4.147","v5.4.146","v5.4.145","v5.4.144","v5.4.143","v5.4.142","v5.4.141","v5.4.140","v5.4.139","v5.4.138","v5.4.137","v5.4.136","v5.4.135","v5.4.134","v5.4.133","v5.4.132","v5.4.131","v5.4.130","v5.4.129","v5.4.128","v5.4.127","v5.4.126","v5.4.125","v5.4.124","v5.4.123","v5.4.122","v5.4.121","v5.4.120","v5.4.119","v5.4.118","v5.4.117","v5.4.116","v5.4.115","v5.4.114","v5.4.113","v5.4.112","v5.4.111","v5.4.110","v5.4.109","v5.4.108","v5.4.107","v5.4.106","v5.4.105","v5.4.104","v5.4.103","v5.4.102","v5.4.101","v5.4.100","v5.4.99","v5.4.98","v5.4.97","v5.4.96","v5.4.95","v5.4.94","v5.4.93","v5.4.92","v5.4.91","v5.4.90","v5.4.89","v5.4.88","v5.4.87","v5.4.86","v5.4.85","v5.4.84","v5.4.83","v5.4.82","v5.4.81","v5.4.80","v5.4.79","v5.4.78","v5.4.77","v5.4.76","v5.4.75","v5.9.16","v5.9.15","v5.9.14","v5.9.13","v5.9.12","v5.9.11","v5.9.10","v5.9.9","v5.9.8","v5.9.7","v5.9.6","v5.9.5"],"database_specific":{"source":"https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2026-99570.json"}},{"package":{"name":"Kernel","ecosystem":"Linux"},"ranges":[{"type":"ECOSYSTEM","events":[{"introduced":"5.4.75"},{"fixed":"5.5"}]},{"type":"ECOSYSTEM","events":[{"introduced":"5.9.5"},{"fixed":"5.10"}]},{"type":"ECOSYSTEM","events":[{"introduced":"5.10.0"},{"fixed":"6.12.118"}]},{"type":"ECOSYSTEM","events":[{"introduced":"6.13.0"},{"fixed":"6.18.64"}]},{"type":"ECOSYSTEM","events":[{"introduced":"6.19.0"},{"fixed":"7.3.5"}]}],"database_specific":{"source":"https://storage.googleapis.com/cve-osv-conversion/osv-output/CVE-2026-99570.json"}}],"schema_version":"1.9.2"}