From patchwork Thu Mar 31 15:31:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeffrey Layton X-Patchwork-Id: 12797313 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 E05A4C433FE for ; Thu, 31 Mar 2022 15:34:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238911AbiCaPgO (ORCPT ); Thu, 31 Mar 2022 11:36:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238744AbiCaPfr (ORCPT ); Thu, 31 Mar 2022 11:35:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7DE762274DF; Thu, 31 Mar 2022 08:32:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 141D061AF2; Thu, 31 Mar 2022 15:31:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D319EC340F3; Thu, 31 Mar 2022 15:31:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1648740715; bh=fbH+iQjjahZKCGhi/iL6elcYJfj/gkysklT3Ay9geJI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HzEWQbx89+QvMXmw4NDQuRUBf8+I90qUcN2PkRsGXmw6JGbH7pdL9u7kqPVGh4b2Z UgBkPw/SkbKeVPwoC/BfQHcOBsfXMFeeO76yeo/uBV5APJWTSwbnYEfX1xm9D/rCCe dPPyLj/E9aTxlYo47YJffShF4bo34y/s3I6Bz0pNha8nIApI5KOFF9ZeMOMAb4dTQ+ gfQXn3XsOZZ+5ASP91yd9YZQa3MUNfkBHPZ2PGTV2wKuEliYpsilzOGx0aaDqM04V6 EQ/6joDfb1YL2jYVQ5Z4OpPYxR4rYzHVVWSq9ot6X+ULJRsnJbs7IVQg+25C066SvD 0F4NU82a5fS+A== From: Jeff Layton To: ceph-devel@vger.kernel.org Cc: xiubli@redhat.com, idryomov@gmail.com, lhenriques@suse.de, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v12 25/54] ceph: add fscrypt support to ceph_fill_trace Date: Thu, 31 Mar 2022 11:31:01 -0400 Message-Id: <20220331153130.41287-26-jlayton@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220331153130.41287-1-jlayton@kernel.org> References: <20220331153130.41287-1-jlayton@kernel.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org When we get a dentry in a trace, decrypt the name so we can properly instantiate the dentry. Signed-off-by: Jeff Layton --- fs/ceph/inode.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index c82a02ba6635..684dfc3f006c 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -1404,8 +1404,15 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req) if (dir && req->r_op == CEPH_MDS_OP_LOOKUPNAME && test_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags) && !test_bit(CEPH_MDS_R_ABORTED, &req->r_req_flags)) { + bool is_nokey = false; struct qstr dname; struct dentry *dn, *parent; + struct fscrypt_str oname = FSTR_INIT(NULL, 0); + struct ceph_fname fname = { .dir = dir, + .name = rinfo->dname, + .ctext = rinfo->altname, + .name_len = rinfo->dname_len, + .ctext_len = rinfo->altname_len }; BUG_ON(!rinfo->head->is_target); BUG_ON(req->r_dentry); @@ -1413,8 +1420,20 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req) parent = d_find_any_alias(dir); BUG_ON(!parent); - dname.name = rinfo->dname; - dname.len = rinfo->dname_len; + err = ceph_fname_alloc_buffer(dir, &oname); + if (err < 0) { + dput(parent); + goto done; + } + + err = ceph_fname_to_usr(&fname, NULL, &oname, &is_nokey); + if (err < 0) { + dput(parent); + ceph_fname_free_buffer(dir, &oname); + goto done; + } + dname.name = oname.name; + dname.len = oname.len; dname.hash = full_name_hash(parent, dname.name, dname.len); tvino.ino = le64_to_cpu(rinfo->targeti.in->ino); tvino.snap = le64_to_cpu(rinfo->targeti.in->snapid); @@ -1429,9 +1448,15 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req) dname.len, dname.name, dn); if (!dn) { dput(parent); + ceph_fname_free_buffer(dir, &oname); err = -ENOMEM; goto done; } + if (is_nokey) { + spin_lock(&dn->d_lock); + dn->d_flags |= DCACHE_NOKEY_NAME; + spin_unlock(&dn->d_lock); + } err = 0; } else if (d_really_is_positive(dn) && (ceph_ino(d_inode(dn)) != tvino.ino || @@ -1443,6 +1468,7 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req) dput(dn); goto retry_lookup; } + ceph_fname_free_buffer(dir, &oname); req->r_dentry = dn; dput(parent);