Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2254278ybd; Mon, 24 Jun 2019 03:22:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqyZ2z2l1brSxH3THQ1Vto2J8Cqjklg+agMfpP/ZtGy9vBgDDl8jLohSrDnU7Ts1OTgVnogl X-Received: by 2002:a17:902:76c3:: with SMTP id j3mr118567131plt.116.1561371765962; Mon, 24 Jun 2019 03:22:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561371765; cv=none; d=google.com; s=arc-20160816; b=q8qkk6p7QZHivFCp6HUUItA5QoptBA+24yd2K5FEuujzrzWJRHvjUbB5RIYIx4FiDO sVI7j/G9QpaekOkqZJ/BI3lfYBpSSFjKWSozWiRIa4DKJU82oP0Hbcx/GM0mP8/+WiTL ukx+SStS70B9VF/4M0W6j4noyaIuNHIwF6VZrhd1DV/z1sDupprdc4vmtwmrFnfXrPXa NK7l0z47EtW2YHMcbu8WPgAkplnYDYDqBMnX49DP0M5NgtJSq0KSmUAdQF2WRsGoh4ec YThoXoc25K2vFDCquuGk0r3wopEqlQd7dTP8GpQ6IrkSmyuHnKIlpv9YMAILLhnXBmJN yn/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4l7Ch/xnz82tJUl985EHcyOIh8AEc7bPrPhVN811Uxw=; b=bWh8SYbWt+yrNdyJ+VGdbdUFLVeqyc9YthLcSHIuTlaWbKOlut61I3u/e6C8UfT5jP bcej0iYDamPog6DN5bGKIn+ztI+ts6oFB8Yl72GYJRjMjiFa7FEQy5sxs7Ry0SH9xywo Q7U/T08OAMJJLcohy4D8RcmKTBoTV0EqjzrijkEQhpssK5RQyzeqENIIKqyVFzGK2TVq bUxmEG/LjVTDzdNyBJ2QjF4j3/HvkAN8sqsR7uV1rB1fBFr9FVB41yqRuOyaIHTN+YaV nPgSIObpjNbDbRBeV5xUiOm2tsGQFour5op19VVhcxwL2ABdbKJIXbfdcKKONz1U3mrX KgVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wKksxoCH; 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 g9si9777184plq.376.2019.06.24.03.22.30; Mon, 24 Jun 2019 03:22:45 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=wKksxoCH; 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 S1731028AbfFXKWD (ORCPT + 99 others); Mon, 24 Jun 2019 06:22:03 -0400 Received: from mail.kernel.org ([198.145.29.99]:57816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730962AbfFXKWB (ORCPT ); Mon, 24 Jun 2019 06:22:01 -0400 Received: from localhost (f4.8f.5177.ip4.static.sl-reverse.com [119.81.143.244]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 48A402133F; Mon, 24 Jun 2019 10:22:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561371720; bh=7xLo/8ltZ3m/6HmFyEdmADw8EBYFNc6hwS8LWzSxUoM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wKksxoCHKqS3quE57fHz+/3tc0XdtBjeKjK12a9hWSOKYGh10SA7wgWGgfHvjM4Ef dagLJ5YAXSFRESeBKx1amFCKIR9vDAtzS34v0P9h0hP3/PhcBbvzXqRVotXbDaWnio Q/uQVHZ/bunSvRJri2A3045GsjnoTEFIRuQa088I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Gao Xiang Subject: [PATCH 5.1 109/121] staging: erofs: add requirements field in superblock Date: Mon, 24 Jun 2019 17:57:21 +0800 Message-Id: <20190624092326.255534512@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092320.652599624@linuxfoundation.org> References: <20190624092320.652599624@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gao Xiang commit 5efe5137f05bbb4688890620934538c005e7d1d6 upstream. There are some backward incompatible features pending for months, mainly due to on-disk format expensions. However, we should ensure that it cannot be mounted with old kernels. Otherwise, it will causes unexpected behaviors. Fixes: ba2b77a82022 ("staging: erofs: add super block operations") Cc: # 4.19+ Reviewed-by: Chao Yu Signed-off-by: Gao Xiang Signed-off-by: Greg Kroah-Hartman --- drivers/staging/erofs/erofs_fs.h | 13 ++++++++++--- drivers/staging/erofs/internal.h | 2 ++ drivers/staging/erofs/super.c | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) --- a/drivers/staging/erofs/erofs_fs.h +++ b/drivers/staging/erofs/erofs_fs.h @@ -17,10 +17,16 @@ #define EROFS_SUPER_MAGIC_V1 0xE0F5E1E2 #define EROFS_SUPER_OFFSET 1024 +/* + * Any bits that aren't in EROFS_ALL_REQUIREMENTS should be + * incompatible with this kernel version. + */ +#define EROFS_ALL_REQUIREMENTS 0 + struct erofs_super_block { /* 0 */__le32 magic; /* in the little endian */ /* 4 */__le32 checksum; /* crc32c(super_block) */ -/* 8 */__le32 features; +/* 8 */__le32 features; /* (aka. feature_compat) */ /* 12 */__u8 blkszbits; /* support block_size == PAGE_SIZE only */ /* 13 */__u8 reserved; @@ -34,9 +40,10 @@ struct erofs_super_block { /* 44 */__le32 xattr_blkaddr; /* 48 */__u8 uuid[16]; /* 128-bit uuid for volume */ /* 64 */__u8 volume_name[16]; /* volume name */ +/* 80 */__le32 requirements; /* (aka. feature_incompat) */ -/* 80 */__u8 reserved2[48]; /* 128 bytes */ -} __packed; +/* 84 */__u8 reserved2[44]; +} __packed; /* 128 bytes */ /* * erofs inode data mapping: --- a/drivers/staging/erofs/internal.h +++ b/drivers/staging/erofs/internal.h @@ -114,6 +114,8 @@ struct erofs_sb_info { u8 uuid[16]; /* 128-bit uuid for volume */ u8 volume_name[16]; /* volume name */ + u32 requirements; + char *dev_name; unsigned int mount_opt; --- a/drivers/staging/erofs/super.c +++ b/drivers/staging/erofs/super.c @@ -76,6 +76,22 @@ static void destroy_inode(struct inode * call_rcu(&inode->i_rcu, i_callback); } +static bool check_layout_compatibility(struct super_block *sb, + struct erofs_super_block *layout) +{ + const unsigned int requirements = le32_to_cpu(layout->requirements); + + EROFS_SB(sb)->requirements = requirements; + + /* check if current kernel meets all mandatory requirements */ + if (requirements & (~EROFS_ALL_REQUIREMENTS)) { + errln("unidentified requirements %x, please upgrade kernel version", + requirements & ~EROFS_ALL_REQUIREMENTS); + return false; + } + return true; +} + static int superblock_read(struct super_block *sb) { struct erofs_sb_info *sbi; @@ -109,6 +125,9 @@ static int superblock_read(struct super_ goto out; } + if (!check_layout_compatibility(sb, layout)) + goto out; + sbi->blocks = le32_to_cpu(layout->blocks); sbi->meta_blkaddr = le32_to_cpu(layout->meta_blkaddr); #ifdef CONFIG_EROFS_FS_XATTR