From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 A5ADF3E4C81 for ; Thu, 23 Apr 2026 09:20:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776936058; cv=none; b=a8x2KLeEuB52QqRHJqa4UNTmPjQsUMzXs5FrGMlfo/f8QDI95MF6AVg6L3Kt2I391FZHAlD61dJFTPkPe1P5tU+RTmJWEM61dbGKTKWvZNG/SZAnVLazKibfMcYQZEjo2aBrCHxf26nASRzpTu1PirE2TfW5r3f6Fwzu6c6TTiI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776936058; c=relaxed/simple; bh=K7o56FXoqRFyY/mX8M8npp10YmZ3rqb233igp8tPuFk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=VyHpYg80eiKOYmK5v0n1f4HBAo9tTqoRjZ0ywo7bpCyi/UDEZklTp+d63pkBsF8LSdsvVg3DYQnxiDwkRi90GKhxpEiPZT31V1LKBlMCYUM13/1AvCLatgUSrJIWjzJIehD4ZDWhPlpRhvTgAO1IwiW36AeNUnM5xv258yaUeqg= 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=XmnIw71c; arc=none smtp.client-ip=209.85.210.173 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="XmnIw71c" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-82748257f5fso4028911b3a.1 for ; Thu, 23 Apr 2026 02:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776936056; x=1777540856; 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=fdhDKETwuj9Ml6qRV2b2vUEXK+zO6bSmJ/i18ItJCMs=; b=XmnIw71cbsJin3xVr9MOR+OfRV2DAUxYKBXD/N2vAngR6bq2wfdvxEkprjxlcEZHdj SPVlMcWDfEcW5BjrH83sCirtCWQZQ5JLtwszZ1v/bEmZOKBKFFDnTFhrGuHawqSx0uSA iQWMiyd5RU6rrqY4Ob/1Ut9+nmo2KnpZH6/n9jI4bMUq49eTapi/+vbR9sixPcVN0Rtg XI6/OtMi5dSgdgDsDbhDmuM+HCrEN2pmZtYajcs3faKONIHdQ6RrCiznBNIzzdp7Ut5i DGW3fTQu4DOV5A2i99ldbgT3gih5D6Y98PnmIuduvC0yTVzr2ma6zFvkKR2GGjjr58oE 5zjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776936056; x=1777540856; 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=fdhDKETwuj9Ml6qRV2b2vUEXK+zO6bSmJ/i18ItJCMs=; b=bZIew6pdjE7pO6XR/yJugM0O9+Wk9C/IIP6+Cw7Tvn7LWrLZfX8q4iH7sIOC9jsjyM VXnzlXMS4UX1YfUjL5vXdEHRjOwhvw8NambWaDPCeWrRuW+4YIWTP5hRzzE1L24Mo46y cq5ToTK20woorLBBOUSTSg+NHjZFCLoOW7Un4VcX+zRnwUr/1X49kbixBSZ4cBk5iQFZ u5KuCF+hSYOA2wTYWevTBPtLz7vlT1hJY89kERQtK6Eq7MbYg0ZeWu63Ht5BocIyZPao jwtHXFJO9WZaxspLnsItzTld80uaWwqTYsmn8kVMCLNvxb/foZmAmNItFdU2tCkU6t23 Xs4g== X-Forwarded-Encrypted: i=1; AFNElJ86yh9TWwnLEP2TsxWFxXlTspkKKCg549NAeBLvQDdVxfylxVxBzyEgzF/wv91z8yqvNZ7rKQ6aUBS00o4=@vger.kernel.org X-Gm-Message-State: AOJu0YzCQk4+vQ8hYScOEQl0BKNbpDc3oTu+VlND8OUJPGa0xE4hPECf szkP8hPBaCCg2+k8SW4YiVJrJqMK02KUC9ppelUBUHLUp5v0vV0YjMD1XI5d2bkQpEE= X-Gm-Gg: AeBDievFO9XioB7qFoNqwjpgowN5tD3Kbmvy+xyTl2sw+RJsZHW465tGmToX4TY7JNF lPxKxuBcuCC56Q8R+LJroWI84v3qFfZjWb8v3H7J/vLORcAtzVaIV+/OKBTiTeIVt7QdStwb/2x MzwD0HuuwiO7z+MsHM05w5QnlQPma3u3THdLOdf2dWZn3SjYzg5BCQaACrBLWbtmznUCnZFKF/F J6CAUptbXGmuX1ZH4JO/qZYcX3m6DUdO6e1cL2M7Xmy5gl+47+IURPAV6RVWj1M1DJi8ZNik4O7 fECummhCfIVao46PfL837SfRBuvs3n1US31qqH2QaZWqPNy10IXLl4oKObUZ6DIDnNCFVZzUhJB NLpIpExz7VdfhKy0wB6c8spVj+l/YSoKY4K2Vta/8LoeMw12tvm+7fb8jImum5/U/65suopRys5 njMH5HJfASUZgt2KeKatxSXX8i1O3NDlbKstNVGc9MIKn1V3f7lH707K/IkWpRKGtD9m5AaLUzw y4+ySk6oA== X-Received: by 2002:a05:6a00:14c2:b0:82f:3774:4fdc with SMTP id d2e1a72fcca58-82f8b32d6c7mr22315357b3a.1.1776936055789; Thu, 23 Apr 2026 02:20:55 -0700 (PDT) Received: from kernel-fuzz.. ([103.172.182.26]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82f8e9d35acsm20300218b3a.15.2026.04.23.02.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2026 02:20:55 -0700 (PDT) From: ZhengYuan Huang To: agruenba@redhat.com Cc: gfs2@lists.linux.dev, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, r33s3n6@gmail.com, zzzccc427@gmail.com, ZhengYuan Huang Subject: [PATCH] gfs2: wait for recovery log bios in sync recovery Date: Thu, 23 Apr 2026 17:20:44 +0800 Message-ID: <20260423092044.3769207-1-gality369@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit [BUG] Mounting a fuzzed image can recover journal 0 and queue clean_journal()'s log-header bio, then fail recovering journal 1 on corrupted metadata. The mount unwind frees struct gfs2_sbd, and the delayed bio completion later reports: BUG: KASAN: slab-use-after-free in instrument_atomic_read_write include/linux/instrumented.h:96 [inline] BUG: KASAN: slab-use-after-free in atomic_dec_and_test include/linux/atomic/atomic-instrumented.h:1383 [inline] BUG: KASAN: slab-use-after-free in gfs2_end_log_write+0xe3/0x7c0 fs/gfs2/lops.c:230 Write of size 4 at addr ffff888012810e78 by task ublk.fsfuzz/334 __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0xbe/0x130 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0xd1/0x650 mm/kasan/report.c:482 kasan_report+0xfb/0x140 mm/kasan/report.c:595 check_region_inline mm/kasan/generic.c:186 [inline] kasan_check_range+0x11c/0x200 mm/kasan/generic.c:200 __kasan_check_write+0x14/0x30 mm/kasan/shadow.c:37 instrument_atomic_read_write include/linux/instrumented.h:96 [inline] atomic_dec_and_test include/linux/atomic/atomic-instrumented.h:1383 [inline] gfs2_end_log_write+0xe3/0x7c0 fs/gfs2/lops.c:230 bio_endio+0x5e0/0x700 block/bio.c:1678 blk_update_request+0x7e5/0x14e0 block/blk-mq.c:998 blk_mq_end_request+0x61/0x3e0 block/blk-mq.c:1160 blk_flush_complete_seq+0x8f6/0xea0 block/blk-flush.c:191 mq_flush_data_end_io+0x2b1/0x550 block/blk-flush.c:362 __blk_mq_end_request+0x123/0x380 block/blk-mq.c:1150 __ublk_complete_rq drivers/block/ublk_drv.c:1202 [inline] ublk_ch_uring_cmd_local+0x1a5f/0x2180 drivers/block/ublk_drv.c:2478 ublk_ch_uring_cmd+0x42/0x640 drivers/block/ublk_drv.c:2562 io_uring_cmd+0x26f/0x570 io_uring/uring_cmd.c:263 __io_issue_sqe+0xc2/0x760 io_uring/io_uring.c:1826 io_issue_sqe+0xdd/0x11e0 io_uring/io_uring.c:1849 io_queue_sqe io_uring/io_uring.c:2076 [inline] io_submit_sqe io_uring/io_uring.c:2336 [inline] io_submit_sqes+0x806/0x2390 io_uring/io_uring.c:2449 __do_sys_io_uring_enter+0x5c0/0x13a0 io_uring/io_uring.c:3516 __se_sys_io_uring_enter io_uring/io_uring.c:3455 [inline] __x64_sys_io_uring_enter+0xe5/0x1c0 io_uring/io_uring.c:3455 x64_sys_call+0x2419/0x26a0 arch/x86/include/generated/asm/syscalls_64.h:427 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x93/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x76/0x7e ... Allocated by task 314: kasan_save_stack+0x39/0x70 mm/kasan/common.c:56 kasan_save_track+0x14/0x40 mm/kasan/common.c:77 kasan_save_alloc_info+0x37/0x60 mm/kasan/generic.c:573 poison_kmalloc_redzone mm/kasan/common.c:400 [inline] __kasan_kmalloc+0xc3/0xd0 mm/kasan/common.c:417 kasan_kmalloc include/linux/kasan.h:262 [inline] __kmalloc_cache_noprof+0x25f/0x800 mm/slub.c:5771 kmalloc_noprof include/linux/slab.h:957 [inline] kzalloc_noprof include/linux/slab.h:1094 [inline] init_sbd fs/gfs2/ops_fstype.c:78 [inline] gfs2_fill_super+0x19e/0x2a80 fs/gfs2/ops_fstype.c:1128 get_tree_bdev_flags+0x38b/0x640 fs/super.c:1698 get_tree_bdev+0x24/0x40 fs/super.c:1721 gfs2_get_tree+0x56/0x280 fs/gfs2/ops_fstype.c:1337 vfs_get_tree+0x9a/0x370 fs/super.c:1758 fc_mount fs/namespace.c:1199 [inline] do_new_mount_fc fs/namespace.c:3642 [inline] do_new_mount fs/namespace.c:3718 [inline] path_mount+0x5b8/0x1ea0 fs/namespace.c:4028 do_mount fs/namespace.c:4041 [inline] __do_sys_mount fs/namespace.c:4229 [inline] __se_sys_mount fs/namespace.c:4206 [inline] __x64_sys_mount+0x282/0x320 fs/namespace.c:4206 x64_sys_call+0x1a7d/0x26a0 arch/x86/include/generated/asm/syscalls_64.h:166 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x93/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x76/0x7e Freed by task 314: kasan_save_stack+0x39/0x70 mm/kasan/common.c:56 kasan_save_track+0x14/0x40 mm/kasan/common.c:77 __kasan_save_free_info+0x3b/0x60 mm/kasan/generic.c:587 kasan_save_free_info mm/kasan/kasan.h:406 [inline] poison_slab_object mm/kasan/common.c:252 [inline] __kasan_slab_free+0x6f/0xa0 mm/kasan/common.c:284 kasan_slab_free include/linux/kasan.h:234 [inline] slab_free_hook mm/slub.c:2543 [inline] slab_free mm/slub.c:6642 [inline] kfree+0x2bf/0x6b0 mm/slub.c:6849 free_sbd fs/gfs2/ops_fstype.c:71 [inline] gfs2_fill_super+0x14cd/0x2a80 fs/gfs2/ops_fstype.c:1321 get_tree_bdev_flags+0x38b/0x640 fs/super.c:1698 get_tree_bdev+0x24/0x40 fs/super.c:1721 gfs2_get_tree+0x56/0x280 fs/gfs2/ops_fstype.c:1337 vfs_get_tree+0x9a/0x370 fs/super.c:1758 fc_mount fs/namespace.c:1199 [inline] do_new_mount_fc fs/namespace.c:3642 [inline] do_new_mount fs/namespace.c:3718 [inline] path_mount+0x5b8/0x1ea0 fs/namespace.c:4028 do_mount fs/namespace.c:4041 [inline] __do_sys_mount fs/namespace.c:4229 [inline] __se_sys_mount fs/namespace.c:4206 [inline] __x64_sys_mount+0x282/0x320 fs/namespace.c:4206 x64_sys_call+0x1a7d/0x26a0 arch/x86/include/generated/asm/syscalls_64.h:166 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x93/0xf80 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x76/0x7e [CAUSE] gfs2_recover_journal(jd, true) only waits for the recovery worker to clear JDF_RECOVERY. After the clean_journal() wait was removed, clean_journal() can still have an in-flight bio holding bi_private = sdp when the synchronous caller returns. If a later recovery step fails, mount teardown can free sdp before gfs2_end_log_write() decrements sd_log_in_flight. [FIX] When wait=true, also wait for sd_log_in_flight to drain before returning from gfs2_recover_journal(). This restores the synchronous recovery completion contract on the cold mount path without changing the wait=false recovery callers. Fixes: 4a3d049db42b ("gfs2: Don't wait for journal flush in clean_journal") Signed-off-by: ZhengYuan Huang --- fs/gfs2/recovery.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/gfs2/recovery.c b/fs/gfs2/recovery.c index 616c46aa3434..954b0367e8e2 100644 --- a/fs/gfs2/recovery.c +++ b/fs/gfs2/recovery.c @@ -566,6 +566,7 @@ void gfs2_recover_func(struct work_struct *work) int gfs2_recover_journal(struct gfs2_jdesc *jd, bool wait) { + struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode); int rv; if (test_and_set_bit(JDF_RECOVERY, &jd->jd_flags)) @@ -575,9 +576,12 @@ int gfs2_recover_journal(struct gfs2_jdesc *jd, bool wait) rv = queue_work(gfs2_recovery_wq, &jd->jd_work); BUG_ON(!rv); - if (wait) + if (wait) { wait_on_bit(&jd->jd_flags, JDF_RECOVERY, TASK_UNINTERRUPTIBLE); + /* Synchronous recovery must not return while its log bio is live. */ + log_flush_wait(sdp); + } return wait ? jd->jd_recover_error : 0; } -- 2.49.0