From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E365C38142 for ; Fri, 27 Jan 2023 23:08:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229495AbjA0XIC (ORCPT ); Fri, 27 Jan 2023 18:08:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232685AbjA0XIA (ORCPT ); Fri, 27 Jan 2023 18:08:00 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBBE52129F for ; Fri, 27 Jan 2023 15:07:58 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2C6BE61B23 for ; Fri, 27 Jan 2023 23:07:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8176CC433D2; Fri, 27 Jan 2023 23:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1674860877; bh=K/+7u81eBZtLT5HrXJWhBaqK61ZrssOr0CSMrEUJXLY=; h=Date:To:From:Subject:From; b=QBtlN+SDxiAC7fk9VaC/YhDFXrFxYKA8PjgtNdxc3bL968g6hOjyVRo7DytsN+BrB j/gforQwBrefLnssZZWXK936L/fgkp+adf+ddOZeog6whDB5MBwLLRZYLVV9ie68uP 4HZAbZ3VxQ2uQVjhvDOTh2Ji44xb9+BETtcbi974= Date: Fri, 27 Jan 2023 15:07:56 -0800 To: mm-commits@vger.kernel.org, syzbot+cbff7a52b6f99059e67f@syzkaller.appspotmail.com, konishi.ryusuke@gmail.com, akpm@linux-foundation.org From: Andrew Morton Subject: + nilfs2-prevent-warning-in-nilfs_dat_commit_end.patch added to mm-nonmm-unstable branch Message-Id: <20230127230757.8176CC433D2@smtp.kernel.org> Precedence: bulk Reply-To: linux-kernel@vger.kernel.org List-ID: X-Mailing-List: mm-commits@vger.kernel.org The patch titled Subject: nilfs2: prevent WARNING in nilfs_dat_commit_end() has been added to the -mm mm-nonmm-unstable branch. Its filename is nilfs2-prevent-warning-in-nilfs_dat_commit_end.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/nilfs2-prevent-warning-in-nilfs_dat_commit_end.patch This patch will later appear in the mm-nonmm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Ryusuke Konishi Subject: nilfs2: prevent WARNING in nilfs_dat_commit_end() Date: Fri, 27 Jan 2023 22:22:02 +0900 If nilfs2 reads a corrupted disk image and its DAT metadata file contains invalid lifetime data for a virtual block number, a kernel warning can be generated by the WARN_ON check in nilfs_dat_commit_end() and can panic if the kernel is booted with panic_on_warn. This patch avoids the issue with a sanity check that treats it as an error. Since error return is not allowed in the execution phase of nilfs_dat_commit_end(), this inserts that sanity check in nilfs_dat_prepare_end(), which prepares for nilfs_dat_commit_end(). As the error code, -EINVAL is returned to notify bmap layer of the metadata corruption. When the bmap layer sees this code, it handles the abnormal situation and replaces the return code with -EIO as it should. Link: https://lkml.kernel.org/r/000000000000154d2c05e9ec7df6@google.com Link: https://lkml.kernel.org/r/20230127132202.6083-1-konishi.ryusuke@gmail.com Signed-off-by: Ryusuke Konishi Reported-by: Tested-by: Ryusuke Konishi Signed-off-by: Andrew Morton --- --- a/fs/nilfs2/dat.c~nilfs2-prevent-warning-in-nilfs_dat_commit_end +++ a/fs/nilfs2/dat.c @@ -158,6 +158,7 @@ void nilfs_dat_commit_start(struct inode int nilfs_dat_prepare_end(struct inode *dat, struct nilfs_palloc_req *req) { struct nilfs_dat_entry *entry; + __u64 start; sector_t blocknr; void *kaddr; int ret; @@ -169,6 +170,7 @@ int nilfs_dat_prepare_end(struct inode * kaddr = kmap_atomic(req->pr_entry_bh->b_page); entry = nilfs_palloc_block_get_entry(dat, req->pr_entry_nr, req->pr_entry_bh, kaddr); + start = le64_to_cpu(entry->de_start); blocknr = le64_to_cpu(entry->de_blocknr); kunmap_atomic(kaddr); @@ -179,6 +181,15 @@ int nilfs_dat_prepare_end(struct inode * return ret; } } + if (unlikely(start > nilfs_mdt_cno(dat))) { + nilfs_err(dat->i_sb, + "vblocknr = %llu has abnormal lifetime: start cno (= %llu) > current cno (= %llu)", + (unsigned long long)req->pr_entry_nr, + (unsigned long long)start, + (unsigned long long)nilfs_mdt_cno(dat)); + nilfs_dat_abort_entry(dat, req); + return -EINVAL; + } return 0; } _ Patches currently in -mm which might be from konishi.ryusuke@gmail.com are nilfs2-replace-warn_ons-for-invalid-dat-metadata-block-requests.patch nilfs2-prevent-warning-in-nilfs_dat_commit_end.patch