From patchwork Tue Aug 8 17:22:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 13346708 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 41BC7C04A6A for ; Tue, 8 Aug 2023 18:17:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235587AbjHHSQ4 (ORCPT ); Tue, 8 Aug 2023 14:16:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235497AbjHHSQV (ORCPT ); Tue, 8 Aug 2023 14:16:21 -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 0AEBE7C701 for ; Tue, 8 Aug 2023 10:23:00 -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 889A98354E; Tue, 8 Aug 2023 13:23:00 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1691515380; bh=joEF3+va5Af010dXO69Cn6ETWbAgY5KWCyraZTJkzRY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UbzusW0R+YQ0Z8VvGwkY42k43/DcTazrnoiGaa9PvjUbstybtU6TtLRbbf343HwcF O08S7QhXOzoWiXQdJXvltuN+bAS2gqcmEoZy8Ic+z7+T/QH0LWhZS56lGPx6N9U5tJ j8o3IDKZ8g1zICr/0KkFB/E12/1kFnn9/ZWhFQQ0pNCfbABXeynBzYH4RW0VIsl7Hp AyjVZcet0hviZdWKQigYfeMEBqpyQgIqrMnyxwNRXEYWi3EtxaPaPjiufPzSwgIiII 25MQrkj1CZpFHCqdG3NBuJ9pJrt6GnS834kkKxwwK710XIx7x3wDnSLO+Ur1RLb2qy MufpwIpILyJ9Q== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, ebiggers@google.com, kernel-team@meta.com Cc: Sweet Tea Dorminy Subject: [PATCH v2 1/8] btrfs-progs: add new FEATURE_INCOMPAT_ENCRYPT flag Date: Tue, 8 Aug 2023 13:22:20 -0400 Message-ID: <9e6e697ccd73915b237fe1caefc55afa0dc95de9.1691520000.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 Matches kernel change by the same name. Signed-off-by: Sweet Tea Dorminy --- kernel-shared/ctree.h | 3 ++- kernel-shared/uapi/btrfs.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index 59533879b..6c9ff866f 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h @@ -103,7 +103,8 @@ static inline u32 __BTRFS_LEAF_DATA_SIZE(u32 nodesize) 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_ENCRYPT) #else #define BTRFS_FEATURE_INCOMPAT_SUPP \ (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \ diff --git a/kernel-shared/uapi/btrfs.h b/kernel-shared/uapi/btrfs.h index 85b04f89a..e347cceb0 100644 --- a/kernel-shared/uapi/btrfs.h +++ b/kernel-shared/uapi/btrfs.h @@ -356,6 +356,7 @@ _static_assert(sizeof(struct btrfs_ioctl_fs_info_args) == 1024); #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_ENCRYPT (1ULL << 14) struct btrfs_ioctl_feature_flags { __u64 compat_flags; From patchwork Tue Aug 8 17:22:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 13346934 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 BCA8DC41513 for ; Tue, 8 Aug 2023 19:48:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230368AbjHHTsz (ORCPT ); Tue, 8 Aug 2023 15:48:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235329AbjHHSQW (ORCPT ); Tue, 8 Aug 2023 14:16:22 -0400 Received: from box.fidei.email (box.fidei.email [71.19.144.250]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65669768A for ; Tue, 8 Aug 2023 10:23:02 -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 04AFE8354F; Tue, 8 Aug 2023 13:23:01 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1691515382; bh=hkyEGCML1GZoM8SkX38/nbSWGHcLrLq9/fryOwU2MeE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w+zsZ6TV6FM2xUBXRAFuAcF/M2EhFeQM7Ko9Tukl1K+bC9lTOJOdHjkC5vHUlHjVY 8MQlSv+XxCAZJIeTuAdeRkuXM7dhu6/YxiUzTcOXlIyzNNuLgGFVxHSbWu0pYUlM+y AvzkISQky4e3vznBRbhE9uCV9+3H584FqdzbPxYzJaj41Ip1cpXeDxK2jt8eBgmJpU rF4Y7o3AS3HwwOnu+Vj5Pw//DxI3n/PfCZGz/Arxvme9iyZ3Yw6+u1Xk1+g5XrrRXJ i6lrFjW/EPzQZKmSWq2B4iKFSA8woAK6RURulbJFAYspCeSI9TL2M7HEY93QstYNES +fueGHH5/MN4g== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, ebiggers@google.com, kernel-team@meta.com Cc: Sweet Tea Dorminy Subject: [PATCH v2 2/8] btrfs-progs: start tracking extent encryption context info Date: Tue, 8 Aug 2023 13:22:21 -0400 Message-ID: <47f04d1db075b2dcc704a59353c64ab368cf9b69.1691520000.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 This recapitulates the kernel change named 'btrfs: start tracking extent encryption context info". Signed-off-by: Sweet Tea Dorminy --- kernel-shared/accessors.h | 2 ++ kernel-shared/fscrypt.h | 25 ++++++++++++++++++++++++ kernel-shared/tree-checker.c | 37 ++++++++++++++++++++++++++++-------- 3 files changed, 56 insertions(+), 8 deletions(-) create mode 100644 kernel-shared/fscrypt.h diff --git a/kernel-shared/accessors.h b/kernel-shared/accessors.h index 539c20d09..1302ce5e6 100644 --- a/kernel-shared/accessors.h +++ b/kernel-shared/accessors.h @@ -949,6 +949,8 @@ BTRFS_SETGET_STACK_FUNCS(stack_file_extent_disk_num_bytes, struct btrfs_file_extent_item, disk_num_bytes, 64); BTRFS_SETGET_STACK_FUNCS(stack_file_extent_compression, struct btrfs_file_extent_item, compression, 8); +BTRFS_SETGET_STACK_FUNCS(stack_file_extent_encryption, + struct btrfs_file_extent_item, encryption, 8); BTRFS_SETGET_FUNCS(file_extent_type, struct btrfs_file_extent_item, type, 8); BTRFS_SETGET_FUNCS(file_extent_disk_bytenr, struct btrfs_file_extent_item, diff --git a/kernel-shared/fscrypt.h b/kernel-shared/fscrypt.h new file mode 100644 index 000000000..32fda99ca --- /dev/null +++ b/kernel-shared/fscrypt.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef BTRFS_FSCRYPT_H +#define BTRFS_FSCRYPT_H + +static inline u32 +btrfs_file_extent_encryption_ctxsize(const struct extent_buffer *eb, + struct btrfs_file_extent_item *e) +{ + if (!btrfs_file_extent_encryption(eb, e)) + return 0; + + return btrfs_get_32(eb, e, offsetof(struct btrfs_file_extent_item, + encryption_context)); +} + +static inline u8 +btrfs_file_extent_ctxsize_from_item(const struct extent_buffer *leaf, + int nr) +{ + return (btrfs_item_size(leaf, nr) - + sizeof(struct btrfs_file_extent_item)); +} + +#endif diff --git a/kernel-shared/tree-checker.c b/kernel-shared/tree-checker.c index 107975891..2665b2038 100644 --- a/kernel-shared/tree-checker.c +++ b/kernel-shared/tree-checker.c @@ -25,6 +25,7 @@ #include "kernel-shared/ctree.h" #include "kernel-shared/tree-checker.h" #include "kernel-shared/disk-io.h" +#include "kernel-shared/fscrypt.h" #include "kernel-shared/compression.h" #include "kernel-shared/volumes.h" #include "kernel-shared/misc.h" @@ -229,6 +230,7 @@ static int check_extent_data_item(struct extent_buffer *leaf, u32 sectorsize = fs_info->sectorsize; u32 item_size = btrfs_item_size(leaf, slot); u64 extent_end; + u8 policy; if (unlikely(!IS_ALIGNED(key->offset, sectorsize))) { file_extent_err(leaf, slot, @@ -280,10 +282,11 @@ static int check_extent_data_item(struct extent_buffer *leaf, BTRFS_NR_COMPRESS_TYPES - 1); return -EUCLEAN; } - if (unlikely(btrfs_file_extent_encryption(leaf, fi))) { + policy = btrfs_file_extent_encryption(leaf, fi); + if (unlikely(policy >= BTRFS_NR_ENCRYPTION_TYPES)) { file_extent_err(leaf, slot, - "invalid encryption for file extent, have %u expect 0", - btrfs_file_extent_encryption(leaf, fi)); + "invalid encryption for file extent, have %u expect range [0, %u]", + policy, BTRFS_NR_ENCRYPTION_TYPES - 1); return -EUCLEAN; } if (btrfs_file_extent_type(leaf, fi) == BTRFS_FILE_EXTENT_INLINE) { @@ -312,12 +315,30 @@ static int check_extent_data_item(struct extent_buffer *leaf, return 0; } - /* Regular or preallocated extent has fixed item size */ - if (unlikely(item_size != sizeof(*fi))) { - file_extent_err(leaf, slot, + if (policy == BTRFS_ENCRYPTION_FSCRYPT) { + u8 ctxsize = btrfs_file_extent_encryption_ctxsize(leaf, fi); + + if (unlikely(item_size != sizeof(*fi) + ctxsize)) { + file_extent_err(leaf, slot, + "invalid item size for encrypted file extent, have %u expect = %zu + context of size %u", + item_size, sizeof(*fi), ctxsize); + return -EUCLEAN; + } + /* Only regular extents should be encrypted. */ + if (btrfs_file_extent_type(leaf, fi) != BTRFS_FILE_EXTENT_REG) { + file_extent_err(leaf, slot, + "invalid type for encrypted file extent, have %u expect %u", + btrfs_file_extent_type(leaf, fi), + BTRFS_FILE_EXTENT_REG); + return -EUCLEAN; + } + } else { + if (unlikely(item_size != sizeof(*fi))) { + file_extent_err(leaf, slot, "invalid item size for reg/prealloc file extent, have %u expect %zu", - item_size, sizeof(*fi)); - return -EUCLEAN; + item_size, sizeof(*fi)); + return -EUCLEAN; + } } if (unlikely(CHECK_FE_ALIGNED(leaf, slot, fi, ram_bytes, sectorsize) || CHECK_FE_ALIGNED(leaf, slot, fi, disk_bytenr, sectorsize) || From patchwork Tue Aug 8 17:22:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 13346933 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 78BE2C001DB for ; Tue, 8 Aug 2023 19:48:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230447AbjHHTs4 (ORCPT ); Tue, 8 Aug 2023 15:48:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235314AbjHHSQW (ORCPT ); Tue, 8 Aug 2023 14:16:22 -0400 Received: from box.fidei.email (box.fidei.email [71.19.144.250]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D56727C70F for ; Tue, 8 Aug 2023 10:23:03 -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 6F36D83557; Tue, 8 Aug 2023 13:23:03 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1691515383; bh=ELYGmi0i2dwyeypiaVUypDmzPYaLqInj4rIxE/sZySY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=v+LREPAVaGpFFEg2shS0tST657By2u12UrwfV7rElGoSHso6isruy6UXtlJVDKNbY w8m9GdzWLe+hLB/ggNCYVar2AzyBBLHcFanEOZ6eEtYZ3hZuc37Zwy9HGE+Xzm9wqo 5MAVKvHbr0Yl4SpjMB+fTRYNJXuvabunXupybO0BUI6x8oRVuaPmXl05gmnt4YuXIe tV0rmx3qwpjGdEFno4UED6Ym8xRQTnYShhVjOT2qyv7DAzzh8t26WdfrvpiYaQ2uGU ShsWNln+D6+IdltA8WxG11fEvTtZ3PA9G0V+LnaZLJoD8vlz4VssyoF1QCQN1sVHIn 1g24p40cQePOw== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, ebiggers@google.com, kernel-team@meta.com Cc: Sweet Tea Dorminy Subject: [PATCH v2 3/8] btrfs-progs: add inode encryption contexts Date: Tue, 8 Aug 2023 13:22:22 -0400 Message-ID: <939240ea58d2004f6b64d06a447f31d8bb97ea0f.1691520000.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 Recapitulates relevant parts of kernel change 'btrfs: add inode encryption contexts'. Signed-off-by: Sweet Tea Dorminy --- kernel-shared/uapi/btrfs_tree.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/kernel-shared/uapi/btrfs_tree.h b/kernel-shared/uapi/btrfs_tree.h index ad555e705..2df7cfec4 100644 --- a/kernel-shared/uapi/btrfs_tree.h +++ b/kernel-shared/uapi/btrfs_tree.h @@ -162,6 +162,8 @@ #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 /* reserve 2-15 close to the inode for later flexibility */ @@ -400,6 +402,7 @@ static inline __u8 btrfs_dir_flags_to_ftype(__u8 flags) #define BTRFS_INODE_NOATIME (1U << 9) #define BTRFS_INODE_DIRSYNC (1U << 10) #define BTRFS_INODE_COMPRESS (1U << 11) +#define BTRFS_INODE_ENCRYPT (1U << 12) #define BTRFS_INODE_ROOT_ITEM_INIT (1U << 31) @@ -416,6 +419,7 @@ static inline __u8 btrfs_dir_flags_to_ftype(__u8 flags) BTRFS_INODE_NOATIME | \ BTRFS_INODE_DIRSYNC | \ BTRFS_INODE_COMPRESS | \ + BTRFS_INODE_ENCRYPT | \ BTRFS_INODE_ROOT_ITEM_INIT) #define BTRFS_INODE_RO_VERITY (1U << 0) @@ -1016,6 +1020,12 @@ enum { BTRFS_NR_FILE_EXTENT_TYPES = 3, }; +enum { + BTRFS_ENCRYPTION_NONE, + BTRFS_ENCRYPTION_FSCRYPT, + BTRFS_NR_ENCRYPTION_TYPES, +}; + struct btrfs_file_extent_item { /* * transaction id that created this extent From patchwork Tue Aug 8 17:22:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 13346709 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 D354BC04A94 for ; Tue, 8 Aug 2023 18:17:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231634AbjHHSRZ (ORCPT ); Tue, 8 Aug 2023 14:17:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235435AbjHHSQX (ORCPT ); Tue, 8 Aug 2023 14:16:23 -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 BB9507C71C for ; Tue, 8 Aug 2023 10:23:05 -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 E71EC8354E; Tue, 8 Aug 2023 13:23:04 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1691515385; bh=gyOQqLkXJ8nN2qhN2fmMkaCWdsky5YkILPiT5605pPc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PXSbxk0Dg77xVOtqydoENsUm3LrFxvtLQteonAFBs8S9iCxvTB7faW/qeotBJFlmh xW+bm5uJJSMwsW0NEV5Rr0BEZNntanqhQ9HhiUDazec6xKoqPPqqGB2GMNB72OPu/h JQl27qDYdB7fCDzEhnTz2/2Qlf8DC65nTJcDPPTf4YQkvCIJksipXI0XhV517n0WAl Yc98T7PDkAqHrZ53LsZfhFHaB+SuPaOYpDF9M1Wipj7CqrGCImNeyMA5wn1bO+Bp4Q aCMagn98XvdxeV1fIYezVSW6CpxOEdppVEARUCYZvzqZzBZRBqrIUMpcahxvbYmj6R vxMELSWphRFBQ== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, ebiggers@google.com, kernel-team@meta.com Cc: Sweet Tea Dorminy Subject: [PATCH v2 4/8] btrfs-progs: save and load fscrypt extent contexts Date: Tue, 8 Aug 2023 13:22:23 -0400 Message-ID: <19d73f2d212981ce808d58a17eea5d7af62fed8b.1691520000.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 Mirrors the relevant part of kernel change 'btrfs: save and load fscrypt extent contexts' to progs. Signed-off-by: Sweet Tea Dorminy --- kernel-shared/uapi/btrfs_tree.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel-shared/uapi/btrfs_tree.h b/kernel-shared/uapi/btrfs_tree.h index 2df7cfec4..c1c3a46e4 100644 --- a/kernel-shared/uapi/btrfs_tree.h +++ b/kernel-shared/uapi/btrfs_tree.h @@ -1075,7 +1075,11 @@ struct btrfs_file_extent_item { * always reflects the size uncompressed and without encoding. */ __le64 num_bytes; - + /* + * fscrypt extent encryption context. Only present if extent is + * encrypted (stored in the encryption field). + */ + __u8 encryption_context[0]; } __attribute__ ((__packed__)); struct btrfs_csum_item { From patchwork Tue Aug 8 17:22:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 13346696 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 9062AC41513 for ; Tue, 8 Aug 2023 18:16:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232225AbjHHSQI (ORCPT ); Tue, 8 Aug 2023 14:16:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235476AbjHHSPp (ORCPT ); Tue, 8 Aug 2023 14:15:45 -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 AEB147C724 for ; Tue, 8 Aug 2023 10:23:06 -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 4B67B83548; Tue, 8 Aug 2023 13:23:06 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1691515386; bh=l9QXXmgyFNfLH+hXZhKDQCPb6+7NWcCsmgzzedPc+oE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c3uq40gqg0J96fjnalFqvf2N7TLHCm/ayNtjKSRZHVV6Wc94HWq/6xlfUy8y6w0tD D6/BM39lPft0lZyqsivEtYU6A9BoOVRd0YqkczEeMgluPTj/VLdhkcwck9pzJdZ8SM ecO5doq5/jCdNb0sm8FiBXaVMNPOsFpPsLRuJKmnX2GtuXQi6S8OJptsU0XOtebHAD 36CkuSAsWm9b1VvOrPvVI8pNBCiDJYKBwxWBRc2EQaO/aRAM9T91Vwl8eLMiySzf/C VUc2mmmR9e5pVsr6AczAXNJgTEBfZaMrWSI72aNYDi8XQPtM1m0Z8JxjYBBXudfgwV dTZNgSt34bsKw== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, ebiggers@google.com, kernel-team@meta.com Cc: Sweet Tea Dorminy Subject: [PATCH v2 5/8] btrfs-progs: interpret encrypted file extents. Date: Tue, 8 Aug 2023 13:22:24 -0400 Message-ID: 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 a context length, and have an extent context appended to the item. This necessitates adjusting the struct to have a variable-length fscrypt_context member at the end, and printing contexts if one is provided. Signed-off-by: Sweet Tea Dorminy --- check/main.c | 5 ++++- kernel-shared/print-tree.c | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/check/main.c b/check/main.c index d66e10e8f..00f73c43e 100644 --- a/check/main.c +++ b/check/main.c @@ -37,6 +37,7 @@ #include "kernel-shared/ctree.h" #include "kernel-shared/volumes.h" #include "kernel-shared/disk-io.h" +#include "kernel-shared/fscrypt.h" #include "kernel-shared/print-tree.h" #include "kernel-shared/transaction.h" #include "kernel-shared/free-space-cache.h" @@ -6345,6 +6346,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 ctxsize; inline_offset = offsetof(struct btrfs_file_extent_item, disk_bytenr); @@ -6480,8 +6482,9 @@ static int run_next_block(struct btrfs_root *root, continue; /* Prealloc/regular extent must have fixed item size */ + ctxsize = btrfs_file_extent_encryption_ctxsize(buf, fi); if (btrfs_item_size(buf, i) != - sizeof(struct btrfs_file_extent_item)) { + sizeof(struct btrfs_file_extent_item) + ctxsize) { ret = -EUCLEAN; error( "invalid file extent item size, have %u expect %zu", diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c index 0f7f7b72f..9f332f811 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -23,6 +23,7 @@ #include "kerncompat.h" #include "kernel-shared/ctree.h" #include "kernel-shared/disk-io.h" +#include "kernel-shared/fscrypt.h" #include "kernel-shared/print-tree.h" #include "kernel-shared/volumes.h" #include "kernel-shared/compression.h" @@ -356,6 +357,27 @@ 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 policy = btrfs_file_extent_encryption(leaf, fi); + u32 ctxsize = btrfs_file_extent_encryption_ctxsize(leaf, fi); + unsigned long offset = (unsigned long) fi; + const struct btrfs_file_extent_item *fi2 = (struct btrfs_file_extent_item *)(leaf->data + offset); + const __u8 *ctx = fi2->encryption_context; + + ret += sprintf(ret, "(%hhu, %u", policy, ctxsize); + + if (ctxsize) { + int i; + ret += sprintf(ret, ": context "); + for (i = 0; i < ctxsize; i++) + ret += sprintf(ret, "%02hhx", ctx[i]); + } + sprintf(ret, ")"); +} + static const char* file_extent_type_to_str(u8 type) { switch (type) { @@ -372,9 +394,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), @@ -407,6 +431,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 Tue Aug 8 17:22:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 13346710 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 41651C04FE2 for ; Tue, 8 Aug 2023 18:17:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233702AbjHHSR0 (ORCPT ); Tue, 8 Aug 2023 14:17:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235465AbjHHSQZ (ORCPT ); Tue, 8 Aug 2023 14:16:25 -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 4245435A7 for ; Tue, 8 Aug 2023 10:23:08 -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 B829483558; Tue, 8 Aug 2023 13:23:07 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1691515388; bh=gz1cvWz9XNld8XbPoojYUET63mYXtw2HSMkgQlZxueg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uMi9UXSZzjtvIhaZZto9+6EX4eS7TbRye/mf4P6gjHWpcbN/8NF+9NQp2+YL0miX8 F0KzjVb3nE/Vp48K/xPsX76n0jRxPrXYtF1LOQlkhwK4Luui+tEqaFiF8onBmtAX3w SvZeNLo8a4md7SKL5Pmupsoi9xiXTIOVFdUjcol8dqavv2jUO9XmpfnXUq6w6vwuRC tFuvlIT9HQUfjcd788+LUwVCyTOWXrEUzQY1WyOVyMLIkoNJSlkHcP5L3rVNiTPZ0m d+Z9jOoxDeX+eG/rcxbCi5h1GqCZJdEaZdJWBA5Y0BDg/BRMKDgdihDTPAmpiCkX/w 5ELTqNsNIjFpQ== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, ebiggers@google.com, kernel-team@meta.com Cc: Sweet Tea Dorminy Subject: [PATCH v2 6/8] btrfs-progs: handle fscrypt context items Date: Tue, 8 Aug 2023 13:22:25 -0400 Message-ID: <0d7c3a8f8584b9f5609da43abb20c434c390b85e.1691520000.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/print-tree.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c index 9f332f811..19a0e8ac8 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -100,6 +100,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) { @@ -675,6 +689,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", @@ -1395,6 +1410,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 Tue Aug 8 17:22:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 13346695 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 A8B6AC04A6A for ; Tue, 8 Aug 2023 18:16:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235347AbjHHSQC (ORCPT ); Tue, 8 Aug 2023 14:16:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233924AbjHHSPh (ORCPT ); Tue, 8 Aug 2023 14:15:37 -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 EB8B07C72E for ; Tue, 8 Aug 2023 10:23:09 -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 18CD18354F; Tue, 8 Aug 2023 13:23:09 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1691515389; bh=adASWTEzcSz7k3WzA+htbmJYOY4lyeVsxyhJldDR4lk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vUYt458SQBsPMNMAf26EbCbfF03GfvLLWYM79JK3dAqbocKSBCnUtQ5wnokA49AM4 4L3oMWSQ1tk/U+pUKP4jiDjiNqFF0wTbUKejmdgtZH9oArrgErLUa8r2v4uil7KugP SsZvFfbPdFh/SjyQIMqgEBEmzADrl8v/1NVe8yoOBb4sDSqmA0qPSU1BCr5bhv9sIk tOMRPLY7pLbJE/ZgaopbSKR+DdIeZkWMmUm05cr12148QYaqoYlw8RAzspBoZtr/Uv HcrQWNz+a83/KkKwOKS4au1Y9MNDXsWklEjiu40Y0W4wIDW/8rQ8PUj17Vz5z1sVIz 8WmDQ67dznmRA== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, ebiggers@google.com, kernel-team@meta.com Cc: Sweet Tea Dorminy Subject: [PATCH v2 7/8] btrfs-progs: escape unprintable characters in names Date: Tue, 8 Aug 2023 13:22:26 -0400 Message-ID: <94539c5eb5b301399c87178d00de758eb6f60803.1691520000.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 19a0e8ac8..fa9f73cba 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -31,6 +31,19 @@ #include "kernel-shared/file-item.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) { @@ -80,7 +93,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) { @@ -138,7 +151,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; @@ -168,7 +181,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 Tue Aug 8 17:22:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 13346711 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 DE3B1C04A6A for ; Tue, 8 Aug 2023 18:17:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234955AbjHHSR1 (ORCPT ); Tue, 8 Aug 2023 14:17:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235470AbjHHSQ1 (ORCPT ); Tue, 8 Aug 2023 14:16:27 -0400 Received: from box.fidei.email (box.fidei.email [71.19.144.250]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C30D7D78A for ; Tue, 8 Aug 2023 10:23:11 -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 A1B488354E; Tue, 8 Aug 2023 13:23:10 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1691515390; bh=AYeLeVX+Q+qjGl3yYMbZy3XbZSzv/n2t/sGbDIQd1dw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jrdRRxy48hM/W6Oi+y0RJYQezWw2peaYnaAt5Sap5JB5Uqn+HmeWawaJLD2KNFvFT SJdjWuwF3HJ4dGSGuJ6FMTmseVsho6yAAz0i3h2nsxOXxhbON5jSiDTSE4oNYMvXDT DClXYYN++UPV9dmUEh4K53fUV2TbvMSKPecjgn51UyXXyeRCErhD42+bXAcBwICVb/ lPut608baiuibnVniRXcgza+XYLtpTykTcDdjkdW0WnSW7BiYSm2vfpOGBKVcXiPF+ aiTsX+GRN3CXQooUAjKGRsDBTTXXtmHYty2m0Af32P9Ia/wJqeTuYnx8s4GXrdkgFf T7WyI9z8B/Fsg== From: Sweet Tea Dorminy To: linux-btrfs@vger.kernel.org, ebiggers@google.com, kernel-team@meta.com Cc: Sweet Tea Dorminy Subject: [PATCH v2 8/8] btrfs-progs: check: update inline extent length checking Date: Tue, 8 Aug 2023 13:22:27 -0400 Message-ID: <494b5b5316096d24370be40344f43594d8498146.1691520000.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 00f73c43e..b78e8b55a 100644 --- a/check/main.c +++ b/check/main.c @@ -1643,7 +1643,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; @@ -1668,25 +1668,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);