From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AB6119D066; Thu, 25 Jul 2024 14:44:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721918664; cv=none; b=om+1cJfioYSUcFGzjfzH06v4Ff7tcCcCe/mvqCDW876skEfrPa8puP+ErzTDs5o9UXQHDUuBPBg6IkKTPPytwUwWi1vGS+eDW6jS0B2nzyryeBDrBb+mq1zdhZ/fC+MAWlT/AaNAIEDLWKaOvvDmSvNGsQhWnANtqfWyIt/cJZk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721918664; c=relaxed/simple; bh=HysMFN/3fXSfn2xS80AsodmfmvZNhYYZboKu/tUJwHU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QBoYuoy7fJibk26c27Wc3L83wnAC/2lBSl7P6AjXUFk+NVBvqvlh3gJLx4clOYC8diPuJqeupe03R2r1vh57cY9nszo13l/q613RK05JuVm0QkC9DXjpIrsUCwJnzyOoI3lk94EJLNFp32mqab5Xtu2NQen7tGy+rxuZXj7dbZQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=U+HscSB5; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="U+HscSB5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9FA6AC116B1; Thu, 25 Jul 2024 14:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1721918664; bh=HysMFN/3fXSfn2xS80AsodmfmvZNhYYZboKu/tUJwHU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U+HscSB5bSSpvKFqdQWotptCG5nOQfX47zFu3SGkEYQLuNxdPJv1s0yFsUULF3/nG mH/aWVnlFWizmYJ1ULQRS7LGzl92XIHx/aYVm5Q4rmZlY6lLzU8aaWZha78TtUffGY +5kUpZAK3WYi1yjInLf+0hgNwSu2d2jOaTIPrguU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Chao Yu , Jaegeuk Kim , =?UTF-8?q?Sergio=20Gonz=C3=A1lez=20Collado?= , syzbot+d0ab8746c920a592aeab@syzkaller.appspotmail.com Subject: [PATCH 6.1 02/13] f2fs: avoid dead loop in f2fs_issue_checkpoint() Date: Thu, 25 Jul 2024 16:37:11 +0200 Message-ID: <20240725142728.124122639@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240725142728.029052310@linuxfoundation.org> References: <20240725142728.029052310@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chao Yu commit 5079e1c0c879311668b77075de3e701869804adf upstream. generic/082 reports a bug as below: __schedule+0x332/0xf60 schedule+0x6f/0xf0 schedule_timeout+0x23b/0x2a0 wait_for_completion+0x8f/0x140 f2fs_issue_checkpoint+0xfe/0x1b0 f2fs_sync_fs+0x9d/0xb0 sync_filesystem+0x87/0xb0 dquot_load_quota_sb+0x41b/0x460 dquot_load_quota_inode+0xa5/0x130 dquot_quota_on+0x4b/0x60 f2fs_quota_on+0xe3/0x1b0 do_quotactl+0x483/0x700 __x64_sys_quotactl+0x15c/0x310 do_syscall_64+0x3f/0x90 entry_SYSCALL_64_after_hwframe+0x72/0xdc The root casue is race case as below: Thread A Kworker IRQ - write() : write data to quota.user file - writepages - f2fs_submit_page_write - __is_cp_guaranteed return false - inc_page_count(F2FS_WB_DATA) - submit_bio - quotactl(Q_QUOTAON) - f2fs_quota_on - dquot_quota_on - dquot_load_quota_inode - vfs_setup_quota_inode : inode->i_flags |= S_NOQUOTA - f2fs_write_end_io - __is_cp_guaranteed return true - dec_page_count(F2FS_WB_CP_DATA) - dquot_load_quota_sb - f2fs_sync_fs - f2fs_issue_checkpoint - do_checkpoint - f2fs_wait_on_all_pages(F2FS_WB_CP_DATA) : loop due to F2FS_WB_CP_DATA count is negative Calling filemap_fdatawrite() and filemap_fdatawait() to keep all data clean before quota file setup. Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sergio González Collado Reported-by: syzbot+d0ab8746c920a592aeab@syzkaller.appspotmail.com Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/super.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -2824,15 +2824,26 @@ static int f2fs_quota_on(struct super_bl return -EBUSY; } + if (path->dentry->d_sb != sb) + return -EXDEV; + err = f2fs_quota_sync(sb, type); if (err) return err; - err = dquot_quota_on(sb, type, format_id, path); + inode = d_inode(path->dentry); + + err = filemap_fdatawrite(inode->i_mapping); if (err) return err; - inode = d_inode(path->dentry); + err = filemap_fdatawait(inode->i_mapping); + if (err) + return err; + + err = dquot_quota_on(sb, type, format_id, path); + if (err) + return err; inode_lock(inode); F2FS_I(inode)->i_flags |= F2FS_NOATIME_FL | F2FS_IMMUTABLE_FL;