Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3309406imu; Sun, 11 Nov 2018 12:05:36 -0800 (PST) X-Google-Smtp-Source: AJdET5fQFxWRpud173tZucaY5wFHeKBXDwmr9BtX8ExKy7P0sx6e8+KUK/0uwKA715n6A6FGIyto X-Received: by 2002:a63:588:: with SMTP id 130mr14819262pgf.273.1541966736198; Sun, 11 Nov 2018 12:05:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541966736; cv=none; d=google.com; s=arc-20160816; b=hcqtmrWqat1ps5V3heIHBMHd0LmRNjWF6g4t4dNEhtRJ+0KNkJx99NZDRebn8aStTE cO15f7/yqJrxN/1JnR3j6oAG9phhqqhPn/A5tKGex5Mvq6bRftz+Yo+GqmVIGnhEgk5h qnG0gGgz27AeBh6i44ryNfbMsB2gIlJpNTJw3RV61Vz1ikPaVcAvfOXFGu0wwCNr/2Fu 0AQBi00N33Ii3jsnEZfYXK4J3eA7LKESbBLLOzA7SBCyj+ACK6I3nzKBG9BQAm9oH0kg 3uc5V5EtNfsDsYVtnz2G3FFkcFEz26yO3Vhymdpy1X9JoZ8QLBmRgtFylPXIqS+UMjJ3 ZHmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=KVAH7F4gLFc1okjOurDp5oWgVXLNmPUVQQcZRxrUhqc=; b=AJV2vQ2Dsn95aV82z6wiCPu14rEVJ6HR1QKwlDCXd+6PwHu+t2xl0McxLS105to3bB ItWM0baB4DWEn4tUqP04Sr3eaUf2v/Pq7EA3inxFvOdaw6OleCL70FK2UY1TOHSjhnsp JMX7wd+pOWCa5WXC9zLn8qOv4FOqx+jAQRv+GRtPMR3l4h6ZS2sF3gWFLpFa/Wp8xhUg e1jkCYLiAlqtOBKyK0N1nkpP8TW18ORjtkm/6B0xCGZ1cWcz7Gc0wvFIUjcaEApUnnOz x5NgvZDq5qHEThfG92P4nj+tYK63U7VnVbNYuoZ/kkQaQuX1/Ak75JXbTMoRWwIDJ9MQ 55Ug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s3-v6si8275718pfm.85.2018.11.11.12.05.21; Sun, 11 Nov 2018 12:05:36 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731092AbeKLFxw (ORCPT + 99 others); Mon, 12 Nov 2018 00:53:52 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:51662 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726508AbeKLFxv (ORCPT ); Mon, 12 Nov 2018 00:53:51 -0500 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLvt0-0000l7-Lz; Sun, 11 Nov 2018 19:59:10 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gLvsS-0001Ye-HQ; Sun, 11 Nov 2018 19:58:36 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Theodore Ts'o" Date: Sun, 11 Nov 2018 19:49:05 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 146/366] ext4: add more mount time checks of the superblock In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.61-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Theodore Ts'o commit bfe0a5f47ada40d7984de67e59a7d3390b9b9ecc upstream. The kernel's ext4 mount-time checks were more permissive than e2fsprogs's libext2fs checks when opening a file system. The superblock is considered too insane for debugfs or e2fsck to operate on it, the kernel has no business trying to mount it. This will make file system fuzzing tools work harder, but the failure cases that they find will be more useful and be easier to evaluate. Signed-off-by: Theodore Ts'o Signed-off-by: Ben Hutchings --- fs/ext4/super.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3725,6 +3725,13 @@ static int ext4_fill_super(struct super_ le32_to_cpu(es->s_log_block_size)); goto failed_mount; } + if (le32_to_cpu(es->s_log_cluster_size) > + (EXT4_MAX_CLUSTER_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) { + ext4_msg(sb, KERN_ERR, + "Invalid log cluster size: %u", + le32_to_cpu(es->s_log_cluster_size)); + goto failed_mount; + } if (le16_to_cpu(sbi->s_es->s_reserved_gdt_blocks) > (blocksize / 4)) { ext4_msg(sb, KERN_ERR, @@ -3853,13 +3860,6 @@ static int ext4_fill_super(struct super_ "block size (%d)", clustersize, blocksize); goto failed_mount; } - if (le32_to_cpu(es->s_log_cluster_size) > - (EXT4_MAX_CLUSTER_LOG_SIZE - EXT4_MIN_BLOCK_LOG_SIZE)) { - ext4_msg(sb, KERN_ERR, - "Invalid log cluster size: %u", - le32_to_cpu(es->s_log_cluster_size)); - goto failed_mount; - } sbi->s_cluster_bits = le32_to_cpu(es->s_log_cluster_size) - le32_to_cpu(es->s_log_block_size); sbi->s_clusters_per_group = @@ -3880,10 +3880,10 @@ static int ext4_fill_super(struct super_ } } else { if (clustersize != blocksize) { - ext4_warning(sb, "fragment/cluster size (%d) != " - "block size (%d)", clustersize, - blocksize); - clustersize = blocksize; + ext4_msg(sb, KERN_ERR, + "fragment/cluster size (%d) != " + "block size (%d)", clustersize, blocksize); + goto failed_mount; } if (sbi->s_blocks_per_group > blocksize * 8) { ext4_msg(sb, KERN_ERR, @@ -3937,6 +3937,13 @@ static int ext4_fill_super(struct super_ ext4_blocks_count(es)); goto failed_mount; } + if ((es->s_first_data_block == 0) && (es->s_log_block_size == 0) && + (sbi->s_cluster_ratio == 1)) { + ext4_msg(sb, KERN_WARNING, "bad geometry: first data " + "block is 0 with a 1k block and cluster size"); + goto failed_mount; + } + blocks_count = (ext4_blocks_count(es) - le32_to_cpu(es->s_first_data_block) + EXT4_BLOCKS_PER_GROUP(sb) - 1); @@ -3972,6 +3979,14 @@ static int ext4_fill_super(struct super_ ret = -ENOMEM; goto failed_mount; } + if (((u64)sbi->s_groups_count * sbi->s_inodes_per_group) != + le32_to_cpu(es->s_inodes_count)) { + ext4_msg(sb, KERN_ERR, "inodes count not valid: %u vs %llu", + le32_to_cpu(es->s_inodes_count), + ((u64)sbi->s_groups_count * sbi->s_inodes_per_group)); + ret = -EINVAL; + goto failed_mount; + } if (ext4_proc_root) sbi->s_proc = proc_mkdir(sb->s_id, ext4_proc_root);