From patchwork Tue Sep 26 18:01:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13399492 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 175F8EEB563 for ; Tue, 26 Sep 2023 18:03:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235490AbjIZSDo (ORCPT ); Tue, 26 Sep 2023 14:03:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235483AbjIZSDm (ORCPT ); Tue, 26 Sep 2023 14:03:42 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A9A610A for ; Tue, 26 Sep 2023 11:03:36 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-7741c5bac51so464102785a.1 for ; Tue, 26 Sep 2023 11:03:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20230601.gappssmtp.com; s=20230601; t=1695751415; x=1696356215; 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=w8WS35cLh6qwSpXHQaQofYAl31yNr6wevnopqXm/zJU=; b=KPxVnay9LNLGFNcDprER6uvHl9N5+5pMvqH4BCBbyPT2cMJqp0SaZuuKYRYgu/xq3v 9K8XUfN4HUHnTc6Zaty0duSxjOskoZpp/ExZINJNBsP1JlPO/9/ZyjLtmwpY/5OPGVmd kLXn94jV1OF3ELPm5SqPgkTP1r6QT5VWwrPtviVjMjZo+zOU4GLcZWqvzrwBREBW7aD7 WXaZD7MDaUNq+Li8FMcms5yk0B8g0TJQEgEs8RqWmZHZFLzjkW47tDnpX9jRht44VXzi 7OpuLPcW17Zve55WktOA8uKLqY3AzdboOLbzgEyq4lI90gw7DyJ57P1D8v9zyYhM4w8a ej1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695751415; x=1696356215; 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=w8WS35cLh6qwSpXHQaQofYAl31yNr6wevnopqXm/zJU=; b=uaSNu7LSYAsfcbiAl9UsQ5bzNQ0pM42iBbKENGROUUiwFMf8yTkWZLPQ3BrFpa1pXh PQaX9ECRUIGbzBwTakgCcPDnd4Dd3r5vw7rGF7/IgIgjWZlkm/e8x3ehDmCg0yWgXGyu 4r+0NgLtsYfPcKlZqeCggJ85pYN7QioCi0t9fkd0F59X+po+UMKfVUC2iDtzoUv5VVX+ WiBv/ZTJVYNTv/+LJHsM7vpTtaInwtwLUV5RQXYLvUoSkeVo1i4V4hCwxw01FLK2KGeu 6zj458eEvXndd0wgKFKD1Okn3mu5GGWIHWuwNmJ/XLMsApqCbn23dP/VHKVXuoDaNvzD qnsQ== X-Gm-Message-State: AOJu0YyFmn9ZOjdI7GL8R2lmlqDQM84SwMQaCXRTc/ARoruirAZ4Xk8C aLOeG5gbmzsE222n5L5yAQTWIRykv+aAzaZkVBwvBA== X-Google-Smtp-Source: AGHT+IFq0+UjXQqxQTELcq/6vffor5tzyIqIwNieYH/OAfGp/n/hGfspIQeg2WD2vGjrplarzJH5UA== X-Received: by 2002:a05:620a:4629:b0:773:bdb3:1318 with SMTP id br41-20020a05620a462900b00773bdb31318mr10395401qkb.15.1695751415046; Tue, 26 Sep 2023 11:03: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 c7-20020a05620a164700b0076d08d5f93asm4920623qko.60.2023.09.26.11.03.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 11:03:34 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com, ebiggers@kernel.org, linux-fscrypt@vger.kernel.org, ngompa13@gmail.com Cc: Sweet Tea Dorminy Subject: [PATCH 19/35] btrfs: set file extent encryption excplicitly Date: Tue, 26 Sep 2023 14:01:45 -0400 Message-ID: <2c6e10642b211a7a6fb20234273a7c627c5c0b44.1695750478.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 This puts the long-preserved 1-byte encryption field to work, storing whether the extent is encrypted. Update the tree-checker to allow for the encryption bit to be set to our valid types. Signed-off-by: Sweet Tea Dorminy Signed-off-by: Josef Bacik --- fs/btrfs/accessors.h | 2 ++ fs/btrfs/inode.c | 8 ++++++-- fs/btrfs/tree-checker.c | 8 +++++--- fs/btrfs/tree-log.c | 2 ++ include/uapi/linux/btrfs_tree.h | 8 +++++++- 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/fs/btrfs/accessors.h b/fs/btrfs/accessors.h index b780d9087490..5627f13a3d3e 100644 --- a/fs/btrfs/accessors.h +++ b/fs/btrfs/accessors.h @@ -951,6 +951,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); diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index ccbaeea68e2e..db053b392d26 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -2993,7 +2993,9 @@ static int insert_ordered_extent_file_extent(struct btrfs_trans_handle *trans, btrfs_set_stack_file_extent_num_bytes(&stack_fi, num_bytes); btrfs_set_stack_file_extent_ram_bytes(&stack_fi, ram_bytes); btrfs_set_stack_file_extent_compression(&stack_fi, oe->compress_type); - /* Encryption and other encoding is reserved and all 0 */ + btrfs_set_stack_file_extent_encryption(&stack_fi, + BTRFS_ENCRYPTION_NONE); + /* Other encoding is reserved and always 0 */ /* * For delalloc, when completing an ordered extent we update the inode's @@ -9640,7 +9642,9 @@ static struct btrfs_trans_handle *insert_prealloc_file_extent( btrfs_set_stack_file_extent_num_bytes(&stack_fi, len); btrfs_set_stack_file_extent_ram_bytes(&stack_fi, len); btrfs_set_stack_file_extent_compression(&stack_fi, BTRFS_COMPRESS_NONE); - /* Encryption and other encoding is reserved and all 0 */ + btrfs_set_stack_file_extent_encryption(&stack_fi, + BTRFS_ENCRYPTION_NONE); + /* Other encoding is reserved and always 0 */ qgroup_released = btrfs_qgroup_release_data(inode, file_offset, len); if (qgroup_released < 0) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 1f2c389b0bfa..c2afdf65c2bf 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -210,6 +210,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, @@ -261,10 +262,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) { diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c index cc262305f4c5..f6f45a0f1b1e 100644 --- a/fs/btrfs/tree-log.c +++ b/fs/btrfs/tree-log.c @@ -4630,6 +4630,7 @@ static int log_one_extent(struct btrfs_trans_handle *trans, u64 extent_offset = em->start - em->orig_start; u64 block_len; int ret; + u8 encryption = BTRFS_ENCRYPTION_NONE; btrfs_set_stack_file_extent_generation(&fi, trans->transid); if (test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) @@ -4651,6 +4652,7 @@ static int log_one_extent(struct btrfs_trans_handle *trans, btrfs_set_stack_file_extent_num_bytes(&fi, em->len); btrfs_set_stack_file_extent_ram_bytes(&fi, em->ram_bytes); btrfs_set_stack_file_extent_compression(&fi, em->compress_type); + btrfs_set_stack_file_extent_encryption(&fi, encryption); ret = log_extent_csums(trans, inode, log, em, ctx); if (ret) diff --git a/include/uapi/linux/btrfs_tree.h b/include/uapi/linux/btrfs_tree.h index 50c9e01a3cb4..dee650f0082c 100644 --- a/include/uapi/linux/btrfs_tree.h +++ b/include/uapi/linux/btrfs_tree.h @@ -1095,8 +1095,14 @@ struct btrfs_file_extent_item { * but not for stat. */ __u8 compression; + + /* + * Type of encryption in use. Unencrypted value is 0. + */ __u8 encryption; - __le16 other_encoding; /* spare for later use */ + + /* spare for later use */ + __le16 other_encoding; /* are we inline data or a real extent? */ __u8 type;