From patchwork Mon Oct 24 23:13:30 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: 13018370 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 D65C6C67871 for ; Tue, 25 Oct 2022 00:42:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229832AbiJYAmu (ORCPT ); Mon, 24 Oct 2022 20:42:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34510 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230525AbiJYAmX (ORCPT ); Mon, 24 Oct 2022 20:42:23 -0400 Received: from box.fidei.email (box.fidei.email [71.19.144.250]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A09F31DEA; Mon, 24 Oct 2022 16:14:17 -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 6B8B581308; Mon, 24 Oct 2022 19:14:16 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=dorminy.me; s=mail; t=1666653256; bh=XHH1uogd6ho7h/w7R3kxnHFjMN6kEy35unxxY/PVHJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A4wpKX2R8H1OYfbi1AVx8gMDiI1wxKfgl/+iw///paWS4eGUkNqK8xkoRUBynpICp IeRPIKDnsA8BVlOqAslqqjEIeQC0U9pHhjjfkOsU9b/qyRnL/RPTUDLIbTwGrEJy38 AtLllABG2gySNI0N3e6GtGQI5NOxMFdiUmWmR1b5vflvXi1HxHMoRkJEHo/lYasArx D7qlEqqfm3wIuAFqvhihFWKqVhQi3U8QSbP5iivjmQVLmqu6GKalZ9WAMiyGelxMO/ LHfMNCHExRAY04iG1FAKqek6jVz1iqwA++ujA6U+l7jK/6YyLwQ2MCciz7MxlXzVSD cUbFczNxehApQ== 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 v4 20/21] btrfs: use correct name hash for nokey names Date: Mon, 24 Oct 2022 19:13:30 -0400 Message-Id: <55e2bd7c38a3b18c33b67c33bd2608a2364ad41b.1666651724.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 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 d5275475e69e..11236ebdb07f 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c @@ -256,8 +256,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)