From patchwork Wed Aug 17 14:42:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 12946007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99B5BC32771 for ; Wed, 17 Aug 2022 14:43:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237271AbiHQOnm (ORCPT ); Wed, 17 Aug 2022 10:43:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240280AbiHQOne (ORCPT ); Wed, 17 Aug 2022 10:43:34 -0400 Received: from box.fidei.email (box.fidei.email [71.19.144.250]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2DF04DF01 for ; Wed, 17 Aug 2022 07:43:30 -0700 (PDT) Received: from authenticated-user (box.fidei.email [71.19.144.250]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by box.fidei.email (Postfix) with ESMTPSA id 0928D80A9D; Wed, 17 Aug 2022 10:43:29 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1660747410; bh=3Mx2jbxtrJmSQnucNP5szJZ0hAuj3ehmiON8uBJKck4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bq8YIkJVr8K72Tj7KJhO4cdIaL0+pVNJiOZOIOIxxUklsxi86LwLmRxO8bvzfHAZs aTmT+g3mqbMvvwS3eveBqRZzOG/Cn6nMRbQBXdbWnqlylxTqsGw8VZpMyNA3QJB1vH ffl70kMAAYxCOcCd8rbaWpPTcC5sZls9hrgUi3QPdBxYrnA8TDD/n7h3gEClEV+B2r yCiXoB4DsehHR8dPgwx/+e6aloO2hIle91zQefO50pzpEJCREMW9ArRLQMHH4n6bgd YX9RbQ/Llmn48sbnuWRFang6Xf6eMCEEKfkU0gzo39stxHuDo39DbUfFGttJHh77Gc PzY4trjmuiB+g== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Sweet Tea Dorminy Subject: [PATCH 1/6] btrfs-progs: add fscrypt feature flag. Date: Wed, 17 Aug 2022 10:42:54 -0400 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Add the new FSCRYPT feature flag and mkfs option. For now, claim 5.19 as the earliest version with this, though the actual kernel version will need fixing up when it actually gets in. Signed-off-by: Sweet Tea Dorminy --- common/fsfeatures.c | 10 ++++++++++ kernel-shared/ctree.h | 4 +++- libbtrfsutil/btrfs.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/common/fsfeatures.c b/common/fsfeatures.c index 23a92c21..7c12576f 100644 --- a/common/fsfeatures.c +++ b/common/fsfeatures.c @@ -143,6 +143,16 @@ static const struct btrfs_feature mkfs_features[] = { .desc = "new extent tree format" }, #endif + { + .name = "encrypt", + .flag = BTRFS_FEATURE_INCOMPAT_FSCRYPT, + .sysfs_name = "fscrypt", + VERSION_TO_STRING2(compat, 5,19), + VERSION_NULL(safe), + VERSION_NULL(default), + .desc = "fs-level encryption" + }, + /* Keep this one last */ { .name = "list-all", diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index 38758dfc..6e5bf74b 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -508,6 +508,7 @@ BUILD_ASSERT(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE); #define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11) #define BTRFS_FEATURE_INCOMPAT_ZONED (1ULL << 12) #define BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2 (1ULL << 13) +#define BTRFS_FEATURE_INCOMPAT_FSCRYPT (1ULL << 14) #define BTRFS_FEATURE_COMPAT_SUPP 0ULL @@ -536,7 +537,8 @@ BUILD_ASSERT(sizeof(struct btrfs_super_block) == BTRFS_SUPER_INFO_SIZE); BTRFS_FEATURE_INCOMPAT_RAID1C34 | \ BTRFS_FEATURE_INCOMPAT_METADATA_UUID | \ BTRFS_FEATURE_INCOMPAT_ZONED | \ - BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2) + BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2 | \ + BTRFS_FEATURE_INCOMPAT_FSCRYPT) #else #define BTRFS_FEATURE_INCOMPAT_SUPP \ (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \ diff --git a/libbtrfsutil/btrfs.h b/libbtrfsutil/btrfs.h index 0d863d58..3d67f251 100644 --- a/libbtrfsutil/btrfs.h +++ b/libbtrfsutil/btrfs.h @@ -277,6 +277,8 @@ struct btrfs_ioctl_fs_info_args { #define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11) #define BTRFS_FEATURE_INCOMPAT_ZONED (1ULL << 12) +#define BTRFS_FEATURE_INCOMPAT_FSCRYPT (1ULL << 14) + struct btrfs_ioctl_feature_flags { __u64 compat_flags; __u64 compat_ro_flags; From patchwork Wed Aug 17 14:42:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 12946008 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AB2F3C25B08 for ; Wed, 17 Aug 2022 14:43:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240291AbiHQOnr (ORCPT ); Wed, 17 Aug 2022 10:43:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240064AbiHQOnf (ORCPT ); Wed, 17 Aug 2022 10:43:35 -0400 Received: from box.fidei.email (box.fidei.email [IPv6:2605:2700:0:2:a800:ff:feba:dc44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEFA7481D4 for ; Wed, 17 Aug 2022 07:43:33 -0700 (PDT) Received: from authenticated-user (box.fidei.email [71.19.144.250]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by box.fidei.email (Postfix) with ESMTPSA id A950580AA3; Wed, 17 Aug 2022 10:43:32 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1660747413; bh=OlnKPN9LLQ9IY/vPCiLjGyKlC424CDRyh1yCjVFkbKA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cOvt6U96igHqRa4gqDbqa0HsJyzjpC4JZRVx/TE19I/vRqDdG7wQzF9/w1N1alGHy rR1XytnbWg1w1sdpAKO1VstJWk+m/M7TXgx8qKLgeIyBydqFKhP047s3VMp/P9oQVY 2YvBVKbrZu+oRj0AmQs2zGmACEZBFrQlpWGVp5kJBezHTQDlZ+jJlZqn+mgv4SdQoV ZUcZ3JwVcbdr7yem/Z84wbAA0Vzo2svMsWU86e5L6KPh0gBsDseQYs7lyTNPJYbMHg 3nGCiHPOcPvHxu71Fz4mb8GReCROq5MlA4LWK+Xq7DOx5El9BnAThu4ZTXhKPvubQ9 5PLxRlrTx8Vyw== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Sweet Tea Dorminy Subject: [PATCH 2/6] btrfs-progs: adjust for new dir flag. Date: Wed, 17 Aug 2022 10:42:55 -0400 Message-Id: <4b01dda0d398550f76647a16ed3c146d8f7c2e17.1660729916.git.sweettea-kernel@dorminy.me> In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The advent of encryption necessitates converting the directory type into a directory type and a flag indicating encryption. Thus, rename the field dir_type to dir_flags. For those uses which don't care about encryption and just want to know what type the directory is, a new helper is added to strip the encryption flag. This renaming, and use of the helper where appropriate, is reflected throughout the codebase. Signed-off-by: Sweet Tea Dorminy --- check/main.c | 4 ++-- check/mode-common.c | 4 ++-- check/mode-lowmem.c | 6 +++--- cmds/restore.c | 2 +- kernel-shared/ctree.h | 18 ++++++++++++++++-- kernel-shared/dir-item.c | 8 ++++---- kernel-shared/inode.c | 4 +++- kernel-shared/print-tree.c | 2 +- libbtrfsutil/btrfs_tree.h | 3 +++ 9 files changed, 35 insertions(+), 16 deletions(-) diff --git a/check/main.c b/check/main.c index 0ba38f73..790b091d 100644 --- a/check/main.c +++ b/check/main.c @@ -1418,7 +1418,7 @@ static int process_dir_item(struct extent_buffer *eb, btrfs_dir_item_key_to_cpu(eb, di, &location); name_len = btrfs_dir_name_len(eb, di); data_len = btrfs_dir_data_len(eb, di); - filetype = btrfs_dir_type(eb, di); + filetype = btrfs_dir_flags_to_ftype(btrfs_dir_flags(eb, di)); rec->found_size += name_len; if (cur + sizeof(*di) + name_len > total || @@ -2122,7 +2122,7 @@ static int add_missing_dir_index(struct btrfs_root *root, disk_key.offset = 0; btrfs_set_dir_item_key(leaf, dir_item, &disk_key); - btrfs_set_dir_type(leaf, dir_item, imode_to_type(rec->imode)); + btrfs_set_dir_flags(leaf, dir_item, imode_to_type(rec->imode)); btrfs_set_dir_data_len(leaf, dir_item, 0); btrfs_set_dir_name_len(leaf, dir_item, backref->namelen); name_ptr = (unsigned long)(dir_item + 1); diff --git a/check/mode-common.c b/check/mode-common.c index b867c350..0c5c7d6d 100644 --- a/check/mode-common.c +++ b/check/mode-common.c @@ -754,7 +754,7 @@ static int find_file_type_dir_index(struct btrfs_root *root, u64 ino, u64 dirid, if (location.objectid != ino || location.type != BTRFS_INODE_ITEM_KEY || location.offset != 0) goto out; - filetype = btrfs_dir_type(path.nodes[0], di); + filetype = btrfs_dir_flags_to_ftype(btrfs_dir_flags(path.nodes[0], di)); if (filetype >= BTRFS_FT_MAX || filetype == BTRFS_FT_UNKNOWN) goto out; len = min_t(u32, BTRFS_NAME_LEN, @@ -813,7 +813,7 @@ static int find_file_type_dir_item(struct btrfs_root *root, u64 ino, u64 dirid, location.type != BTRFS_INODE_ITEM_KEY || location.offset != 0) continue; - filetype = btrfs_dir_type(path.nodes[0], di); + filetype = btrfs_dir_flags_to_ftype(btrfs_dir_flags(path.nodes[0], di)); if (filetype >= BTRFS_FT_MAX || filetype == BTRFS_FT_UNKNOWN) continue; len = min_t(u32, BTRFS_NAME_LEN, diff --git a/check/mode-lowmem.c b/check/mode-lowmem.c index fa324506..920358d8 100644 --- a/check/mode-lowmem.c +++ b/check/mode-lowmem.c @@ -856,7 +856,7 @@ loop: location.offset != 0) goto next; - filetype = btrfs_dir_type(node, di); + filetype = btrfs_dir_flags_to_ftype(btrfs_dir_flags(node, di)); if (file_type != filetype) goto next; @@ -954,7 +954,7 @@ static int find_dir_item(struct btrfs_root *root, struct btrfs_key *key, location.offset != location_key->offset) goto next; - filetype = btrfs_dir_type(node, di); + filetype = btrfs_dir_flags_to_ftype(btrfs_dir_flags(node, di)); if (file_type != filetype) goto next; @@ -1744,7 +1744,7 @@ begin: (*size) += name_len; read_extent_buffer(node, namebuf, (unsigned long)(di + 1), len); - filetype = btrfs_dir_type(node, di); + filetype = btrfs_dir_flags_to_ftype(btrfs_dir_flags(node, di)); if (di_key->type == BTRFS_DIR_ITEM_KEY && di_key->offset != btrfs_name_hash(namebuf, len)) { diff --git a/cmds/restore.c b/cmds/restore.c index b517c30c..84cc0724 100644 --- a/cmds/restore.c +++ b/cmds/restore.c @@ -991,7 +991,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key, name_len = btrfs_dir_name_len(leaf, dir_item); read_extent_buffer(leaf, filename, name_ptr, name_len); filename[name_len] = '\0'; - type = btrfs_dir_type(leaf, dir_item); + type = btrfs_dir_flags_to_ftype(btrfs_dir_flags(leaf, dir_item)); btrfs_dir_item_key_to_cpu(leaf, dir_item, &location); /* full path from root of btrfs being restored */ diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index 6e5bf74b..bbb4b534 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -176,6 +176,14 @@ enum btrfs_csum_type { #define BTRFS_FT_XATTR 8 #define BTRFS_FT_MAX 9 +/* Name is encrypted */ +#define BTRFS_FT_FSCRYPT_NAME 0x80 + +static inline __u8 btrfs_dir_flags_to_ftype(__u8 flags) +{ + return flags & ~BTRFS_FT_FSCRYPT_NAME; +} + #define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0) /* @@ -2039,15 +2047,21 @@ BTRFS_SETGET_STACK_FUNCS(stack_root_ref_name_len, struct btrfs_root_ref, name_le /* struct btrfs_dir_item */ BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16); -BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8); +BTRFS_SETGET_FUNCS(dir_flags, struct btrfs_dir_item, type, 8); BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16); BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64); BTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item, data_len, 16); -BTRFS_SETGET_STACK_FUNCS(stack_dir_type, struct btrfs_dir_item, type, 8); +BTRFS_SETGET_STACK_FUNCS(stack_dir_flags, struct btrfs_dir_item, type, 8); BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16); BTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item, transid, 64); +static inline __u8 btrfs_dir_ftype(const struct extent_buffer *eb, + const struct btrfs_dir_item *item) +{ + return btrfs_dir_flags_to_ftype(btrfs_dir_flags(eb, item)); +} + static inline void btrfs_dir_item_key(struct extent_buffer *eb, struct btrfs_dir_item *item, struct btrfs_disk_key *key) diff --git a/kernel-shared/dir-item.c b/kernel-shared/dir-item.c index 27dfb362..27cf459d 100644 --- a/kernel-shared/dir-item.c +++ b/kernel-shared/dir-item.c @@ -89,7 +89,7 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, leaf = path->nodes[0]; btrfs_cpu_key_to_disk(&disk_key, &location); btrfs_set_dir_item_key(leaf, dir_item, &disk_key); - btrfs_set_dir_type(leaf, dir_item, BTRFS_FT_XATTR); + btrfs_set_dir_flags(leaf, dir_item, BTRFS_FT_XATTR); btrfs_set_dir_name_len(leaf, dir_item, name_len); btrfs_set_dir_data_len(leaf, dir_item, data_len); name_ptr = (unsigned long)(dir_item + 1); @@ -141,7 +141,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root leaf = path->nodes[0]; btrfs_cpu_key_to_disk(&disk_key, location); btrfs_set_dir_item_key(leaf, dir_item, &disk_key); - btrfs_set_dir_type(leaf, dir_item, type); + btrfs_set_dir_flags(leaf, dir_item, type); btrfs_set_dir_data_len(leaf, dir_item, 0); btrfs_set_dir_name_len(leaf, dir_item, name_len); name_ptr = (unsigned long)(dir_item + 1); @@ -170,7 +170,7 @@ insert: leaf = path->nodes[0]; btrfs_cpu_key_to_disk(&disk_key, location); btrfs_set_dir_item_key(leaf, dir_item, &disk_key); - btrfs_set_dir_type(leaf, dir_item, type); + btrfs_set_dir_flags(leaf, dir_item, type); btrfs_set_dir_data_len(leaf, dir_item, 0); btrfs_set_dir_name_len(leaf, dir_item, name_len); name_ptr = (unsigned long)(dir_item + 1); @@ -292,7 +292,7 @@ static int verify_dir_item(struct btrfs_root *root, struct btrfs_dir_item *dir_item) { u16 namelen = BTRFS_NAME_LEN; - u8 type = btrfs_dir_type(leaf, dir_item); + u8 type = btrfs_dir_flags_to_ftype(btrfs_dir_flags(leaf, dir_item)); if (type == BTRFS_FT_XATTR) namelen = XATTR_NAME_MAX; diff --git a/kernel-shared/inode.c b/kernel-shared/inode.c index 8dfe5b0d..66c16a98 100644 --- a/kernel-shared/inode.c +++ b/kernel-shared/inode.c @@ -541,6 +541,7 @@ int btrfs_mkdir(struct btrfs_trans_handle *trans, struct btrfs_root *root, if (dir_item) { struct btrfs_key found_key; + u8 type; /* * Already have conflicting name, check if it is a dir. @@ -548,7 +549,8 @@ int btrfs_mkdir(struct btrfs_trans_handle *trans, struct btrfs_root *root, */ btrfs_dir_item_key_to_cpu(path->nodes[0], dir_item, &found_key); ret_ino = found_key.objectid; - if (btrfs_dir_type(path->nodes[0], dir_item) != BTRFS_FT_DIR) + type = btrfs_dir_flags_to_ftype(btrfs_dir_flags(path->nodes[0], dir_item)); + if (type != BTRFS_FT_DIR) ret = -EEXIST; goto out; } diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c index 24163258..3b1c2d4d 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -31,7 +31,7 @@ static void print_dir_item_type(struct extent_buffer *eb, struct btrfs_dir_item *di) { - u8 type = btrfs_dir_type(eb, di); + u8 type = btrfs_dir_flags_to_ftype(btrfs_dir_flags(eb, di)); static const char* dir_item_str[] = { [BTRFS_FT_REG_FILE] = "FILE", [BTRFS_FT_DIR] = "DIR", diff --git a/libbtrfsutil/btrfs_tree.h b/libbtrfsutil/btrfs_tree.h index 1df9efd6..fbe25037 100644 --- a/libbtrfsutil/btrfs_tree.h +++ b/libbtrfsutil/btrfs_tree.h @@ -322,6 +322,9 @@ #define BTRFS_FT_XATTR 8 #define BTRFS_FT_MAX 9 +/* Name is encrypted */ +#define BTRFS_FT_FSCRYPT_NAME 0x80 + /* * The key defines the order in the tree, and so it also defines (optimal) * block layout. From patchwork Wed Aug 17 14:42:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 12946009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D022C32771 for ; Wed, 17 Aug 2022 14:43:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240264AbiHQOnv (ORCPT ); Wed, 17 Aug 2022 10:43:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240278AbiHQOnj (ORCPT ); Wed, 17 Aug 2022 10:43:39 -0400 Received: from box.fidei.email (box.fidei.email [71.19.144.250]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B1FF49B69 for ; Wed, 17 Aug 2022 07:43:35 -0700 (PDT) Received: from authenticated-user (box.fidei.email [71.19.144.250]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by box.fidei.email (Postfix) with ESMTPSA id DF3CE80A9D; Wed, 17 Aug 2022 10:43:34 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1660747415; bh=wzmC/znpPDtjs5D9r4UF+Hm6fJ9W4WvD3sKfAqtfqUQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NEyCdHTIH03CDTkOKgFBxvUqVn0Lg402Zu/ZuwS/3Lm1YmgnPK76/UVKSH0z9ymxo Ena9VnjcWfTdSOQjn+jDkzbi3HZuM2l7SWyVxzXcxRMGUZcF3mqXJcvNJUhdWFwDpd mf6VYemQFKVH88RRJeD4lXjOfSNpRGFULJmgxjlBWLA1H4hZmLEc0KBiV5U4WtNSeZ iEoAWIGnsDg/F1aRAQAiwp9MmxSJ5xY0flFvxSsuWQrzmU99PWU7VxJfex8EqzzIIv R4gRtgbhKiYacnycLDIhFnVLIMVjZ4LHlHORwVsvC9Meun4G40o67R4q5izutlj/5x FL0pbAS1qhcnw== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Sweet Tea Dorminy Subject: [PATCH 3/6] btrfs-progs: interpret encrypted file extents. Date: Wed, 17 Aug 2022 10:42:56 -0400 Message-Id: <264361a86fdb6e30b2361a1156aed52aba90a7fa.1660729916.git.sweettea-kernel@dorminy.me> In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Encrypted file extents now have the 'encryption' field set to a encryption type plus an IV length, and have an IV appended to the item. This necessitates adjusting the struct to have a variable-length iv member at the end, and printing IVs if one is provided. Signed-off-by: Sweet Tea Dorminy --- check/main.c | 4 +++- kernel-shared/ctree.h | 24 +++++++++++++++++++++++- kernel-shared/fscrypt.h | 32 ++++++++++++++++++++++++++++++++ kernel-shared/print-tree.c | 25 +++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 kernel-shared/fscrypt.h diff --git a/check/main.c b/check/main.c index 790b091d..bfcd16fc 100644 --- a/check/main.c +++ b/check/main.c @@ -6538,6 +6538,7 @@ static int run_next_block(struct btrfs_root *root, for (i = 0; i < nritems; i++) { struct btrfs_file_extent_item *fi; unsigned long inline_offset; + u8 ivsize; inline_offset = offsetof(struct btrfs_file_extent_item, disk_bytenr); @@ -6673,8 +6674,9 @@ static int run_next_block(struct btrfs_root *root, continue; /* Prealloc/regular extent must have fixed item size */ + ivsize = btrfs_file_extent_encryption_ivsize(buf, fi); if (btrfs_item_size(buf, i) != - sizeof(struct btrfs_file_extent_item)) { + sizeof(struct btrfs_file_extent_item) + ivsize) { ret = -EUCLEAN; error( "invalid file extent item size, have %u expect %zu", diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index bbb4b534..e3ffdf8d 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -25,6 +25,7 @@ #include "kerncompat.h" #include "common/extent-cache.h" #include "kernel-shared/extent_io.h" +#include "kernel-shared/fscrypt.h" #include "ioctl.h" struct btrfs_root; @@ -989,7 +990,10 @@ struct btrfs_file_extent_item { * uncompressed and without encoding. */ __le64 num_bytes; - + /* + * The IV used to encrypt the data in this extent. + */ + u8 iv[0]; } __attribute__ ((__packed__)); struct btrfs_dev_stats_item { @@ -2446,6 +2450,24 @@ BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item, encryption, 8); BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item, other_encoding, 16); +static inline u8 +btrfs_file_extent_encryption_ivsize(const struct extent_buffer *eb, + struct btrfs_file_extent_item *e) +{ + u8 ivsize; + btrfs_unpack_encryption(btrfs_file_extent_encryption(eb, e), + NULL, &ivsize); + return ivsize; +} + +static inline u8 +btrfs_file_extent_ivsize_from_item(const struct extent_buffer *leaf, + struct btrfs_path *path) +{ + return (btrfs_item_size(leaf, path->slots[0]) - + sizeof(struct btrfs_file_extent_item)); +} + /* btrfs_qgroup_status_item */ BTRFS_SETGET_FUNCS(qgroup_status_version, struct btrfs_qgroup_status_item, diff --git a/kernel-shared/fscrypt.h b/kernel-shared/fscrypt.h new file mode 100644 index 00000000..277b775f --- /dev/null +++ b/kernel-shared/fscrypt.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef BTRFS_FSCRYPT_H +#define BTRFS_FSCRYPT_H + +#define BTRFS_ENCRYPTION_POLICY_MASK 0x0f +#define BTRFS_ENCRYPTION_IVSIZE_MASK 0xf0 + +/* Actually from include/linux/fscrypt.h */ +#define FSCRYPT_MAX_IV_SIZE 32 + +static inline void btrfs_unpack_encryption(u8 encryption, + u8 *policy, + u8 *ivsize) +{ + if (policy) + *policy = encryption & BTRFS_ENCRYPTION_POLICY_MASK; + if (ivsize) { + u8 transformed_ivsize = + (encryption & BTRFS_ENCRYPTION_IVSIZE_MASK) >> 4; + *ivsize = (transformed_ivsize ? + (1 << (transformed_ivsize - 1)) : 0); + } +} + +static inline u8 btrfs_pack_encryption(u8 policy, u8 ivsize) +{ + u8 transformed_ivsize = ivsize ? ilog2(ivsize) + 1 : 0; + return policy | (transformed_ivsize << 4); +} + +#endif // BTRFS_FSCRYPT_H diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c index 3b1c2d4d..215cbb11 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -354,6 +354,26 @@ static void compress_type_to_str(u8 compress_type, char *ret) } } +static void generate_encryption_string(struct extent_buffer *leaf, + struct btrfs_file_extent_item *fi, + char *ret) +{ + u8 encryption = btrfs_file_extent_encryption(leaf, fi); + u8 policy, ivsize; + u8 iv[FSCRYPT_MAX_IV_SIZE]; + btrfs_unpack_encryption(encryption, &policy, &ivsize); + if (ivsize) + read_extent_buffer(leaf, iv, (unsigned long)fi->iv, ivsize); + ret += sprintf(ret, "(%hhu, %hhu", policy, ivsize); + if (ivsize) { + int i; + ret += sprintf(ret, ": IV "); + for (i = 0; i < ivsize; i++) + ret += sprintf(ret, "%02hhx", iv[i]); + } + sprintf(ret, ")"); +} + static const char* file_extent_type_to_str(u8 type) { switch (type) { @@ -370,9 +390,11 @@ static void print_file_extent_item(struct extent_buffer *eb, { unsigned char extent_type = btrfs_file_extent_type(eb, fi); char compress_str[16]; + char encrypt_str[16]; compress_type_to_str(btrfs_file_extent_compression(eb, fi), compress_str); + generate_encryption_string(eb, fi, encrypt_str); printf("\t\tgeneration %llu type %hhu (%s)\n", btrfs_file_extent_generation(eb, fi), @@ -405,6 +427,9 @@ static void print_file_extent_item(struct extent_buffer *eb, printf("\t\textent compression %hhu (%s)\n", btrfs_file_extent_compression(eb, fi), compress_str); + printf("\t\textent encryption %hhu (%s)\n", + btrfs_file_extent_encryption(eb, fi), + encrypt_str); } /* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */ From patchwork Wed Aug 17 14:42:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 12946010 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 13EF6C28B2B for ; Wed, 17 Aug 2022 14:43:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240288AbiHQOnw (ORCPT ); Wed, 17 Aug 2022 10:43:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240298AbiHQOnm (ORCPT ); Wed, 17 Aug 2022 10:43:42 -0400 Received: from box.fidei.email (box.fidei.email [71.19.144.250]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D7D04E844 for ; Wed, 17 Aug 2022 07:43:38 -0700 (PDT) Received: from authenticated-user (box.fidei.email [71.19.144.250]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by box.fidei.email (Postfix) with ESMTPSA id 41D4B80AA3; Wed, 17 Aug 2022 10:43:37 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1660747417; bh=FY1D9X/4xL8y+zwLjidWzJDC0QLE8J9BRww3tw2Rk7U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uB73FC+XixbPOhSz67HwbQzYAztLOpb306xoGQKrYY51BKfeqWEPdu35zHGiAG8u8 JJybaXgUTLvzPk8eYWMqwIjX5WeP8d7L2fT8xmQVqcAm9HiTHH/ZrOlc/iYoVmOZxy Xs3gQ0LLKpifvORtoCCCeHEo6NhQ5Pvlob0nkbF5tl95Q6EmUenR4Om/1PIOYhrgPv Xg8+33GrSd5dcjKSlEhrTfn4NOp85nERZ67HwBc3OzCMV1FD8J/Vhk6ECU6l07e+lX A4044epZomUDZ7tFog6fCrhaEUZz3xSGxVvE7rLDHLdbCF/ZZsQH8YZD9pluPc//Cs o0UmN6UAeJsLw== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Sweet Tea Dorminy Subject: [PATCH 4/6] btrfs-progs: handle fscrypt context items Date: Wed, 17 Aug 2022 10:42:57 -0400 Message-Id: <25a60facebe4e79e5bbe5cc0c355270c2c219d83.1660729916.git.sweettea-kernel@dorminy.me> In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Encrypted inodes have a new associated item, the fscrypt context, which can be printed as a pure hex string in dump-tree. Signed-off-by: Sweet Tea Dorminy --- kernel-shared/ctree.h | 2 ++ kernel-shared/print-tree.c | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index e3ffdf8d..5a600aa0 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -1375,6 +1375,8 @@ static inline u32 BTRFS_MAX_XATTR_SIZE(const struct btrfs_fs_info *info) #define BTRFS_VERITY_DESC_ITEM_KEY 36 #define BTRFS_VERITY_MERKLE_ITEM_KEY 37 +#define BTRFS_FSCRYPT_CTXT_ITEM_KEY 41 + #define BTRFS_ORPHAN_ITEM_KEY 48 #define BTRFS_DIR_LOG_ITEM_KEY 60 diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c index 215cbb11..fce1be7e 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -97,6 +97,20 @@ static void print_dir_item(struct extent_buffer *eb, u32 size, } } +static void print_fscrypt_context(struct extent_buffer *eb, int slot) +{ + int i; + unsigned long ptr = btrfs_item_ptr_offset(eb, slot); + u32 item_size = btrfs_item_size(eb, slot); + u8 ctx_buf[item_size]; + + read_extent_buffer(eb, ctx_buf, ptr, item_size); + printf("\t\tvalue: "); + for(i = 0; i < item_size; i++) + printf("%02x", ctx_buf[i]); + printf("\n"); +} + static void print_inode_extref_item(struct extent_buffer *eb, u32 size, struct btrfs_inode_extref *extref) { @@ -671,6 +685,7 @@ void print_key_type(FILE *stream, u64 objectid, u8 type) [BTRFS_DIR_LOG_ITEM_KEY] = "DIR_LOG_ITEM", [BTRFS_DIR_LOG_INDEX_KEY] = "DIR_LOG_INDEX", [BTRFS_XATTR_ITEM_KEY] = "XATTR_ITEM", + [BTRFS_FSCRYPT_CTXT_ITEM_KEY] = "FSCRYPT_CTXT_ITEM", [BTRFS_VERITY_DESC_ITEM_KEY] = "VERITY_DESC_ITEM", [BTRFS_VERITY_MERKLE_ITEM_KEY] = "VERITY_MERKLE_ITEM", [BTRFS_ORPHAN_ITEM_KEY] = "ORPHAN_ITEM", @@ -1378,6 +1393,9 @@ void btrfs_print_leaf(struct extent_buffer *eb, unsigned int mode) case BTRFS_XATTR_ITEM_KEY: print_dir_item(eb, item_size, ptr); break; + case BTRFS_FSCRYPT_CTXT_ITEM_KEY: + print_fscrypt_context(eb, i); + break; case BTRFS_DIR_LOG_INDEX_KEY: case BTRFS_DIR_LOG_ITEM_KEY: { struct btrfs_dir_log_item *dlog; From patchwork Wed Aug 17 14:42:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 12946011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86FE6C25B08 for ; Wed, 17 Aug 2022 14:43:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240336AbiHQOny (ORCPT ); Wed, 17 Aug 2022 10:43:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240300AbiHQOnq (ORCPT ); Wed, 17 Aug 2022 10:43:46 -0400 Received: from box.fidei.email (box.fidei.email [71.19.144.250]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEFA25B7B9 for ; Wed, 17 Aug 2022 07:43:40 -0700 (PDT) Received: from authenticated-user (box.fidei.email [71.19.144.250]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by box.fidei.email (Postfix) with ESMTPSA id 6A73480B43; Wed, 17 Aug 2022 10:43:39 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1660747419; bh=N9rhdA2rpJe9TW33+TBs+cTLCT061KlQddnPpMcqi3w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s/LFJyu3/W1SfoIJc/E/0BdkA6ygOJt9F3j1RlufhpkfWg80AS83GpQFPUSVOWHTF 1ckj7DFwZ6fXi0eThAq+LKLlAS2GFXmTyr88+TWEtsh+3BRERdi+Knx+JinRgaQ9T2 6yuNXKRIDtg0ETDmCaF+9fqKaNs60M9EViGAmkO3r7q7hz79Fge3UFS0l7sZ/X8pEn UplwOrEBtSW67z3uc67mo0jrifgDPVfciYbhzRFhMkSBNoAPYfrsrdq+j+2Omn4hZ8 6/lHkuGIIZylxEg//jSjw5LX8ph2z2b4Mwb2Yh+ixWf7p3/LBm+6SKKKavYgBPG+1M 9SxKntMdkuoZA== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Sweet Tea Dorminy Subject: [PATCH 5/6] btrfs-progs: escape unprintable characters in names Date: Wed, 17 Aug 2022 10:42:58 -0400 Message-Id: <443a1d4e8b3428d69e746793d4494304e42dab94.1660729916.git.sweettea-kernel@dorminy.me> In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org There are several item types which have an associated name: inode refs and dir items. While they could always be unprintable, the advent of encryption makes it much more likely that the names contain characters outside the normal ASCII range. As such, it's useful to print the characters outside normal ASCII in hex format. Signed-off-by: Sweet Tea Dorminy --- kernel-shared/print-tree.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c index fce1be7e..0e892c81 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -28,6 +28,19 @@ #include "kernel-shared/volumes.h" #include "common/utils.h" +static void print_name(const char *buf, size_t len) +{ + size_t i; + printf("name: "); + for(i = 0; i < len; i++) { + if (buf[i] >= ' ' && buf[i] <= '~') + printf("%c", buf[i]); + else + printf("\\x%02hhx", buf[i]); + } + printf("\n"); +} + static void print_dir_item_type(struct extent_buffer *eb, struct btrfs_dir_item *di) { @@ -77,7 +90,7 @@ static void print_dir_item(struct extent_buffer *eb, u32 size, } else { read_extent_buffer(eb, namebuf, (unsigned long)(di + 1), len); - printf("\t\tname: %.*s\n", len, namebuf); + print_name(namebuf, len); } if (data_len) { @@ -135,7 +148,7 @@ static void print_inode_extref_item(struct extent_buffer *eb, u32 size, } else { read_extent_buffer(eb, namebuf, (unsigned long)extref->name, len); - printf("name: %.*s\n", len, namebuf); + print_name(namebuf, len); } len = sizeof(*extref) + name_len; @@ -165,7 +178,7 @@ static void print_inode_ref_item(struct extent_buffer *eb, u32 size, } else { read_extent_buffer(eb, namebuf, (unsigned long)(ref + 1), len); - printf("name: %.*s\n", len, namebuf); + print_name(namebuf, len); } len = sizeof(*ref) + name_len; ref = (struct btrfs_inode_ref *)((char *)ref + len); From patchwork Wed Aug 17 14:42:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 12946012 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E548C28B2B for ; Wed, 17 Aug 2022 14:43:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240349AbiHQOnz (ORCPT ); Wed, 17 Aug 2022 10:43:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240305AbiHQOnr (ORCPT ); Wed, 17 Aug 2022 10:43:47 -0400 Received: from box.fidei.email (box.fidei.email [71.19.144.250]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2CFA875CEC for ; Wed, 17 Aug 2022 07:43:42 -0700 (PDT) Received: from authenticated-user (box.fidei.email [71.19.144.250]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by box.fidei.email (Postfix) with ESMTPSA id 896FB80A9D; Wed, 17 Aug 2022 10:43:41 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1660747422; bh=GN+UOAXwTW8iDc3zN0WFJa5yXDq5JDXTjZir2RNcpOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fTlXrm4W5OP7NMdqoQBZUMdBIch8yQ9BG9iT88NjYecCzJjX+yCIUvQxXZTWdsk7j EjzBpqjVo6OMs6oQgjrnmgGcxhQwndiz7qNrqXOj55fLxiaP2PbCQ3cXH3EZhDe7lO uhlWgz3DGnekYHs77qE6NY8/PNxo9FPGueNloerGERyFLKg/H00KIuaTDkPbktnr2M CFXOOeUvlAKxgad6vwIi1Mdr65BYvmQe7bdhvyQwDfEtzmLFYHx/Ukpwd8DFmMnSAj SQVurDwgiskQg+Xl+Z4GrszYFjxgYhNNUp3+Nscoz/UuMHxMxJBNalf2dZI7aFEXE4 Od9LjNtCin9Jw== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Sweet Tea Dorminy Subject: [PATCH 6/6] btrfs-progs: update inline extent length checking Date: Wed, 17 Aug 2022 10:42:59 -0400 Message-Id: <640399bd56c8795ef2606a0a5349bac498e92ee4.1660729916.git.sweettea-kernel@dorminy.me> In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org As part of the encryption changes, encrypted inline file extents record their actual data length in ram_bytes, like compressed inline file extents, while the item's length records the actual size. As such, encrypted inline extents must be treated like compressed ones for inode length consistency checking. Signed-off-by: Sweet Tea Dorminy --- check/main.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/check/main.c b/check/main.c index bfcd16fc..5ed665ef 100644 --- a/check/main.c +++ b/check/main.c @@ -1623,7 +1623,7 @@ static int process_file_extent(struct btrfs_root *root, u64 mask = gfs_info->sectorsize - 1; u32 max_inline_size = min_t(u32, mask, BTRFS_MAX_INLINE_DATA_SIZE(gfs_info)); - u8 compression; + u8 compression, encryption; int extent_type; int ret; @@ -1648,25 +1648,25 @@ static int process_file_extent(struct btrfs_root *root, fi = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item); extent_type = btrfs_file_extent_type(eb, fi); compression = btrfs_file_extent_compression(eb, fi); + encryption = btrfs_file_extent_encryption(eb, fi); if (extent_type == BTRFS_FILE_EXTENT_INLINE) { - num_bytes = btrfs_file_extent_ram_bytes(eb, fi); - if (num_bytes == 0) + u64 num_decoded_bytes = btrfs_file_extent_ram_bytes(eb, fi); + u64 num_disk_bytes = btrfs_file_extent_inline_item_len(eb, slot); + if (num_decoded_bytes == 0) rec->errors |= I_ERR_BAD_FILE_EXTENT; - if (compression) { - if (btrfs_file_extent_inline_item_len(eb, slot) > - max_inline_size || - num_bytes > gfs_info->sectorsize) + if (compression || encryption) { + if (num_disk_bytes > max_inline_size || + num_decoded_bytes > gfs_info->sectorsize) rec->errors |= I_ERR_FILE_EXTENT_TOO_LARGE; } else { - if (num_bytes > max_inline_size) + if (num_decoded_bytes > max_inline_size) rec->errors |= I_ERR_FILE_EXTENT_TOO_LARGE; - if (btrfs_file_extent_inline_item_len(eb, slot) != - num_bytes) + if (num_disk_bytes != num_decoded_bytes) rec->errors |= I_ERR_INLINE_RAM_BYTES_WRONG; } - rec->found_size += num_bytes; - num_bytes = (num_bytes + mask) & ~mask; + rec->found_size += num_decoded_bytes; + num_bytes = (num_decoded_bytes + mask) & ~mask; } else if (extent_type == BTRFS_FILE_EXTENT_REG || extent_type == BTRFS_FILE_EXTENT_PREALLOC) { num_bytes = btrfs_file_extent_num_bytes(eb, fi);