From patchwork Tue Oct 10 20:28:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13416027 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 63A3FCD8CB6 for ; Tue, 10 Oct 2023 20:28:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234412AbjJJU2f (ORCPT ); Tue, 10 Oct 2023 16:28:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234410AbjJJU2e (ORCPT ); Tue, 10 Oct 2023 16:28:34 -0400 Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14FFE91 for ; Tue, 10 Oct 2023 13:28:32 -0700 (PDT) Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-5a505762c9dso74916347b3.2 for ; Tue, 10 Oct 2023 13:28:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1696969711; x=1697574511; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ak1Eq1xLaehOMQ0y0GL69LpJqddCMtVfYsts+ouyM4o=; b=XPLz61xPf+EZbDHSrxu/p0NEG2W1J+9aXT+Vc7PfC6JwLSqkBGoWpVilNPwSxHXtv8 mL19HAQvE4y3sdNhEfBZlJWpjqceiiqft4XOrs8nmhpio/2rMY+MJcxFExgkL7FNRp9/ iIrS08d4PriLhzCCIZ9RQ04fw0kP6KeJ3aff8GWilMlM+hBxOERUW9lJigkxBfeHsxc+ 4DKbx2zTiw6BnkZIxqjPCD1RSKFKaglrYIDPjLasYOpDscKLz097UAjXUiCisArNT4ds 0voyd2VDiI6bb9RzcgzWiyfysT10A4x168tfconBASBH8ewGXOtafDXQClK8pHLs7PSB 5sjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696969711; x=1697574511; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ak1Eq1xLaehOMQ0y0GL69LpJqddCMtVfYsts+ouyM4o=; b=ATVOc8Y3arfaNyohSHfr8NByeXL8w/NMWLWxhIkvBPdPPaEddJEzHeuQuguxE5USZi kbszOXrdvsHmM3BPhglJ+83eOD+hS9lQje333XQ198vjr1RPuPq+Q2uAjRbaMFQSZPA9 iqRvhJG8p+pNovfs4izegJWedEtpoHGz1B2bF4bOL+FIZmK1v4qQqOEmxuSjmj8xjIx+ 68ERoFGLbSgBqJPZkrQs8MJgI55zgV+5QFnzonAG7889/c8J2TEGf0gBfEyPv48/ksfh SL+oSGTipBDsfbpvwhwRPaTn9ZA1C4WNXkBhYYqKV03yp3XIELqayKaDXwP6uZSOGvjl hLrw== X-Gm-Message-State: AOJu0YxpetQBtL8C40WeCxTaH634afIcN3qMvJqdLMBES1TGmr48fb3W 5W4X35fNaNrMI/wq6+iSkStPfS1rgKIRdz5B40+C9w== X-Google-Smtp-Source: AGHT+IHp+EnIiIHJgyuCWCdP+gzIxdvxpQj9ZyP19mYTtMROmiKwXhL5iigQIOVU0AQ2w/vI76HtzA== X-Received: by 2002:a81:6c8b:0:b0:59f:67f5:66c6 with SMTP id h133-20020a816c8b000000b0059f67f566c6mr19902863ywc.16.1696969711157; Tue, 10 Oct 2023 13:28:31 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id i5-20020a0ddf05000000b005a23ab90366sm4637007ywe.11.2023.10.10.13.28.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 13:28:30 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/8] btrfs-progs: check: fix max inline extent size Date: Tue, 10 Oct 2023 16:28:18 -0400 Message-ID: <999dc4783e67f45b00173f1ea869136c52ea598d.1696969632.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Fscrypt will use our entire inline extent range for symlinks, which uncovered a bug in btrfs check where we set the maximum inline extent size to min(sectorsize - 1, BTRFS_MAX_INLINE_DATA_SIZE) which isn't correct, we have always allowed sectorsize sized inline extents, so fix check to use the correct maximum inline extent size. Signed-off-by: Josef Bacik Reviewed-by: Neal Gompa --- check/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/check/main.c b/check/main.c index d387eb25..0979a8c6 100644 --- a/check/main.c +++ b/check/main.c @@ -1640,7 +1640,7 @@ static int process_file_extent(struct btrfs_root *root, u64 disk_bytenr = 0; u64 extent_offset = 0; u64 mask = gfs_info->sectorsize - 1; - u32 max_inline_size = min_t(u32, mask, + u32 max_inline_size = min_t(u32, gfs_info->sectorsize, BTRFS_MAX_INLINE_DATA_SIZE(gfs_info)); u8 compression; int extent_type; From patchwork Tue Oct 10 20:28:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13416028 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 C7188CD8CB7 for ; Tue, 10 Oct 2023 20:28:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234480AbjJJU2g (ORCPT ); Tue, 10 Oct 2023 16:28:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234442AbjJJU2f (ORCPT ); Tue, 10 Oct 2023 16:28:35 -0400 Received: from mail-yw1-x1132.google.com (mail-yw1-x1132.google.com [IPv6:2607:f8b0:4864:20::1132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 165FAA4 for ; Tue, 10 Oct 2023 13:28:33 -0700 (PDT) Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-5a7b92cd0ccso18786867b3.1 for ; Tue, 10 Oct 2023 13:28:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1696969712; x=1697574512; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YQcM66izjkkHNOvP6iDeJB5xjXS7gzV4FjRngbaMKvQ=; b=Vbx3AEed7lVN/jMCcHBG/jR+2q9bgS7SXXgdRRy8Xp6p6BLjqGDuxDzSJKsn3VSw6a g6sDU78+duGoV18a51aWmhqTXLzFeJzc69epj4nLsE/jGQFRQ5cKF9YoHCAd3zwibDBI rPbpyN12cVa1IoA3Z2wvWuIAvBP0Jj2gM9gudOpqc578yAWesHEfnacXKpb3QL2aJj0l h4E0JgAfCGcPa3Nep9W/AbrggLiecUORr1U/6gOdF54ZiPymuNJB1M6WmxIJGzbgALrD uf6/HuGeDncJiL/AVju6ak+NNTo7IKPo2mAsL3LRzECHX+XHKEQrrcWQBhE0yjn65UaF GpTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696969712; x=1697574512; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YQcM66izjkkHNOvP6iDeJB5xjXS7gzV4FjRngbaMKvQ=; b=LT1x650U/4AF6DImYorC6fRNxFYmu1qJboslRIwusF0qC4S5P/AFlRCIZGksKk/G9u 7ScNc9VdNfdZL1r/y2pBj0CH2w6jU0rPXc9PO3u+nr8LzrfQ+CsgNiBEWjrRGMDL0nv0 NEmgG1iyjSI5k0zN6f3tqSSHYYVC/3NKeb4e0meaHLAakZOypkC2/mGlfM+mm/SIm+LL VJ1Th8LFMN6fKB3glRampTc4Br6Lp/uSl6553Iv8uO4HA1HIstSc0KsyyEwju6gH4K2t kN4jQLW0Eyykfu/ls+gCdPhvA9wsGHFAkcsKRfM3+Q9eHH7BsEYtO1E038iI5ZoIXjJj TQbw== X-Gm-Message-State: AOJu0YwFwrbi6Z84vUQnkNAEZ18qT9eYwEHu1rApcsrSbxZ9/p92kH7n ChI/f/sOq5O4MCd8rlK7qwrAspVi8of9RItoibnXLw== X-Google-Smtp-Source: AGHT+IFWnZNCGiFe9IqnpC67uyPvginJ837m6qhil5MvjltxZoO357m1lJ9w8cnTZyKeRmVhExXfVA== X-Received: by 2002:a81:78d3:0:b0:5a7:a817:be43 with SMTP id t202-20020a8178d3000000b005a7a817be43mr4645258ywc.6.1696969712140; Tue, 10 Oct 2023 13:28:32 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id ft18-20020a05690c361200b0059b20231f1dsm3382648ywb.121.2023.10.10.13.28.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 13:28:31 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org Cc: Sweet Tea Dorminy Subject: [PATCH 2/8] btrfs-progs: add new FEATURE_INCOMPAT_ENCRYPT flag Date: Tue, 10 Oct 2023 16:28:19 -0400 Message-ID: <8328d47baed55c7e275eef41ddcab003c2c43e3a.1696969632.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Sweet Tea Dorminy 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 59533879..6c9ff866 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 85b04f89..cd00be93 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 << 15) struct btrfs_ioctl_feature_flags { __u64 compat_flags; From patchwork Tue Oct 10 20:28:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13416030 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 63F88CD8CB4 for ; Tue, 10 Oct 2023 20:28:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234432AbjJJU2g (ORCPT ); Tue, 10 Oct 2023 16:28:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234416AbjJJU2f (ORCPT ); Tue, 10 Oct 2023 16:28:35 -0400 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4230BB7 for ; Tue, 10 Oct 2023 13:28:34 -0700 (PDT) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-5a7be88e9ccso14417567b3.2 for ; Tue, 10 Oct 2023 13:28:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1696969713; x=1697574513; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3boZB9d4DR1nvDBWFnnLLUoFhwVH07qcVUA45H8uCsg=; b=ThPFwvADrA/fCQJXs2758GmXvl5a9w/TsN/BsymWfhUTCxr8QzjJHxZO3AAZWdaglj LNhhDLm3qzSSLARg3QNRDIdQL7erJZH72Jtx+EBXun/4yEaVGCG5ReeiR3kIVL44JYBa oB9F0lcsQnpQu5JOzlWWLugjk+kyYczI+TiJcyYmflwXeDHOw2Y5/dSXPwwzinhsSNsv UNmu1YaC08TMdU+A4ujtqq93KlpreMPtiBr7BF674xbbHqirrXw6oPfq5yNqhro4ma2D UanEI1mkUMB+77LU/Qx6rZwQjE5FHBv2pPaCPEpwBLIMGXe9CEqYIfZxwPjbbMdG/0Ki PiQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696969713; x=1697574513; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3boZB9d4DR1nvDBWFnnLLUoFhwVH07qcVUA45H8uCsg=; b=UtaWwDEJjI2CYknyNRlOg6g8+xxrts8tTcb3kImHjzyk+G+si3wx9IblpS0ep4JC8K u7fJnzOMJKTyzdIL6xUraGVYiR16Mv0P19ZGkZAuqrtL87livdYUgnLAvEErCXPM3U5S JrbXuogCMYX9ladrxmp0vP2RJ9fEn2wuaah3vSlpst3I7wKXBReuRhZsKDaiRIGp1JuB Q4MsSkQy7JkiONdpT2xHyRQ6i8lRP/Qi94aBnvIJuKmwwmuDbWbYxSb6z7RYNl9H6OEt NnbehtbpWs7F1h83ySeBgSgf9AP/EkHnvqHbYKiyv98wkgF/ezodlPAKw0QWT1saOQx6 nlgA== X-Gm-Message-State: AOJu0YybIb0MHYam6n5I1uZrifLBLUe8XWsww7RtNLpOZFVkioa5guBz PjvXQevzCGm6ZJFkfhVc/XNcDlfy1RlxWhEvSyDXYg== X-Google-Smtp-Source: AGHT+IG7jQhqlxU0Q1LAQQ1xorocUwBGC3Sc6EeLZa5qqlAfcZ33gM0Uv+m4vcjPEZIyFJMbgxtabA== X-Received: by 2002:a0d:cbd7:0:b0:5a7:d9e6:8fc6 with SMTP id n206-20020a0dcbd7000000b005a7d9e68fc6mr769596ywd.39.1696969713291; Tue, 10 Oct 2023 13:28:33 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id l21-20020a81ad15000000b005a20ab8a184sm919602ywh.31.2023.10.10.13.28.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 13:28:32 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org Cc: Sweet Tea Dorminy Subject: [PATCH 3/8] btrfs-progs: start tracking extent encryption context info Date: Tue, 10 Oct 2023 16:28:20 -0400 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Sweet Tea Dorminy This recapitulates the kernel change named 'btrfs: start tracking extent encryption context info". Signed-off-by: Sweet Tea Dorminy --- kernel-shared/accessors.h | 48 ++++++++++++++++++++++++ kernel-shared/tree-checker.c | 66 ++++++++++++++++++++++++++++----- kernel-shared/uapi/btrfs_tree.h | 23 +++++++++++- 3 files changed, 127 insertions(+), 10 deletions(-) diff --git a/kernel-shared/accessors.h b/kernel-shared/accessors.h index 539c20d0..04c0093c 100644 --- a/kernel-shared/accessors.h +++ b/kernel-shared/accessors.h @@ -932,6 +932,10 @@ BTRFS_SETGET_STACK_FUNCS(super_uuid_tree_generation, struct btrfs_super_block, BTRFS_SETGET_STACK_FUNCS(super_nr_global_roots, struct btrfs_super_block, nr_global_roots, 64); +/* struct btrfs_file_extent_encryption_info */ +BTRFS_SETGET_FUNCS(encryption_info_size, struct btrfs_encryption_info, size, + 32); + /* struct btrfs_file_extent_item */ BTRFS_SETGET_STACK_FUNCS(stack_file_extent_type, struct btrfs_file_extent_item, type, 8); @@ -970,6 +974,50 @@ BTRFS_SETGET_FUNCS(file_extent_encryption, struct btrfs_file_extent_item, BTRFS_SETGET_FUNCS(file_extent_other_encoding, struct btrfs_file_extent_item, other_encoding, 16); +static inline struct btrfs_encryption_info *btrfs_file_extent_encryption_info( + const struct btrfs_file_extent_item *ei) +{ + unsigned long offset = (unsigned long)ei; + + offset += offsetof(struct btrfs_file_extent_item, encryption_info); + return (struct btrfs_encryption_info *)offset; +} + +static inline unsigned long btrfs_file_extent_encryption_ctx_offset( + const struct btrfs_file_extent_item *ei) +{ + unsigned long offset = (unsigned long)ei; + + offset += offsetof(struct btrfs_file_extent_item, encryption_info); + return offset + offsetof(struct btrfs_encryption_info, context); +} + +static inline u32 btrfs_file_extent_encryption_ctx_size( + const struct extent_buffer *eb, + const struct btrfs_file_extent_item *ei) +{ + return btrfs_encryption_info_size(eb, + btrfs_file_extent_encryption_info(ei)); +} + +static inline void btrfs_set_file_extent_encryption_ctx_size( + const struct extent_buffer *eb, + struct btrfs_file_extent_item *ei, + u32 val) +{ + btrfs_set_encryption_info_size(eb, + btrfs_file_extent_encryption_info(ei), + val); +} + +static inline u32 btrfs_file_extent_encryption_info_size( + const struct extent_buffer *eb, + const struct btrfs_file_extent_item *ei) +{ + return btrfs_encryption_info_size(eb, + btrfs_file_extent_encryption_info(ei)); +} + /* btrfs_qgroup_status_item */ BTRFS_SETGET_FUNCS(qgroup_status_generation, struct btrfs_qgroup_status_item, generation, 64); diff --git a/kernel-shared/tree-checker.c b/kernel-shared/tree-checker.c index 10797589..282f9ba6 100644 --- a/kernel-shared/tree-checker.c +++ b/kernel-shared/tree-checker.c @@ -229,6 +229,8 @@ 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; + u8 fe_type; if (unlikely(!IS_ALIGNED(key->offset, sectorsize))) { file_extent_err(leaf, slot, @@ -259,12 +261,12 @@ static int check_extent_data_item(struct extent_buffer *leaf, SZ_4K); return -EUCLEAN; } - if (unlikely(btrfs_file_extent_type(leaf, fi) >= - BTRFS_NR_FILE_EXTENT_TYPES)) { + + fe_type = btrfs_file_extent_type(leaf, fi); + if (unlikely(fe_type >= BTRFS_NR_FILE_EXTENT_TYPES)) { file_extent_err(leaf, slot, "invalid type for file extent, have %u expect range [0, %u]", - btrfs_file_extent_type(leaf, fi), - BTRFS_NR_FILE_EXTENT_TYPES - 1); + fe_type, BTRFS_NR_FILE_EXTENT_TYPES - 1); return -EUCLEAN; } @@ -286,6 +288,13 @@ static int check_extent_data_item(struct extent_buffer *leaf, btrfs_file_extent_encryption(leaf, fi)); return -EUCLEAN; } + 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 range [0, %u]", + policy, BTRFS_NR_ENCRYPTION_TYPES - 1); + return -EUCLEAN; + } if (btrfs_file_extent_type(leaf, fi) == BTRFS_FILE_EXTENT_INLINE) { /* Inline extent must have 0 as key offset */ if (unlikely(key->offset)) { @@ -312,12 +321,51 @@ 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) { + size_t fe_size = sizeof(*fi) + + sizeof(struct btrfs_encryption_info); + u32 ctxsize; + + if (unlikely(item_size < fe_size)) { + file_extent_err(leaf, slot, + "invalid item size for encrypted file extent, have %u expect = %zu + size of u32", + item_size, sizeof(*fi)); + return -EUCLEAN; + } + + ctxsize = btrfs_file_extent_encryption_info_size(leaf, fi); + if (unlikely(item_size != (fe_size + ctxsize))) { + file_extent_err(leaf, slot, + "invalid item size for encrypted file extent, have %u expect = %zu + context of size %u", + item_size, fe_size, ctxsize); + return -EUCLEAN; + } + + if (unlikely(ctxsize > BTRFS_MAX_EXTENT_CTX_SIZE)) { + file_extent_err(leaf, slot, + "invalid file extent context size, have %u expect a maximum of %u", + ctxsize, BTRFS_MAX_EXTENT_CTX_SIZE); + return -EUCLEAN; + } + + /* + * Only regular and prealloc extents should have an encryption + * context. + */ + if (unlikely(fe_type != BTRFS_FILE_EXTENT_REG && + fe_type != BTRFS_FILE_EXTENT_PREALLOC)) { + file_extent_err(leaf, slot, + "invalid type for encrypted file extent, have %u", + btrfs_file_extent_type(leaf, fi)); + 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) || diff --git a/kernel-shared/uapi/btrfs_tree.h b/kernel-shared/uapi/btrfs_tree.h index ad555e70..f49ae534 100644 --- a/kernel-shared/uapi/btrfs_tree.h +++ b/kernel-shared/uapi/btrfs_tree.h @@ -1016,6 +1016,24 @@ enum { BTRFS_NR_FILE_EXTENT_TYPES = 3, }; +/* + * Currently just the FSCRYPT_SET_CONTEXT_MAX_SIZE, which is larger than the + * current extent context size from fscrypt, so this should give us plenty of + * breathing room for expansion later. + */ +#define BTRFS_MAX_EXTENT_CTX_SIZE 40 + +enum { + BTRFS_ENCRYPTION_NONE, + BTRFS_ENCRYPTION_FSCRYPT, + BTRFS_NR_ENCRYPTION_TYPES, +}; + +struct btrfs_encryption_info { + __le32 size; + __u8 context[0]; +}; + struct btrfs_file_extent_item { /* * transaction id that created this extent @@ -1065,7 +1083,10 @@ struct btrfs_file_extent_item { * always reflects the size uncompressed and without encoding. */ __le64 num_bytes; - + /* + * the encryption info, if any + */ + struct btrfs_encryption_info encryption_info[0]; } __attribute__ ((__packed__)); struct btrfs_csum_item { From patchwork Tue Oct 10 20:28:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13416029 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 C8FF5CD8CB8 for ; Tue, 10 Oct 2023 20:28:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343693AbjJJU2i (ORCPT ); Tue, 10 Oct 2023 16:28:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343548AbjJJU2g (ORCPT ); Tue, 10 Oct 2023 16:28:36 -0400 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 283E691 for ; Tue, 10 Oct 2023 13:28:35 -0700 (PDT) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-5a7ac4c3666so22749487b3.3 for ; Tue, 10 Oct 2023 13:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1696969714; x=1697574514; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7JoAqvQEt6eH9DqcEa1Y5bx41bv20K2cSzoQx+Xkzm0=; b=tXniS0Iwgab0oaVCYe2r4vPKcZ+SK8D6cRqBgujIxvVhNuwoLXCbh8/A9Ui9eaHaIK gKzWbPRmzYIc9DX5evLHXWbJFEodgckNRZ2S/IP1aZA4TYYIm4FpnfsjYisweDCqhPxU IpWNhm/lxBjekopsSAf5AtOwV34KUnSunf4HULAowBtNFcwgfcFdGXhovJrghjSumrKd ZemYBTz+EvdIP/MQMyt+23eEynZ9jN1bebbG/U6CD4sUt7bNHmbhjIVxaRGBcUbYEjQ8 kdY2/pZDgVfG3AGMXyZ8YZuAO/mShBamCE80q04bEpzVd42fagTKaVr64KETnRXTmEvW zLkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696969714; x=1697574514; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7JoAqvQEt6eH9DqcEa1Y5bx41bv20K2cSzoQx+Xkzm0=; b=iWWwt3CMGPTLvJcbGkZv0n9AikRzgSYzg1ggXuIWvaUF+Ztqo4VmW/w4UL4deo9Op0 gQrtudrPofD/paPCPJpL+73/JJA8unjoiLlisEHt16LadqEoB/oq+7ooAvodGGKNSWfb m6MA5q8yY6sMJ96dpFuH9v47IURaA6f45JGPcNzIGfZeQUsDmJ9GdO7JaZrqpM+fqBxf KtcEBcQQJF8fl1MZgczuSp9i2gW8B+9KlXGzHiv4hcRurViavB7U5wKoNLLBV66sT6q8 j8EE+QISsF7PRn2uBV+cczXKn11C0BbMX9S2XeO4jDfjhBUCahi9Ia7x/VJVZp5E9hJr qorQ== X-Gm-Message-State: AOJu0Ywg/prnXmHrgCFLCO3MClx+3t+ddJAtqGDGGJpRKc1P+lOKkKkx iK1I7B7y12peRQm9wVvLuDjvhEFN7Ih6O0uBVItQ3g== X-Google-Smtp-Source: AGHT+IFMJNpyPjuutYCWXJhQXe+nhGdrKqerW1hhVlRYpct9UOvDXz2j63jwLyzBY3s41HDDIROzMg== X-Received: by 2002:a0d:d4d3:0:b0:5a7:be23:6a7c with SMTP id w202-20020a0dd4d3000000b005a7be236a7cmr3275971ywd.6.1696969714259; Tue, 10 Oct 2023 13:28:34 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d1-20020a81ab41000000b0059511008958sm4555970ywk.76.2023.10.10.13.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 13:28:33 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org Cc: Sweet Tea Dorminy Subject: [PATCH 4/8] btrfs-progs: add inode encryption contexts Date: Tue, 10 Oct 2023 16:28:21 -0400 Message-ID: <1a456b16da0ab1dbf643e62235954d8a7de5e61a.1696969632.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Sweet Tea Dorminy Recapitulates relevant parts of kernel change 'btrfs: add inode encryption contexts'. Signed-off-by: Sweet Tea Dorminy --- kernel-shared/uapi/btrfs_tree.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel-shared/uapi/btrfs_tree.h b/kernel-shared/uapi/btrfs_tree.h index f49ae534..37869fea 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) From patchwork Tue Oct 10 20:28:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13416031 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 826CECD8CB6 for ; Tue, 10 Oct 2023 20:28:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343722AbjJJU2i (ORCPT ); Tue, 10 Oct 2023 16:28:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343647AbjJJU2h (ORCPT ); Tue, 10 Oct 2023 16:28:37 -0400 Received: from mail-yw1-x1131.google.com (mail-yw1-x1131.google.com [IPv6:2607:f8b0:4864:20::1131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4B26E94 for ; Tue, 10 Oct 2023 13:28:36 -0700 (PDT) Received: by mail-yw1-x1131.google.com with SMTP id 00721157ae682-579de633419so74863367b3.3 for ; Tue, 10 Oct 2023 13:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1696969715; x=1697574515; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Eg5fs+zEanWgTMZW9LpTtVG6BeK+nTh05mS+PcssrsM=; b=vfuDDgXvC+gKizX4WJQ6KQXdv6WUmycv8nkrefsrMT40AQDehiNLbaV3E+0QoFpjty CFzpkKKeA9f5NYhaRX1LgFDynEWzEN7yLR6pBQTsoPCNCHH8gHdNJJPrSoL/fnrgu4jD TxWT9yJZy7mX8nT8nsjbih13nJ2EQw1/ZRZPIpuH+RkkReZO9ov+/dpGO1QKfJ1LHJh3 +IXZSuxoo3i/MyT9e65HQLfw9h7BIiRDg26F6Zq4LN926uWdo13fQWfEfEr/apydQ/XF R28iYq/lC+SrFMNsagEZoTJlmNWev1tqUohQeAKFq1ns3ZHi7o8BRUGz9ec4h9rMAMDP xumQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696969715; x=1697574515; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Eg5fs+zEanWgTMZW9LpTtVG6BeK+nTh05mS+PcssrsM=; b=nc/E1cNVafk5I0FwYpiuKYpNE8r8WsjFHnJkx2icmN6QmKkRPwrDYC3a6XSRBndUO1 qMfcOGIHVNwVeJzJIjN2cfYOLLMNOBFJ5G+BcYOHPgkHqWKGpN/JrPjzqkRuJDZ4FMcO yqCxHU1SdpjP4X53jnli5L4bsQYUn6bcFb6Zc7jgosYjdCKAe/eCAVF88mZTN3AyMAIZ 6o24HKXhPRibFmzkmfsXX6D7snQZdaWioJAMZxBhqN29NR91IAqrGNC2Nkbk3e0Wmwmd 1XWb/+waO0wBgtoVNVX+hEzAHNCZGEAX9LDaq0oEtgkpDoC60mwhHLij18PW/tjzCplH SLGA== X-Gm-Message-State: AOJu0Ywkct9iUsUPET5iG0s8TC2EaA3xWnI32RzXBIEbvZ+DyEUTdrds BEUsOXUCtSQAkTjwKCKHBNSwgYXoA5lc+Dp/bsEXmQ== X-Google-Smtp-Source: AGHT+IET4WU6w8+xEwrCFyCAdGxVA+aqpquGGHoUJgobZLWgnRAYl6/y4ZtrdKKFMcJOPOamu1iAug== X-Received: by 2002:a81:bb48:0:b0:59e:8f6d:92e with SMTP id a8-20020a81bb48000000b0059e8f6d092emr17913484ywl.49.1696969715257; Tue, 10 Oct 2023 13:28:35 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d184-20020a0ddbc1000000b00586108dd8f5sm4600868ywe.18.2023.10.10.13.28.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 13:28:34 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org Cc: Sweet Tea Dorminy Subject: [PATCH 5/8] btrfs-progs: interpret encrypted file extents. Date: Tue, 10 Oct 2023 16:28:22 -0400 Message-ID: <92d67445dd292368cf8b67a0efb8af8d9f46c7ad.1696969632.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Sweet Tea Dorminy 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 | 12 +++++++++--- kernel-shared/print-tree.c | 25 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/check/main.c b/check/main.c index 0979a8c6..e841ae9c 100644 --- a/check/main.c +++ b/check/main.c @@ -1698,7 +1698,6 @@ static int process_file_extent(struct btrfs_root *root, rec->errors |= I_ERR_BAD_FILE_EXTENT; if (extent_type == BTRFS_FILE_EXTENT_PREALLOC && (btrfs_file_extent_compression(eb, fi) || - btrfs_file_extent_encryption(eb, fi) || btrfs_file_extent_other_encoding(eb, fi))) rec->errors |= I_ERR_BAD_FILE_EXTENT; if (compression && rec->nodatasum) @@ -6352,6 +6351,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; + size_t extra_size = 0; inline_offset = offsetof(struct btrfs_file_extent_item, disk_bytenr); @@ -6487,13 +6487,19 @@ static int run_next_block(struct btrfs_root *root, continue; /* Prealloc/regular extent must have fixed item size */ + if (btrfs_file_extent_encryption(buf, fi)) + extra_size = btrfs_file_extent_encryption_info_size(buf, fi) + + sizeof(struct btrfs_encryption_info); + if (btrfs_item_size(buf, i) != - sizeof(struct btrfs_file_extent_item)) { + (sizeof(struct btrfs_file_extent_item) + + extra_size)) { ret = -EUCLEAN; error( "invalid file extent item size, have %u expect %zu", btrfs_item_size(buf, i), - sizeof(struct btrfs_file_extent_item)); + sizeof(struct btrfs_file_extent_item) + + extra_size); continue; } /* key.offset (file offset) must be aligned */ diff --git a/kernel-shared/print-tree.c b/kernel-shared/print-tree.c index d7ffeccd..859eb015 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -356,6 +356,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 policy = btrfs_file_extent_encryption(leaf, fi); + u32 ctxsize = btrfs_file_extent_encryption_ctx_size(leaf, fi); + const __u8 *ctx = (__u8 *)(leaf->data + + btrfs_file_extent_encryption_ctx_offset(fi)); + + 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 +392,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 +429,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 Oct 10 20:28:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13416032 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 56B2CCD8CB7 for ; Tue, 10 Oct 2023 20:28:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234461AbjJJU2k (ORCPT ); Tue, 10 Oct 2023 16:28:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343780AbjJJU2j (ORCPT ); Tue, 10 Oct 2023 16:28:39 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 549E791 for ; Tue, 10 Oct 2023 13:28:37 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-d89ba259964so6696985276.2 for ; Tue, 10 Oct 2023 13:28:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1696969716; x=1697574516; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/u46hLMNS4RzQTNNSS2Qms4cPdJOoCgyXOu0Gun9Lx4=; b=ytV3W6JNz6ZKUO5mufZTotLHBOy1MPxbH4PJJB1AvlwMFlO4EKdKn+5B3ZonPFYdno 1hROhl13lgjPfjzTvpXjGLXEmwP74fPXZBnFPEhlVs9GYlW0JQ0kwWjcPyKT+OdKC6TH f6+vP6F64RmYGHpZh/SsXa9GB7RsW4Ga/XtrzCzTeY6qxVpsfsmBK0vkkK7Fquosblrk NlastNUuOzfXdNdYIavYwdG8OZDpwgTUfz2Qs28WBxsR4EoSi/UFj1D3UVTQNNi5SdcW VPfgzhHjeylZotYzF3Af+O6CXza7VWvYPe8GdKqWkQf3geOOR1vNrNkS5gaXejLDYOTW LDAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696969716; x=1697574516; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/u46hLMNS4RzQTNNSS2Qms4cPdJOoCgyXOu0Gun9Lx4=; b=NL8jKq57wULMXLqbw42nL3drV+MZGo7Ij+aatMoNr1N5EZDV1DZhsJEMowq5WLOEb8 q0ZKgH1tnA9qmUg7g9bF929RK0L/fL6ZuXz4ZuTFoyKHQvtv3AEtrVSfEB7XRmJ7iCEJ yXjpx30gO4DX2FFOQn/5mR8iprPmMSYaaKQN7hjFIbZIqq12+thLzOSfY6tLOJ/c/syv a9WgPr7HZW1kF9oyO/Zmpb9k3GQAaE6tLDyoSG0fVTT3636zeHKBkbKwT+qn1Un6Hall waYnxeg/KI4zS2pZajpyac2xwT+E6TVQ8SebNVR6vYVU9W6Lei8tG6W8ybP02lmzbdEW E5YA== X-Gm-Message-State: AOJu0YxJbFg8jWLF2JqxAuvPyQ27xYRxniOVSI/HVISDUbRp8xzPdRZi C4oKi2F7IZk6hl1fME89L87oFG02yLovLkRZOOxgYQ== X-Google-Smtp-Source: AGHT+IGSYOgg6mvEEvY8ZdqygBr3mK7VC5uiP4byirqBZKXCI1XlLmgQnOwqcDcTWMQokVrDtte7Mw== X-Received: by 2002:a25:abef:0:b0:cfd:58aa:b36e with SMTP id v102-20020a25abef000000b00cfd58aab36emr19728700ybi.9.1696969716358; Tue, 10 Oct 2023 13:28:36 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 127-20020a250885000000b00d7465a90f0csm3995271ybi.22.2023.10.10.13.28.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 13:28:36 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org Cc: Sweet Tea Dorminy Subject: [PATCH 6/8] btrfs-progs: handle fscrypt context items Date: Tue, 10 Oct 2023 16:28:23 -0400 Message-ID: <6c0ce0af24a2e19de2ce0e451dc949971779a3d9.1696969632.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Sweet Tea Dorminy 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 859eb015..38086275 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -99,6 +99,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) { @@ -673,6 +687,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", @@ -1393,6 +1408,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 Oct 10 20:28:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13416033 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 283C1CD8CB8 for ; Tue, 10 Oct 2023 20:28:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230141AbjJJU2l (ORCPT ); Tue, 10 Oct 2023 16:28:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234442AbjJJU2k (ORCPT ); Tue, 10 Oct 2023 16:28:40 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 430DAAC for ; Tue, 10 Oct 2023 13:28:38 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-d90da64499cso6665004276.0 for ; Tue, 10 Oct 2023 13:28:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1696969717; x=1697574517; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7TiFA2tlBh5ynC20r8LqCQ79wIpbpnZvS1/ifeJfrw0=; b=kuyGk9NT1Ma25pohl9uta0T3A1FDE62p3r4ZxR6oJeffEeG4SO2LqOokpOFlN4UDZG npzCgzLDbg5QVESymd9BHR/GE2Lk5X41r9ys8CKWnmQwXunvi11TgnLDxW912yT3jdIU 3STKkcQWa2NrNV2287NiCxONy9IrpxOGm7WsTttm5w8YzMQSBO0QPR3gnGgFnjF6ycrx 3QSkYzDLlv9aruryjaLETw16E0EeicPaV3MoRKfOGJ4rb/KhUwBBKq2S0JKYJPoVi/jJ kqDGo0MLZl/eOIHpEDHgIAuLsGhWU2JfCEF1iQXl/9i6CTnYPvKGtWUgj0wePlUgx0V5 rbcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696969717; x=1697574517; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7TiFA2tlBh5ynC20r8LqCQ79wIpbpnZvS1/ifeJfrw0=; b=d7958N5IEi60drgEBcjYNtD5wAu+6Q9WOhFtkyjXleP9Epw+aLZz3oy8d4zT3Py3HK vCQnVu/FxxJ+021IFwGdi/kBdYJKQ535vOCy2kruqYsaBnt5lr9W9i68+EqCaeX9pji2 oPPh7GIAT9/eNhTyGvq2fvM/QMS2PAbf8RSA0knMryTMuzcj/V5Y/yxKJPa+7HN9dWzp 0MiG+c38H0WDjkgeSI8gFypjhtiMR9ewS8RiczG3QIrAIW28ZoROW91j1qeiEqI2dW6s +kkTS3uU8xbZ8G7gJzMTpZUB2hjCZapzHQfqzqHjjQWSNaFT+Te3S8KxhyhjInp170BC FYTg== X-Gm-Message-State: AOJu0YwUmXOgr0lNVWxtKINHPchfmO7eKhLiCmtcwhLsISLMM8VxdZgH L9iwvLYt2H7Rhd5iEbj7UaeL/NGv4P8KxJbMHU9LAA== X-Google-Smtp-Source: AGHT+IEQis5Oy/EdWfgdP1tJ4QrBpBf7n2iH0lvxAjmkiO6ZSBR0lTJr2kgjMs0sj2r/JMahYcmVLw== X-Received: by 2002:a25:9302:0:b0:d9a:36f6:fa61 with SMTP id f2-20020a259302000000b00d9a36f6fa61mr4287494ybo.42.1696969717378; Tue, 10 Oct 2023 13:28:37 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id b33-20020a25aea1000000b00d8179f577basm4011322ybj.49.2023.10.10.13.28.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 13:28:37 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org Cc: Sweet Tea Dorminy Subject: [PATCH 7/8] btrfs-progs: escape unprintable characters in names Date: Tue, 10 Oct 2023 16:28:24 -0400 Message-ID: <4db28c419c3fbd6337034e9ae25d3fb234b81a41.1696969632.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Sweet Tea Dorminy 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 38086275..9aa1ce16 100644 --- a/kernel-shared/print-tree.c +++ b/kernel-shared/print-tree.c @@ -30,6 +30,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) { @@ -79,7 +92,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) { @@ -137,7 +150,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; @@ -167,7 +180,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 Oct 10 20:28:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13416034 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 8C5E2CD8CB4 for ; Tue, 10 Oct 2023 20:28:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234466AbjJJU2m (ORCPT ); Tue, 10 Oct 2023 16:28:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229448AbjJJU2k (ORCPT ); Tue, 10 Oct 2023 16:28:40 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41006AF for ; Tue, 10 Oct 2023 13:28:39 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id 3f1490d57ef6-d81d09d883dso6680555276.0 for ; Tue, 10 Oct 2023 13:28:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1696969718; x=1697574518; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4LzDGmpMBZ38H2nIF78o0VPhtObXIvEqVfGZY9bSPdI=; b=OYYPG6dBiQmDEuqQWn6UZJ53aIrk0+dkAVMK8aHV6UmD3sA6/Z/4DkCGidiVYLqNXk A9Lte02U0rwCq7ZMbqAhSoL6Za8qI8NjxDEP+5T1CL6RRFYjW8PNavv3wKLbyxv22YVS iHc2C1hRTu8HKRtT2fa88Iy34BC6ZE8gJh6pRrvXbeEl6fxiBNcemkW6cFjmgdI4rN1L 3vdjlVIzFCaJst+s12cOTW9xGuPxTBcNyLx5ykWuP45TCHffyoKPv2P0lAAC4U3Msan6 Cn5z7hF1e2YqJKHbwi5BcrD/X8a5BiPYrUwjCchpRDO49blhVDB3Pb0cROo9gNjtC5rC Hc3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696969718; x=1697574518; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4LzDGmpMBZ38H2nIF78o0VPhtObXIvEqVfGZY9bSPdI=; b=hPV4gmp+gOWDF0X31Dlox2nr4yev2XL3GJqcRh2otgQsPGXuuOd7aa61OkgkxuNN9R UoebuMYc2jmESFul9eHu8Xss5ZSTxI//KViJVFVabYdpzrLHyz+FgBhIKNNeR954/mGv R4ANyfRFvW68ASjBSgSXNGTjZDX4nY9kRmqo5obGF2ttOndA3fYawpPTRqNHWZcVRQLS oSJzlj7Gozm5JY6uxqbUN53+GzZ5YTZBdHdpe3P4KfhywOgmve1Z7xzcNjqrWAb4hWGR HYuA0laN034SlyxhUJ3b9iuk93Kv0AB8E5SyEaSxye5M7c3znQ5AkSfAxwc3GyrMKSI5 FPUQ== X-Gm-Message-State: AOJu0YwY+2Pj2Q4UIKrHWBuahnF41pzdKzyNxHB/sGe5OOayQs5YZole zWI5iyC7jJyuXaGY0/vKAlegy1WpdHJ4gh5Hkp0HXA== X-Google-Smtp-Source: AGHT+IGgQJwBQyhuK7PXD6nKqfhqsJT5koHkeOnNj7pV5vmE40+FTvdpJIQtWQVF3UyV6aSoN02fLA== X-Received: by 2002:a25:a029:0:b0:d74:62df:e802 with SMTP id x38-20020a25a029000000b00d7462dfe802mr16776448ybh.0.1696969718361; Tue, 10 Oct 2023 13:28:38 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id t29-20020a252d1d000000b00d746487d6f7sm615737ybt.35.2023.10.10.13.28.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 13:28:38 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org Cc: Sweet Tea Dorminy Subject: [PATCH 8/8] btrfs-progs: check: update inline extent length checking Date: Tue, 10 Oct 2023 16:28:25 -0400 Message-ID: <5741808b5b32ad9d7671f59fbfc8524867407c3d.1696969632.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org From: Sweet Tea Dorminy 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 e841ae9c..a8c4c7cf 100644 --- a/check/main.c +++ b/check/main.c @@ -1642,7 +1642,7 @@ static int process_file_extent(struct btrfs_root *root, u64 mask = gfs_info->sectorsize - 1; u32 max_inline_size = min_t(u32, gfs_info->sectorsize, BTRFS_MAX_INLINE_DATA_SIZE(gfs_info)); - u8 compression; + u8 compression, encryption; int extent_type; int ret; @@ -1667,25 +1667,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);