From patchwork Thu Feb 8 14:42:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Smirnov X-Patchwork-Id: 198436 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp215287dyd; Thu, 8 Feb 2024 06:43:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IEyL2VjzooldIpI7VzOmAgDKEoALwon+Q+QXZ/LuhwYz/b8JxUpU7l2pm450GxpUVWCnT88 X-Received: by 2002:a05:622a:1d6:b0:42c:6c5:d519 with SMTP id t22-20020a05622a01d600b0042c06c5d519mr11337416qtw.31.1707403399646; Thu, 08 Feb 2024 06:43:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707403399; cv=pass; d=google.com; s=arc-20160816; b=Sn9TxM0u4eeHGs6jnclaiVEg0+k4bF6Cgh41K6izAuAW90hC8YnEiRoYjBFRx4FYgU d+MERQUoPzcx4eBqvKRJx0vbBZBEp72Hon7O8WpoPIbCx0LX4/0iSptAW4UHYQd5FqPM mCgGj7p+bZ9NrZEQQgym5ttmht89rXOdlU77+iYwbkJrHon+yc0LnKWpAgs2CPWIE2kq yKMG/vHWc6CAMFVMHMNtqMgvgam7VKVLLBiLGFCzUmVWLCptq6XEzrKSuRLRmw3p9cQK bTlSW5kMrl482xS8AlyTrDr/PxyPoIsehXVdXELwr1hJENNOvZleO5a+dvBdE58PwPRN 8GTw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=MqNlvurw/bCIYNdrzAu8aweF2wH4VdLvzrteNnw1tzQ=; fh=1yxW4Tyasi3ykt0GFKCpjIneQi+TwOiZmel68kiXXPk=; b=0gTWk0YHVgjG18cvw3RCl9l+BnMhOLbDmN9XpWDl3+q4jGyd1WpaFVyqbY2bzB9LYp 1eX7hnyozBOzZTHAob3YFKWlidMp7DdsXwEKKHkqxT7ftUtkNGLH1iwIxHcerslEViuM 0XkKyLq8pkW7sl3+RStDBEZuPbcjqTwm3FJ+nzuBeEO3uLxCvDSsg5IX1wpnLuRAjoyH eRoLySVpdsjzk7/eT92CffxzwmTFVZcLxf5kQV6TC+zAJo3Nnam/2l0jJThvDb8mItSB dViz3LwgZJ0oZPf0ZYPqoBv+44IqGmxKScvUB7q3bLHXWqQqqG+qvtrhKWk60kIzP4iI k8GA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=omp.ru); spf=pass (google.com: domain of linux-kernel+bounces-58244-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58244-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCWZCGB428xsYP7Eftjb1qnC65pjUDVFB+E5nPQH3V3mYUVoQfIIVoGki4AWaLG1/spvZvyPshqunvlW5IU/7wwCfUHOLg== Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id b18-20020ac85bd2000000b0042c366a6041si161384qtb.104.2024.02.08.06.43.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 06:43:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58244-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=omp.ru); spf=pass (google.com: domain of linux-kernel+bounces-58244-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58244-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6D6221C2681F for ; Thu, 8 Feb 2024 14:43:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9021A7B3F3; Thu, 8 Feb 2024 14:42:57 +0000 (UTC) Received: from mx01.omp.ru (mx01.omp.ru [90.154.21.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACCD279DBC; Thu, 8 Feb 2024 14:42:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.154.21.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707403375; cv=none; b=kuf7gmsupBpVj1V/tPsO4F2/nT/NXKrggwAp4FJw9meR4YiWx/UBu+QEDxTC4vJvT3WJKRZLjNNYVhPDBMva7SdOYC/iUls8VHXFgvgtwZJnof7jdY49R03y0NB31AGCP70bFrBxvzWfqWbsbpFIhd6xVUNaJssmOWzucJrDkuE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707403375; c=relaxed/simple; bh=X3hYsJQUl7XAROpU2r6hlHoHIxUPoVToI+Gp6Eg2AZY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZrFBQJduAknFgosGD+RUiNcjJBA3zRf221IXuy7PBPwwsY62pyxEQw9OCop7DP+Fp4iroktMxJhcB1t7sXRHmWsAqkheSAp2QaVhTyDOeICExh9HN9DOxqO8H4C/rvjIFYxGIjD8h0uQDyNbOIVUIfP6BA2WWPg3T1yMGeC93UM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=omp.ru; spf=pass smtp.mailfrom=omp.ru; arc=none smtp.client-ip=90.154.21.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=omp.ru Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=omp.ru Received: from r.smirnovsmtp.omp.ru (10.189.215.22) by msexch01.omp.ru (10.188.4.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1258.12; Thu, 8 Feb 2024 17:42:41 +0300 From: Roman Smirnov To: , Greg Kroah-Hartman CC: Roman Smirnov , Ryusuke Konishi , , , Alexey Khoroshilov , , Sergey Shtylyov , Karina Yankevich , Andrey Rusalin , Sergey Yudin , Valentin Perevozchikov Subject: [PATCH 5.10/5.15/6.1 1/1] nilfs2: replace WARN_ONs for invalid DAT metadata block requests Date: Thu, 8 Feb 2024 14:42:24 +0000 Message-ID: <20240208144224.438146-2-r.smirnov@omp.ru> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240208144224.438146-1-r.smirnov@omp.ru> References: <20240208144224.438146-1-r.smirnov@omp.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: msexch02.omp.ru (10.188.4.13) To msexch01.omp.ru (10.188.4.12) X-KSE-ServerInfo: msexch01.omp.ru, 9 X-KSE-AntiSpam-Interceptor-Info: scan successful X-KSE-AntiSpam-Version: 6.1.0, Database issued on: 02/08/2024 14:27:39 X-KSE-AntiSpam-Status: KAS_STATUS_NOT_DETECTED X-KSE-AntiSpam-Method: none X-KSE-AntiSpam-Rate: 0 X-KSE-AntiSpam-Info: Lua profiles 183298 [Feb 08 2024] X-KSE-AntiSpam-Info: Version: 6.1.0.3 X-KSE-AntiSpam-Info: Envelope from: r.smirnov@omp.ru X-KSE-AntiSpam-Info: LuaCore: 7 0.3.7 6d6bf5bd8eea7373134f756a2fd73e9456bb7d1a X-KSE-AntiSpam-Info: {Tracking_uf_ne_domains} X-KSE-AntiSpam-Info: {Tracking_from_domain_doesnt_match_to} X-KSE-AntiSpam-Info: d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;r.smirnovsmtp.omp.ru:7.1.1;lkml.kernel.org:7.1.1;127.0.0.199:7.1.2;omp.ru:7.1.1 X-KSE-AntiSpam-Info: FromAlignment: s X-KSE-AntiSpam-Info: Rate: 0 X-KSE-AntiSpam-Info: Status: not_detected X-KSE-AntiSpam-Info: Method: none X-KSE-AntiSpam-Info: Auth:dkim=none X-KSE-Antiphishing-Info: Clean X-KSE-Antiphishing-ScanningType: Heuristic X-KSE-Antiphishing-Method: None X-KSE-Antiphishing-Bases: 02/08/2024 14:32:00 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 2/8/2024 12:48:00 PM X-KSE-Attachment-Filter-Triggered-Rules: Clean X-KSE-Attachment-Filter-Triggered-Filters: Clean X-KSE-BulkMessagesFiltering-Scan-Result: InTheLimit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790342226848412214 X-GMAIL-MSGID: 1790342226848412214 From: Ryusuke Konishi commit 5124a0a549857c4b87173280e192eea24dea72ad upstream. If DAT metadata file block access fails due to corruption of the DAT file or abnormal virtual block numbers held by b-trees or inodes, a kernel warning is generated. This replaces the WARN_ONs by error output, so that a kernel, booted with panic_on_warn, does not panic. This patch also replaces the detected return code -ENOENT with another internal code -EINVAL to notify the bmap layer of metadata corruption. When the bmap layer sees -EINVAL, it handles the abnormal situation with nilfs_bmap_convert_error() and finally returns code -EIO as it should. Link: https://lkml.kernel.org/r/0000000000005cc3d205ea23ddcf@google.com Link: https://lkml.kernel.org/r/20230126164114.6911-1-konishi.ryusuke@gmail.com Signed-off-by: Ryusuke Konishi Reported-by: Tested-by: Ryusuke Konishi Signed-off-by: Andrew Morton Signed-off-by: Roman Smirnov --- fs/nilfs2/dat.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/fs/nilfs2/dat.c b/fs/nilfs2/dat.c index 9930fa901039..1e7f653c1df7 100644 --- a/fs/nilfs2/dat.c +++ b/fs/nilfs2/dat.c @@ -40,8 +40,21 @@ static inline struct nilfs_dat_info *NILFS_DAT_I(struct inode *dat) static int nilfs_dat_prepare_entry(struct inode *dat, struct nilfs_palloc_req *req, int create) { - return nilfs_palloc_get_entry_block(dat, req->pr_entry_nr, - create, &req->pr_entry_bh); + int ret; + + ret = nilfs_palloc_get_entry_block(dat, req->pr_entry_nr, + create, &req->pr_entry_bh); + if (unlikely(ret == -ENOENT)) { + nilfs_err(dat->i_sb, + "DAT doesn't have a block to manage vblocknr = %llu", + (unsigned long long)req->pr_entry_nr); + /* + * Return internal code -EINVAL to notify bmap layer of + * metadata corruption. + */ + ret = -EINVAL; + } + return ret; } static void nilfs_dat_commit_entry(struct inode *dat, @@ -123,11 +136,7 @@ static void nilfs_dat_commit_free(struct inode *dat, int nilfs_dat_prepare_start(struct inode *dat, struct nilfs_palloc_req *req) { - int ret; - - ret = nilfs_dat_prepare_entry(dat, req, 0); - WARN_ON(ret == -ENOENT); - return ret; + return nilfs_dat_prepare_entry(dat, req, 0); } void nilfs_dat_commit_start(struct inode *dat, struct nilfs_palloc_req *req, @@ -154,10 +163,8 @@ int nilfs_dat_prepare_end(struct inode *dat, struct nilfs_palloc_req *req) int ret; ret = nilfs_dat_prepare_entry(dat, req, 0); - if (ret < 0) { - WARN_ON(ret == -ENOENT); + if (ret < 0) return ret; - } kaddr = kmap_atomic(req->pr_entry_bh->b_page); entry = nilfs_palloc_block_get_entry(dat, req->pr_entry_nr,