From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.208.169 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796058417; b=Vc9WkcJfzscmIJYoMqzNnfMBMns7prhxzsg8Wul2WuienoWFXpz0HA95ITkbaboDXS70 qPjd63RFUj8106UjpezupgegsRGxUEiwYx2dt5YpfY2KVFBT0FiYY2ujOq2KTdmP3r//d vxsbTOJeF2hh3/C8Sm1XGZrzfnZQccya4Rv8uN/Ot3iWn/4PrlNSHxoQZMG/HKR33yR2w HgolYsHXJsPJ7PWx3+aKu+ZxEzLa1QWKk0NiKzVRv9oANpPNsL8rjTTjs7vRjgtTLa8Gz aNZkgnUs/CGQrb3SpE2n4XexJcCv2EfNy93A4+0iVchzFaClWR0NJs/z/2/UJzKMufA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796058417; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=cfnXvviFz9mf1kvovRS8Hceb1o9AK1VxWbrdmRDSjRE=; b=ZFO2we0nBCPi2Wp+F8q8Ch/xvuZSrtQ/8lYOuj9k5vi6tOp7v8hoHr2Om0cTC5NAAdsl bcbknG7oGd7VBIm7+I1vAUTrLWoML7OHiSID/dlBvEBvBKwKahVPcmZT+g0KwxUz+TVlp rQmP7aiRjnUW3IeJ2Dto2SEtwNrV2/O6/vrNXTW0dKJ/NO0SM58Pz5PSyzel9YfkU4YTD xvMmvF9vdhn/aC6FgI/9VxUBg8kE0u6kGfOgUQ4fb77B5DRmEQg2FSe9juTrJMe3JOzDj 0z8LsHZKDw04gq6yVv1OPyT4p/qAnhHQ9aQW54thPpnlDt6OC+CNs75jxCAc6BKH7MA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=d3aMi1uB; arc=none smtp.remote-ip=209.85.208.169 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE927606A31C for ; Mon, 30 Nov 2026 17:06:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AE927606A31C 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.a=rsa-sha256 header.s=20260707 header.b=d3aMi1uB Received: by mail-lj1-f169.google.com with SMTP id 38308e7fff4ca-3adef977ad9so80447161fa.1 for ; Mon, 30 Nov 2026 09:06:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796058415; x=1796663215; 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:content-type; bh=cfnXvviFz9mf1kvovRS8Hceb1o9AK1VxWbrdmRDSjRE=; b=d3aMi1uBZnymA3cCKjJj1H5lwE3lu9z+/7Y1hrElklE26r2ng7ixZgIvCyFR7jFpZC ZWBtges4Zo0xxHicDmb03jNNWHAg6vBWLU08KwpLkIoXtb09pKqYsqY3evhUc/G1vr3k +PC+Wzqb7rdOb1kF1PE2emg4naCIrMzc8ro6uTgDfCHlI3aSTDHkdAEHdEvL8MrgWEpH //10Po/BlvASuf34iWoC2UM73L4OSpc0SY1EL7bb+VZwXagkghFc0AQEUXOMPTecjjn+ 5VZJH64/T02g2tEKx42EfAZRC0RVPnDYcZBwe41coC1Wd7KoVxjHkahWVtDYsYQdaToC MgVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796058415; x=1796663215; 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:content-type; bh=cfnXvviFz9mf1kvovRS8Hceb1o9AK1VxWbrdmRDSjRE=; b=MfTr5awh+5gFrxYNc1WB6CNcBogOcbOwC1ZkN0mW0k3eFuLA/um7G1Rb8bu/UqST28 KsZV8BMrlng7BZzxln2GBfVvAmVhLUW5mZwSKwRLgJ4jpeDRxXWx4T1rVQE9JKR/ciWI nGmhSnHO0m+va6Vj54PUPMR6GI/sTSTmCsZ8I8ZJs4INkm+U/ptrXcjfGbzVJvcEmkuu govqSm478zEdt/jZqeks7qmm9kh48IT/EB1xRgaKW+vWfaG1akXqAw+gndf9JwCjgfu3 9l52U0PoP0Jsu3gVSYqQbOBkOasybGwUob/lO2wVEX3emLG+3vgnothD2M6uyC83dgxd WZmg== X-Forwarded-Encrypted: i=1; AL+hErEo/VpxmGVI428S5802+bGbuIVD8zuuP4HbHMRmp0b7VRK4Eht+4t9PhPUwmNHbQk7AtxTcUSA4zGXB7nw=@vger.kernel.org X-Gm-Message-State: APuU4Z/viW0X5OOncanK+4nJFHq/wDPWzrp5NYOOvt1F37NyMvayfT23 4o1t6mhP08BE9qPCBBV3sKsCMfW0UcznPKvQd2ixNi267f0L5eEFGFmv X-Gm-Gg: AZFdTZcS5OejMQR9Ie8oQyMxpewJmFaWd+7EuhUgBiLBWz+F+Gad8G3ysjHfpQxr3Ly BX8TCyQQl8/L63NfojDqcjAkAcql3RGvmJ8VIBp5ZijAKC77TQMScpMsfJqVJ/NaKn0dL+gPAWT UaJuaSvN38g3AzSyrthjA+NEUMvb3nmnpRZ6RjCWXO0hD8QepwFlcqsUKVQqyrjrzjh3Uw8+9YU 0zLx36blv8lIOXEVi5NVXjx5I85PxVO1ytUBh/Fy+pGHJQSGL7e1mYTZMvzbloOJi1hQUNLBk24 wHuEtrYXdMhQwMU+KjulU7f7q+KtsIc1Zp4HJ+TocPjDLB8GCi0WP9fnPBPS1Q9Uztw2I37B7fS xjrngp7FkgVaLyjJ00TQ/eh7Mi0FKtMGpDhPefn4y9bEvXNLp4UPV9sblvBICCilm6F9cJ4Ftcg KyiopXUyUD5oA+2QHOM6vvl5xhTCbier/izC0pQFWb8xBE8Gdrb7FU51HrUzp0TJ57aVv4OOua+ 0+f6amZBI6Z4UULjtt6/W7N/qHfW4Hikhz1KXHuh9YdzDqT7iCA8wz0X87FQYvpiKxn18iYvAfC bTUMi48OuTPYExnoKOHnbpUWrzT8OvM= X-Received: by 2002:a05:651c:418c:b0:3ab:716d:6406 with SMTP id 38308e7fff4ca-3ae7f9f4057mr74302401fa.17.1796058414677; Mon, 30 Nov 2026 09:06:54 -0800 (PST) Received: from archlinux ([92.36.107.34]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-3ae805575aasm85403981fa.33.2026.11.30.09.06.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 09:06:54 -0800 (PST) From: Kirill Vanzha To: jaegeuk@kernel.org, chao@kernel.org Cc: frank.li@vivo.com, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Kirill Vanzha , stable@vger.kernel.org Subject: [PATCH] f2fs: flush s_error_work on early mount failures Date: Mon, 30 Nov 2026 20:06:11 +0300 Message-ID: <20261130170615.150247-2-vanzha.kirill@gmail.com> X-Mailer: git-send-email 2.56.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit f2fs_fill_super() initializes s_error_work early, but the only flush_work() on the mount failure paths sits at the stop_ckpt_thread label. Failure exits that jump to labels located after it in source order skip the flush while still freeing raw_super and sbi, a pending f2fs_record_error_work() can run afterwards and touch freed memory. A crafted image with a single-segment checkpoint area and zero-length SIT/NAT/SSA areas passes sanity_check_area_boundary(), which makes main_blkaddr == cp_blkaddr + 512. f2fs_get_valid_checkpoint() then reads checkpoint pack 2 at cp_blkaddr + 512, f2fs_is_valid_blkaddr(META_GENERIC) rejects the address and calls f2fs_handle_error(ERROR_INVALID_BLKADDR), which schedules s_error_work. Both checkpoint packs are unusable, the mount fails with -EFSCORRUPTED, and the cleanup frees raw_super/sbi with the work still queued. Flush s_error_work at free_sb_buf before raw_super and sbi are freed. Also move INIT_WORK() above read_raw_super_block(), the sb_set_blocksize() failure path jumps to free_sb_buf before the current INIT_WORK() site flushing a never-initialized work. On these early failure paths no background threads are running and the error worker does not requeue itself, so a plain flush_work() is sufficient and preserves pending error recording. Found by Linux Verification Center (linuxtesting.org) with Syzkaller. Fixes: ca8b201f2854 ("f2fs: fix to avoid potential deadlock") Cc: stable@vger.kernel.org Signed-off-by: Kirill Vanzha --- The patch is based on the bugfix/common branch of the f2fs development tree: https://git.kernel.org/pub/scm/linux/kernel/git/chao/linux.git/log/?h=bugfix/common fs/f2fs/super.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 0cbcc1bc9c42..e300e5445641 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -5245,6 +5245,7 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) init_f2fs_rwsem(&sbi->quota_sem); init_waitqueue_head(&sbi->cp_wait); spin_lock_init(&sbi->error_lock); + INIT_WORK(&sbi->s_error_work, f2fs_record_error_work); for (i = 0; i < NR_INODE_TYPE; i++) { INIT_LIST_HEAD(&sbi->inode_list[i]); @@ -5268,7 +5269,6 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) goto free_sb_buf; } - INIT_WORK(&sbi->s_error_work, f2fs_record_error_work); memcpy(sbi->errors, raw_super->s_errors, MAX_F2FS_ERRORS); memcpy(sbi->stop_reason, raw_super->s_stop_reason, MAX_STOP_REASON); @@ -5702,6 +5702,12 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) /* no need to free dummy_enc_policy, we just keep it in ctx when failed */ swap(F2FS_CTX_INFO(ctx).dummy_enc_policy, F2FS_OPTION(sbi).dummy_enc_policy); free_sb_buf: + /* + * s_error_work may be scheduled on early error paths that bypass + * stop_ckpt_thread's flush, make sure it is flushed before + * freeing raw_super + */ + flush_work(&sbi->s_error_work); kfree(raw_super); free_sbi: #ifdef CONFIG_DEBUG_LOCK_ALLOC -- 2.56.1