From patchwork Sun Jan 1 05:06:14 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: 13086305 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 84E2CC4167B for ; Sun, 1 Jan 2023 05:06:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232396AbjAAFGy (ORCPT ); Sun, 1 Jan 2023 00:06:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232429AbjAAFGv (ORCPT ); Sun, 1 Jan 2023 00:06:51 -0500 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 3DF18272A for ; Sat, 31 Dec 2022 21:06:49 -0800 (PST) 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 4CB8B82647; Sun, 1 Jan 2023 00:06:49 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1672549609; bh=kIBJVYH2JqSKtwNK1QBti5TNYAdm7cp7w0tqOZfFeZo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fxgx0hEHqqVEcnK6BIa/+pYem6g0O8j9J23+hUXjO/eDzvi6M7hh+/ECz7Up9fASz y6o7wXRgGLWa08X9mr5kMePPIOGN4+t0ITtx3iRSiEllAyjuzg1cHGgBu2+wXJDcZi nNu6Xu3RYWve/ghkpaSPn/yvzl9zv9uBoIewWw0ud89Xuv0ZUyIB8P06vAI0jMNJlU 62eXZHV1ZHhQ5mP2arJuidwPWOrZqYpxiJNK3mtRbJmte9A9KO+DricGHIOpy28yGr fFiZh2VXytIB+N+whS36XbyWGK/A6LAYgBjdGOSc07wRN25oPMctAxdlrZs8SqboBI YfgdAZ2vtb7gQ== From: Sweet Tea Dorminy To: linux-fscrypt@vger.kernel.org, ebiggers@kernel.org, paulcrowley@google.com, linux-btrfs@vger.kernel.org, kernel-team@meta.com Cc: Sweet Tea Dorminy Subject: [RFC PATCH 10/17] fscrypt: let fscrypt_infos be owned by an extent Date: Sun, 1 Jan 2023 00:06:14 -0500 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org In order to notify extents when their info is part of a master key which is going away, the fscrypt_info must have a backpointer to the extent somehow. Similarly, if a fscrypt_info is owned by an extent, the info must not have a pointer to an inode -- multiple inodes may reference a extent, and the first inode to cause an extent's creation may have a lifetime much shorter than the extent, so there is no inode pointer safe to track in an extent-owned info. Therefore, this adds a new pointer for extent-owned infos to track their extent and updates fscrypt_setup_encryption_info() accordingly. Since it's simple to track the piece of extent memory pointing to the info, and for the extent to then go from such a pointer to the whole extent via container_of(), we store that. Although some sort of generic void * or some artificial fscrypt_extent embedded structure would also work, those would require additional plumbing which doesn't seem strictly required or clarifying. Signed-off-by: Sweet Tea Dorminy --- fs/crypto/fscrypt_private.h | 6 ++++++ fs/crypto/keysetup.c | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/fs/crypto/fscrypt_private.h b/fs/crypto/fscrypt_private.h index 0c7b785f1d8c..dc45cd35391f 100644 --- a/fs/crypto/fscrypt_private.h +++ b/fs/crypto/fscrypt_private.h @@ -229,6 +229,12 @@ struct fscrypt_info { /* Back-pointer to the inode, for infos owned by a specific inode */ struct inode *ci_inode; + /* + * Back-pointer to the info pointer in the extent, for infos owned + * by an extent + */ + struct fscrypt_info **ci_info_ptr; + /* The superblock of the filesystem to which this fscrypt_info pertains */ struct super_block *ci_sb; diff --git a/fs/crypto/keysetup.c b/fs/crypto/keysetup.c index 04f01da900ca..c611e2613aa6 100644 --- a/fs/crypto/keysetup.c +++ b/fs/crypto/keysetup.c @@ -567,7 +567,11 @@ fscrypt_setup_encryption_info(struct inode *inode, if (!crypt_info) return -ENOMEM; - crypt_info->ci_inode = inode; + if (fscrypt_uses_extent_encryption(inode)) + crypt_info->ci_info_ptr = info_ptr; + else + crypt_info->ci_inode = inode; + crypt_info->ci_sb = inode->i_sb; crypt_info->ci_policy = *policy; memcpy(crypt_info->ci_nonce, nonce, FSCRYPT_FILE_NONCE_SIZE);