From patchwork Tue Jun 12 09:53:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 928250 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 414myg4R9fz9s1B for ; Tue, 12 Jun 2018 20:56:11 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933443AbeFLK4K (ORCPT ); Tue, 12 Jun 2018 06:56:10 -0400 Received: from mx2.suse.de ([195.135.220.15]:40147 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933408AbeFLK4J (ORCPT ); Tue, 12 Jun 2018 06:56:09 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1DC28AEA4; Tue, 12 Jun 2018 10:56:06 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 290521E0516; Tue, 12 Jun 2018 11:53:35 +0200 (CEST) From: Jan Kara To: Cc: Ted Tso , Jan Kara Subject: [PATCH 01/10] libext2fs: Fix possible inode count overflow when creating fs Date: Tue, 12 Jun 2018 11:53:19 +0200 Message-Id: <20180612095328.5215-2-jack@suse.cz> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180612095328.5215-1-jack@suse.cz> References: <20180612095328.5215-1-jack@suse.cz> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org If blocks count is exactly 1<<32, then the code computing number of inode count in ext2fs_initialize() will overflow and set number of inodes to 0 (which will be later fixed up to EXT2_FIRST_INODE(super)+1). Fix the off-by-one bug in the check. Reviewed-by: Andreas Dilger Signed-off-by: Jan Kara --- lib/ext2fs/initialize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index dbe798b27826..e1eff22eac33 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -295,7 +295,7 @@ retry: i = fs->blocksize >= 4096 ? 1 : 4096 / fs->blocksize; if (ext2fs_has_feature_64bit(super) && - (ext2fs_blocks_count(super) / i) > (1ULL << 32)) + (ext2fs_blocks_count(super) / i) >= (1ULL << 32)) set_field(s_inodes_count, ~0U); else set_field(s_inodes_count, ext2fs_blocks_count(super) / i); From patchwork Tue Jun 12 09:53:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 928258 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 414mys3Kmtz9s1B for ; Tue, 12 Jun 2018 20:56:21 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933467AbeFLK4T (ORCPT ); Tue, 12 Jun 2018 06:56:19 -0400 Received: from mx2.suse.de ([195.135.220.15]:40145 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933397AbeFLK4I (ORCPT ); Tue, 12 Jun 2018 06:56:08 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 1DB91AE5E; Tue, 12 Jun 2018 10:56:06 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 2AE831E0D64; Tue, 12 Jun 2018 11:53:35 +0200 (CEST) From: Jan Kara To: Cc: Ted Tso , Jan Kara Subject: [PATCH 02/10] ext2fs: Fix overflow when checking s_inodes_count in ext2fs_open() Date: Tue, 12 Jun 2018 11:53:20 +0200 Message-Id: <20180612095328.5215-3-jack@suse.cz> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180612095328.5215-1-jack@suse.cz> References: <20180612095328.5215-1-jack@suse.cz> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org The check whether s_inodes_count is correct in ext2fs_open() can overflow and thus not catch all problematic cases. Fix the test. Reviewed-by: Andreas Dilger Signed-off-by: Jan Kara --- lib/ext2fs/openfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index 532e70f7f645..e9ad0cd1a2c6 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -386,7 +386,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, goto cleanup; } fs->group_desc_count = groups_cnt; - if (fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) != + if ((__u64)fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) != fs->super->s_inodes_count) { retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; From patchwork Tue Jun 12 09:53:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 928251 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 414myh3vShz9s1b for ; Tue, 12 Jun 2018 20:56:12 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933448AbeFLK4L (ORCPT ); Tue, 12 Jun 2018 06:56:11 -0400 Received: from mx2.suse.de ([195.135.220.15]:40150 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933367AbeFLK4J (ORCPT ); Tue, 12 Jun 2018 06:56:09 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 35EE5AED2; Tue, 12 Jun 2018 10:56:06 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 2FAF61E113D; Tue, 12 Jun 2018 11:53:35 +0200 (CEST) From: Jan Kara To: Cc: Ted Tso , Jan Kara Subject: [PATCH 03/10] resize2fs: Add missing EOL to error message Date: Tue, 12 Jun 2018 11:53:21 +0200 Message-Id: <20180612095328.5215-4-jack@suse.cz> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180612095328.5215-1-jack@suse.cz> References: <20180612095328.5215-1-jack@suse.cz> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Reviewed-by: Andreas Dilger Signed-off-by: Jan Kara --- resize/resize2fs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resize/resize2fs.c b/resize/resize2fs.c index 0bd325bae81d..7afc1342bc88 100644 --- a/resize/resize2fs.c +++ b/resize/resize2fs.c @@ -756,7 +756,7 @@ retry: */ new_inodes =(unsigned long long) fs->super->s_inodes_per_group * fs->group_desc_count; if (new_inodes > ~0U) { - fprintf(stderr, _("inodes (%llu) must be less than %u"), + fprintf(stderr, _("inodes (%llu) must be less than %u\n"), new_inodes, ~0U); return EXT2_ET_TOO_MANY_INODES; } From patchwork Tue Jun 12 09:53:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 928254 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 414mym61Wsz9s1b for ; Tue, 12 Jun 2018 20:56:16 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933437AbeFLK4J (ORCPT ); Tue, 12 Jun 2018 06:56:09 -0400 Received: from mx2.suse.de ([195.135.220.15]:40092 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932286AbeFLK4H (ORCPT ); Tue, 12 Jun 2018 06:56:07 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E80FAADE3; Tue, 12 Jun 2018 10:56:05 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 328351E0FC4; Tue, 12 Jun 2018 11:53:35 +0200 (CEST) From: Jan Kara To: Cc: Ted Tso , Jan Kara Subject: [PATCH 04/10] ext2fs: Don't create filesystems with meta_bg and resize_inode Date: Tue, 12 Jun 2018 11:53:22 +0200 Message-Id: <20180612095328.5215-5-jack@suse.cz> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180612095328.5215-1-jack@suse.cz> References: <20180612095328.5215-1-jack@suse.cz> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org ext2fs_initialize() may end up enabling meta_bg feature for filesystem which have resize_inode. Such combination is invalid to make sure we disable resize_inode when enabling meta_bg. Reviewed-by: Andreas Dilger Signed-off-by: Jan Kara --- lib/ext2fs/initialize.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index e1eff22eac33..8c9e97fee831 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -382,6 +382,13 @@ ipg_retry: retval = EXT2_ET_RES_GDT_BLOCKS; goto cleanup; } + /* Enable meta_bg if we'd lose more than 3/4 of a BG to GDT blocks. */ + if (super->s_reserved_gdt_blocks + fs->desc_blocks > + super->s_blocks_per_group * 3 / 4) { + ext2fs_set_feature_meta_bg(fs->super); + ext2fs_clear_feature_resize_inode(fs->super); + set_field(s_reserved_gdt_blocks, 0); + } /* * Calculate the maximum number of bookkeeping blocks per @@ -392,11 +399,6 @@ ipg_retry: overhead = (int) (3 + fs->inode_blocks_per_group + super->s_reserved_gdt_blocks); - /* Enable meta_bg if we'd lose more than 3/4 of a BG to GDT blocks. */ - if (super->s_reserved_gdt_blocks + fs->desc_blocks > - super->s_blocks_per_group * 3 / 4) - ext2fs_set_feature_meta_bg(fs->super); - if (ext2fs_has_feature_meta_bg(fs->super)) overhead++; else From patchwork Tue Jun 12 09:53:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 928257 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 414myr53F3z9s1b for ; Tue, 12 Jun 2018 20:56:20 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933464AbeFLK4S (ORCPT ); Tue, 12 Jun 2018 06:56:18 -0400 Received: from mx2.suse.de ([195.135.220.15]:40144 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933403AbeFLK4I (ORCPT ); Tue, 12 Jun 2018 06:56:08 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 14B0AAE20; Tue, 12 Jun 2018 10:56:06 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 34ABF1E11C2; Tue, 12 Jun 2018 11:53:35 +0200 (CEST) From: Jan Kara To: Cc: Ted Tso , Jan Kara Subject: [PATCH 05/10] e2fsck: Allow to fix some superblock corruptions Date: Tue, 12 Jun 2018 11:53:23 +0200 Message-Id: <20180612095328.5215-6-jack@suse.cz> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180612095328.5215-1-jack@suse.cz> References: <20180612095328.5215-1-jack@suse.cz> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Add a flag to ext2fs_open() which allows to open a filesystem even if superblock is somewhat inconsistent. Use this flag from e2fsck as a last resort to try to fix the superblok. Currently, the flag does nothing. We'll relax checks in ext2fs_open() once e2fsck is able to handle corresponding corruption gracefully. Reviewed-by: Andreas Dilger Signed-off-by: Jan Kara --- e2fsck/unix.c | 22 +++++++++++++++++++++- lib/ext2fs/ext2fs.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/e2fsck/unix.c b/e2fsck/unix.c index cbe5ec5034cb..55e21ea0aeac 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -1364,7 +1364,7 @@ int main (int argc, char *argv[]) const char *lib_ver_date; int my_ver, lib_ver; e2fsck_t ctx; - blk64_t orig_superblock; + blk64_t orig_superblock = ~(blk64_t)0; struct problem_context pctx; int flags, run_result, was_changed; int journal_size; @@ -1571,6 +1571,26 @@ failure: "check of the device.\n")); #endif else { + /* + * Let's try once more will less consistency checking + * so that we are able to recover from more errors + * (e.g. some tool messing up some value in the sb). + */ + if (!(flags & EXT2_FLAG_IGNORE_SB_ERRORS)) { + if (fs) + ext2fs_close_free(&fs); + log_out(ctx, _("%s: Trying to load superblock " + "despite errors...\n"), + ctx->program_name); + flags |= EXT2_FLAG_IGNORE_SB_ERRORS; + /* + * If we tried backup sb, revert to the + * original one now. + */ + if (orig_superblock != ~(blk64_t)0) + ctx->superblock = orig_superblock; + goto restart; + } fix_problem(ctx, PR_0_SB_CORRUPT, &pctx); if (retval == EXT2_ET_BAD_MAGIC) check_plausibility(ctx->filesystem_name, diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 6774e32c91c2..250fd174cd48 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -195,6 +195,7 @@ typedef struct ext2_file *ext2_file_t; #define EXT2_FLAG_DIRECT_IO 0x80000 #define EXT2_FLAG_SKIP_MMP 0x100000 #define EXT2_FLAG_IGNORE_CSUM_ERRORS 0x200000 +#define EXT2_FLAG_IGNORE_SB_ERRORS 0x400000 /* * Special flag in the ext2 inode i_flag field that means that this is From patchwork Tue Jun 12 09:53:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 928259 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 414myw0s5yz9s1B for ; Tue, 12 Jun 2018 20:56:24 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933472AbeFLK4W (ORCPT ); Tue, 12 Jun 2018 06:56:22 -0400 Received: from mx2.suse.de ([195.135.220.15]:40116 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752705AbeFLK4H (ORCPT ); Tue, 12 Jun 2018 06:56:07 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 152A7AE3A; Tue, 12 Jun 2018 10:56:06 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 36D171E11D1; Tue, 12 Jun 2018 11:53:35 +0200 (CEST) From: Jan Kara To: Cc: Ted Tso , Jan Kara Subject: [PATCH 06/10] e2fsck: Handle s_inodes_count corruption properly Date: Tue, 12 Jun 2018 11:53:24 +0200 Message-Id: <20180612095328.5215-7-jack@suse.cz> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180612095328.5215-1-jack@suse.cz> References: <20180612095328.5215-1-jack@suse.cz> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org When s_inodes_count would overflow given number of groups and inodes per group, we cannot currently fix the breakage in e2fsck as that requires trimming number of groups or inodes per group which both means data & inode migration etc. Just trimming sb->s_inodes_count is not enough as kernel's inode allocation code is not able to handle filesystems where not all inodes in the last group are usable. So don't pretend we can fix s_inodes_count overflow by just trimming the s_inodes_count value. When s_inodes_count is just wrong but will not overflow, let's fix it. Also move this check before we use s_inodes_count for checking s_first_ino. Signed-off-by: Jan Kara --- e2fsck/problem.c | 5 +++++ e2fsck/problem.h | 2 ++ e2fsck/super.c | 27 ++++++++++++++++----------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/e2fsck/problem.c b/e2fsck/problem.c index edc9d51fcf31..8de558edc5dd 100644 --- a/e2fsck/problem.c +++ b/e2fsck/problem.c @@ -184,6 +184,11 @@ static struct e2fsck_problem problem_table[] = { N_("@i count in @S is %i, @s %j.\n"), PROMPT_FIX, 0 }, + /* Too many inodes in the filesystem */ + { PR_0_INODE_COUNT_BIG, + N_("@S would have too many inodes (%N).\n"), + PROMPT_NONE, PR_AFTER_CODE, PR_0_SB_CORRUPT }, + { PR_0_HURD_CLEAR_FILETYPE, N_("The Hurd does not support the filetype feature.\n"), PROMPT_CLEAR, 0 }, diff --git a/e2fsck/problem.h b/e2fsck/problem.h index 482d111a0f2c..b6bca668bb1b 100644 --- a/e2fsck/problem.h +++ b/e2fsck/problem.h @@ -282,6 +282,8 @@ struct problem_context { /* Invalid quota inode number */ #define PR_0_INVALID_QUOTA_INO 0x00004F +/* Inode count in the superblock incorrect */ +#define PR_0_INODE_COUNT_BIG 0x000050 /* * Pass 1 errors diff --git a/e2fsck/super.c b/e2fsck/super.c index 9c0e0e7b35b4..60a19a7e2767 100644 --- a/e2fsck/super.c +++ b/e2fsck/super.c @@ -646,6 +646,22 @@ void check_super_block(e2fsck_t ctx) check_super_value(ctx, "desc_size", sb->s_desc_size, MAX_CHECK | LOG2_CHECK, 0, EXT2_MAX_DESC_SIZE); + + should_be = (__u64)sb->s_inodes_per_group * fs->group_desc_count; + if (should_be > ~0U) { + pctx.num = should_be; + fix_problem(ctx, PR_0_INODE_COUNT_BIG, &pctx); + ctx->flags |= E2F_FLAG_ABORT; + return; + } + if (sb->s_inodes_count != should_be) { + pctx.ino = sb->s_inodes_count; + pctx.ino2 = should_be; + if (fix_problem(ctx, PR_0_INODE_COUNT_WRONG, &pctx)) { + sb->s_inodes_count = should_be; + ext2fs_mark_super_dirty(fs); + } + } if (sb->s_rev_level > EXT2_GOOD_OLD_REV) check_super_value(ctx, "first_ino", sb->s_first_ino, MIN_CHECK | MAX_CHECK, @@ -683,17 +699,6 @@ void check_super_block(e2fsck_t ctx) return; } - should_be = (blk64_t)sb->s_inodes_per_group * fs->group_desc_count; - if (should_be > UINT_MAX) - should_be = UINT_MAX; - if (sb->s_inodes_count != should_be) { - pctx.ino = sb->s_inodes_count; - pctx.ino2 = should_be; - if (fix_problem(ctx, PR_0_INODE_COUNT_WRONG, &pctx)) { - sb->s_inodes_count = should_be; - ext2fs_mark_super_dirty(fs); - } - } if (EXT2_INODE_SIZE(sb) > EXT2_GOOD_OLD_INODE_SIZE) { unsigned min = sizeof(((struct ext2_inode_large *) 0)->i_extra_isize) + From patchwork Tue Jun 12 09:53:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 928256 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 414myq2n0xz9s1B for ; Tue, 12 Jun 2018 20:56:19 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933421AbeFLK4I (ORCPT ); Tue, 12 Jun 2018 06:56:08 -0400 Received: from mx2.suse.de ([195.135.220.15]:40090 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933367AbeFLK4H (ORCPT ); Tue, 12 Jun 2018 06:56:07 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E7FE6ADBD; Tue, 12 Jun 2018 10:56:05 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 3A0451E11DA; Tue, 12 Jun 2018 11:53:35 +0200 (CEST) From: Jan Kara To: Cc: Ted Tso , Jan Kara Subject: [PATCH 07/10] debugfs: Allow read-write opening in catastrophic mode Date: Tue, 12 Jun 2018 11:53:25 +0200 Message-Id: <20180612095328.5215-8-jack@suse.cz> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180612095328.5215-1-jack@suse.cz> References: <20180612095328.5215-1-jack@suse.cz> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Allow filesystem to be open read-write in catastrophic mode so that one can fixup e.g. superblock breakage. The CHECK_FS_BITMAPS flag to common_args_process() still guards us from doing operations on bitmaps which we don't load in this mode. Signed-off-by: Jan Kara --- debugfs/debugfs.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index 905c8cdc6733..b1842443aa8e 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -159,11 +159,6 @@ static void open_filesystem(char *device, int open_flags, blk64_t superblock, } } - if (catastrophic && (open_flags & EXT2_FLAG_RW)) { - com_err(device, 0, - "opening read-only because of catastrophic mode"); - open_flags &= ~EXT2_FLAG_RW; - } if (catastrophic) open_flags |= EXT2_FLAG_SKIP_MMP; From patchwork Tue Jun 12 09:53:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 928253 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 414myk4zhNz9s1b for ; Tue, 12 Jun 2018 20:56:14 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933452AbeFLK4M (ORCPT ); Tue, 12 Jun 2018 06:56:12 -0400 Received: from mx2.suse.de ([195.135.220.15]:40146 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933417AbeFLK4J (ORCPT ); Tue, 12 Jun 2018 06:56:09 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 23A5BAEB6; Tue, 12 Jun 2018 10:56:06 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 3BC081E115F; Tue, 12 Jun 2018 11:53:35 +0200 (CEST) From: Jan Kara To: Cc: Ted Tso , Jan Kara Subject: [PATCH 08/10] debugfs: Allow fixing superblock errors in catastrophic mode Date: Tue, 12 Jun 2018 11:53:26 +0200 Message-Id: <20180612095328.5215-9-jack@suse.cz> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180612095328.5215-1-jack@suse.cz> References: <20180612095328.5215-1-jack@suse.cz> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Open filesystem with EXT2_FLAG_IGNORE_SB_ERRORS flag in catastrophic mode so that superblock errors can be fixed in debugfs. Reviewed-by: Andreas Dilger Signed-off-by: Jan Kara --- debugfs/debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index b1842443aa8e..51e3783bfa86 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -160,7 +160,7 @@ static void open_filesystem(char *device, int open_flags, blk64_t superblock, } if (catastrophic) - open_flags |= EXT2_FLAG_SKIP_MMP; + open_flags |= EXT2_FLAG_SKIP_MMP | EXT2_FLAG_IGNORE_SB_ERRORS; if (undo_file) { retval = debugfs_setup_tdb(device, undo_file, &io_ptr); From patchwork Tue Jun 12 09:53:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 928255 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 414myp0Q8nz9s1B for ; Tue, 12 Jun 2018 20:56:18 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933429AbeFLK4J (ORCPT ); Tue, 12 Jun 2018 06:56:09 -0400 Received: from mx2.suse.de ([195.135.220.15]:40093 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933350AbeFLK4H (ORCPT ); Tue, 12 Jun 2018 06:56:07 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E6139AB37; Tue, 12 Jun 2018 10:56:05 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 406441E11E3; Tue, 12 Jun 2018 11:53:35 +0200 (CEST) From: Jan Kara To: Cc: Ted Tso , Jan Kara Subject: [PATCH 09/10] ext2fs: Don't check s_inodes_count with EXT2_FLAG_IGNORE_SB_ERRORS Date: Tue, 12 Jun 2018 11:53:27 +0200 Message-Id: <20180612095328.5215-10-jack@suse.cz> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180612095328.5215-1-jack@suse.cz> References: <20180612095328.5215-1-jack@suse.cz> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Don't verify s_inodes_count is correct with EXT2_FLAG_IGNORE_SB_ERRORS flag set. This allows e2fsck and debugfs to fix this value. Reviewed-by: Andreas Dilger Signed-off-by: Jan Kara --- lib/ext2fs/openfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index e9ad0cd1a2c6..d046b2517505 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -386,7 +386,8 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, goto cleanup; } fs->group_desc_count = groups_cnt; - if ((__u64)fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) != + if (!(flags & EXT2_FLAG_IGNORE_SB_ERRORS) && + (__u64)fs->group_desc_count * EXT2_INODES_PER_GROUP(fs->super) != fs->super->s_inodes_count) { retval = EXT2_ET_CORRUPT_SUPERBLOCK; goto cleanup; From patchwork Tue Jun 12 09:53:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kara X-Patchwork-Id: 928260 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 414myx2NsHz9s1B for ; Tue, 12 Jun 2018 20:56:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933469AbeFLK4V (ORCPT ); Tue, 12 Jun 2018 06:56:21 -0400 Received: from mx2.suse.de ([195.135.220.15]:40091 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933394AbeFLK4H (ORCPT ); Tue, 12 Jun 2018 06:56:07 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext-too.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id E89FDAE0C; Tue, 12 Jun 2018 10:56:05 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 42A0B1E11E9; Tue, 12 Jun 2018 11:53:35 +0200 (CEST) From: Jan Kara To: Cc: Ted Tso , Jan Kara Subject: [PATCH 10/10] e2fsck: Report only one sb corruption Date: Tue, 12 Jun 2018 11:53:28 +0200 Message-Id: <20180612095328.5215-11-jack@suse.cz> X-Mailer: git-send-email 2.13.7 In-Reply-To: <20180612095328.5215-1-jack@suse.cz> References: <20180612095328.5215-1-jack@suse.cz> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org check_super_value() does not terminate in case of error anymore since c8b20b40ebf0 "misc: add plausibility checks to debugfs/tune2fs/dumpe2fs/e2fsck" which removed the PR_FATAL flag from PR_0_SB_CORRUPT problem. This results in potentially many errors for superblock being printed including the long message about how to deal with corrupted superblock. Restore the original behavior of reporting only one error and also remove the comments 'never get here' as they are not true anymore. Reviewed-by: Andreas Dilger Signed-off-by: Jan Kara --- e2fsck/super.c | 98 ++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 58 insertions(+), 40 deletions(-) diff --git a/e2fsck/super.c b/e2fsck/super.c index 60a19a7e2767..bfd1006697c5 100644 --- a/e2fsck/super.c +++ b/e2fsck/super.c @@ -24,7 +24,7 @@ #define MAX_CHECK 2 #define LOG2_CHECK 4 -static void check_super_value(e2fsck_t ctx, const char *descr, +static int check_super_value(e2fsck_t ctx, const char *descr, unsigned long value, int flags, unsigned long min_val, unsigned long max_val) { @@ -37,11 +37,13 @@ static void check_super_value(e2fsck_t ctx, const char *descr, pctx.num = value; pctx.str = descr; fix_problem(ctx, PR_0_MISC_CORRUPT_SUPER, &pctx); - ctx->flags |= E2F_FLAG_ABORT; /* never get here! */ + ctx->flags |= E2F_FLAG_ABORT; + return 0; } + return 1; } -static void check_super_value64(e2fsck_t ctx, const char *descr, +static int check_super_value64(e2fsck_t ctx, const char *descr, __u64 value, int flags, __u64 min_val, __u64 max_val) { @@ -54,8 +56,10 @@ static void check_super_value64(e2fsck_t ctx, const char *descr, pctx.num = value; pctx.str = descr; fix_problem(ctx, PR_0_MISC_CORRUPT_SUPER, &pctx); - ctx->flags |= E2F_FLAG_ABORT; /* never get here! */ + ctx->flags |= E2F_FLAG_ABORT; + return 0; } + return 1; } /* @@ -618,34 +622,46 @@ void check_super_block(e2fsck_t ctx) /* * Verify the super block constants... */ - check_super_value(ctx, "inodes_count", sb->s_inodes_count, - MIN_CHECK, 1, 0); - check_super_value64(ctx, "blocks_count", ext2fs_blocks_count(sb), - MIN_CHECK | MAX_CHECK, 1, blks_max); - check_super_value(ctx, "first_data_block", sb->s_first_data_block, - MAX_CHECK, 0, ext2fs_blocks_count(sb)); - check_super_value(ctx, "log_block_size", sb->s_log_block_size, - MIN_CHECK | MAX_CHECK, 0, - EXT2_MAX_BLOCK_LOG_SIZE - EXT2_MIN_BLOCK_LOG_SIZE); - check_super_value(ctx, "log_cluster_size", - sb->s_log_cluster_size, - MIN_CHECK | MAX_CHECK, sb->s_log_block_size, - (EXT2_MAX_CLUSTER_LOG_SIZE - - EXT2_MIN_CLUSTER_LOG_SIZE)); - check_super_value(ctx, "clusters_per_group", sb->s_clusters_per_group, - MIN_CHECK | MAX_CHECK, 8, cpg_max); - check_super_value(ctx, "blocks_per_group", sb->s_blocks_per_group, - MIN_CHECK | MAX_CHECK, 8, bpg_max); - check_super_value(ctx, "inodes_per_group", sb->s_inodes_per_group, - MIN_CHECK | MAX_CHECK, inodes_per_block, ipg_max); - check_super_value(ctx, "r_blocks_count", ext2fs_r_blocks_count(sb), - MAX_CHECK, 0, ext2fs_blocks_count(sb) / 2); - check_super_value(ctx, "reserved_gdt_blocks", - sb->s_reserved_gdt_blocks, MAX_CHECK, 0, - fs->blocksize / sizeof(__u32)); - check_super_value(ctx, "desc_size", - sb->s_desc_size, MAX_CHECK | LOG2_CHECK, 0, - EXT2_MAX_DESC_SIZE); + if (!check_super_value(ctx, "inodes_count", sb->s_inodes_count, + MIN_CHECK, 1, 0)) + return; + if (!check_super_value64(ctx, "blocks_count", ext2fs_blocks_count(sb), + MIN_CHECK | MAX_CHECK, 1, blks_max)) + return; + if (!check_super_value(ctx, "first_data_block", sb->s_first_data_block, + MAX_CHECK, 0, ext2fs_blocks_count(sb))) + return; + if (!check_super_value(ctx, "log_block_size", sb->s_log_block_size, + MIN_CHECK | MAX_CHECK, 0, + EXT2_MAX_BLOCK_LOG_SIZE - EXT2_MIN_BLOCK_LOG_SIZE)) + return; + if (!check_super_value(ctx, "log_cluster_size", + sb->s_log_cluster_size, + MIN_CHECK | MAX_CHECK, sb->s_log_block_size, + (EXT2_MAX_CLUSTER_LOG_SIZE - + EXT2_MIN_CLUSTER_LOG_SIZE))) + return; + if (!check_super_value(ctx, "clusters_per_group", + sb->s_clusters_per_group, + MIN_CHECK | MAX_CHECK, 8, cpg_max)) + return; + if (!check_super_value(ctx, "blocks_per_group", sb->s_blocks_per_group, + MIN_CHECK | MAX_CHECK, 8, bpg_max)) + return; + if (!check_super_value(ctx, "inodes_per_group", sb->s_inodes_per_group, + MIN_CHECK | MAX_CHECK, inodes_per_block, ipg_max)) + return; + if (!check_super_value(ctx, "r_blocks_count", ext2fs_r_blocks_count(sb), + MAX_CHECK, 0, ext2fs_blocks_count(sb) / 2)) + return; + if (!check_super_value(ctx, "reserved_gdt_blocks", + sb->s_reserved_gdt_blocks, MAX_CHECK, 0, + fs->blocksize / sizeof(__u32))) + return; + if (!check_super_value(ctx, "desc_size", + sb->s_desc_size, MAX_CHECK | LOG2_CHECK, 0, + EXT2_MAX_DESC_SIZE)) + return; should_be = (__u64)sb->s_inodes_per_group * fs->group_desc_count; if (should_be > ~0U) { @@ -662,20 +678,22 @@ void check_super_block(e2fsck_t ctx) ext2fs_mark_super_dirty(fs); } } - if (sb->s_rev_level > EXT2_GOOD_OLD_REV) - check_super_value(ctx, "first_ino", sb->s_first_ino, - MIN_CHECK | MAX_CHECK, - EXT2_GOOD_OLD_FIRST_INO, sb->s_inodes_count); + if (sb->s_rev_level > EXT2_GOOD_OLD_REV && + !check_super_value(ctx, "first_ino", sb->s_first_ino, + MIN_CHECK | MAX_CHECK, + EXT2_GOOD_OLD_FIRST_INO, sb->s_inodes_count)) + return; inode_size = EXT2_INODE_SIZE(sb); - check_super_value(ctx, "inode_size", - inode_size, MIN_CHECK | MAX_CHECK | LOG2_CHECK, - EXT2_GOOD_OLD_INODE_SIZE, fs->blocksize); + if (!check_super_value(ctx, "inode_size", + inode_size, MIN_CHECK | MAX_CHECK | LOG2_CHECK, + EXT2_GOOD_OLD_INODE_SIZE, fs->blocksize)) + return; if (sb->s_blocks_per_group != (sb->s_clusters_per_group * EXT2FS_CLUSTER_RATIO(fs))) { pctx.num = sb->s_clusters_per_group * EXT2FS_CLUSTER_RATIO(fs); pctx.str = "block_size"; fix_problem(ctx, PR_0_MISC_CORRUPT_SUPER, &pctx); - ctx->flags |= E2F_FLAG_ABORT; /* never get here! */ + ctx->flags |= E2F_FLAG_ABORT; return; }