Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp2245786ybd; Mon, 24 Jun 2019 03:13:40 -0700 (PDT) X-Google-Smtp-Source: APXvYqzlgLCpZclaiihDOeKbfbuIUmavOLW35rrWgaNcKzEEiZb576kHm7/K8K/dTs6166JvwBl9 X-Received: by 2002:a17:90a:3463:: with SMTP id o90mr24444945pjb.15.1561371220371; Mon, 24 Jun 2019 03:13:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561371220; cv=none; d=google.com; s=arc-20160816; b=XduRgObeepstdBMBgXz50F66rFJMzQcDMib96wFhk1J55dFfQpkTwWGUy6BT5v7koX h8TpvPuvemEgXSviz7stv/LCrP5czBs4VMFihU0LWc9ydv4OKzVDQ5mNp4T+6/BWn9ow sYgmzwZVTAfuAjlwOnM77LDOHxwY8G6OuO0AGVPBvSfp2DoIGEVTlaFN1XGeCUUMeH/w f3t3F42OH+4md3b7JgnH4NLpWszW0G3jrAad7DHlPZP5Pae6LF0rj/3+KE5QretdJNFP aWbMzgtOBRF4sqm4OdY1+rk26Y33xesxqNyd6gBYWKm/7HNDXCLFss1Qj03f8RjvkDeq 2TNA== 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=eIc4T+go6gNRXieS9BtggZ4d018rCNtSK1TJKBnvNIY=; b=LKpRD1ngl6zbuCOdRmZn2/pHQwgx9Zo+LVVnFaiD8cz3UhO1RfcbTNTSYK6L2dPcu3 YLHdVDA0AkjoLkz0DniwEiqG3xqnZVf0RwDsyzaYDXTcXpZAjTxVgi27jfwtCg9wDW6v 65C9QdtP5sbgm13jpTXQJRHa0eieslxhhvt7AWo0arOmZeHqxQqYmyK3ekMK689B8Ccz DQIPBYeisSUlJ8HwceEYbcCK16xnChte+r241zmb0pxO6psYTJ/LzIsQnc5CnhhK+XKk UQMSvkU/0bXfs5neU3E7K/vrwoAu/uu1VybgdsheF+jOeRy3PRiM1AntszB6aIrmM6zu K4og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jmp27kTv; 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 59si10648089plp.90.2019.06.24.03.13.24; Mon, 24 Jun 2019 03:13:40 -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=jmp27kTv; 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 S1730025AbfFXKGE (ORCPT + 99 others); Mon, 24 Jun 2019 06:06:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:38112 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729403AbfFXKGB (ORCPT ); Mon, 24 Jun 2019 06:06: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 0370C212F5; Mon, 24 Jun 2019 10:05:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561370760; bh=OQps3H3ljcKHdkYTP3akozmibnMzVqfCH4EZLVabmbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jmp27kTv1RlcRhxf7Q/JdqryTPQ0mk+j6T95yWfBS0S7Glv6wFt/Y4VxL80n83y8F NFg5heK8Nw0vHHKrYHRQotG8QG0b4O5rBFp4JkHUig/jLp7UT/4Cvb1ySJbD+A93lF DXUXxNrXCBYKd76y4JmQ8DzCwOdgn0BtGPEzNPg8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Gao Xiang Subject: [PATCH 4.19 80/90] staging: erofs: add requirements field in superblock Date: Mon, 24 Jun 2019 17:57:10 +0800 Message-Id: <20190624092319.173827456@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092313.788773607@linuxfoundation.org> References: <20190624092313.788773607@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 */ #define __EROFS_BIT(_prefix, _cur, _pre) enum { \ _prefix ## _cur ## _BIT = _prefix ## _pre ## _BIT + \ --- a/drivers/staging/erofs/internal.h +++ b/drivers/staging/erofs/internal.h @@ -111,6 +111,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 @@ -75,6 +75,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; @@ -108,6 +124,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