From patchwork Thu Oct 20 16:58:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sweet Tea Dorminy X-Patchwork-Id: 13013798 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 822DEC43217 for ; Thu, 20 Oct 2022 16:59:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229919AbiJTQ7q (ORCPT ); Thu, 20 Oct 2022 12:59:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230013AbiJTQ7p (ORCPT ); Thu, 20 Oct 2022 12:59:45 -0400 Received: from box.fidei.email (box.fidei.email [71.19.144.250]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE98B360A6; Thu, 20 Oct 2022 09:59:37 -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 F3DF7811D3; Thu, 20 Oct 2022 12:59:35 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1666285176; bh=DTJozN52PHFej+KPgzm0Zb8eOu7K4iupMc8ZqDQmvsQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BS7emtTUbU/FcUnthvkyBwsXvDMpbKFV70umk6WzS3ZuGiWpWqQbMVai1PgFTUiao zcBbpbmRMlZz2YrisZ89UZYpkW57YFKaNAlFAfnhCADWCdBi3EheEpmNjWsFNkmHm2 s1wy/QcP5VD9WiV0h4fE6rcfqK6Rt3lMDI8xL27o2YxJCTsImistXYg+R8ui+Pu8jK l5DICEcs/eEUfI+6IWM3eLTzTmKxmxEH+b7wMwKRtzcWMxDJEJr/dvdHOeXpFOenwF mqQQo4D2XSclk8vGPmHKKpgng2bOMD+OnHS5Wu9fzAwK2I2OMtI98hdhskPS08sLGJ 89OYHivMdsItQ== From: Sweet Tea Dorminy To: "Theodore Y. Ts'o" , Jaegeuk Kim , Eric Biggers , Chris Mason , Josef Bacik , David Sterba , linux-fscrypt@vger.kernel.org, linux-btrfs@vger.kernel.org, kernel-team@meta.com Cc: Sweet Tea Dorminy Subject: [PATCH v3 19/22] btrfs: use correct name hash for nokey names Date: Thu, 20 Oct 2022 12:58:38 -0400 Message-Id: <7f83465a5a42e8098c71ac052ff17969f40913bc.1666281277.git.sweettea-kernel@dorminy.me> In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org For encrypted or unencrypted names, we calculate the offset for the dir item by hashing the name for the dir item. However, this doesn't work for a long nokey name, where we do not have the complete ciphertext. Instead, fscrypt stores the filesystem-provided hash in the nokey name, and we can extract it from the fscrypt_name structure in such a case. Signed-off-by: Sweet Tea Dorminy --- fs/btrfs/dir-item.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c index 039f473e27f4..d49bc19b91da 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c @@ -254,8 +254,12 @@ struct btrfs_dir_item *btrfs_lookup_dir_item_fname(struct btrfs_trans_handle *tr key.objectid = dir; key.type = BTRFS_DIR_ITEM_KEY; - key.offset = btrfs_name_hash(name->disk_name.name, name->disk_name.len); - /* XXX get the right hash for no-key names */ + + if (!name->disk_name.name) + key.offset = name->hash | ((u64)name->minor_hash << 32); + else + key.offset = btrfs_name_hash(name->disk_name.name, + name->disk_name.len); ret = btrfs_search_slot(trans, root, &key, path, mod, -mod); if (ret == 0)