From patchwork Tue Apr 16 12:52:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 10902931 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 483A41669 for ; Tue, 16 Apr 2019 12:53:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9356287C5 for ; Tue, 16 Apr 2019 12:52:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DBF47287D1; Tue, 16 Apr 2019 12:52:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EF12287C5 for ; Tue, 16 Apr 2019 12:52:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727633AbfDPMw6 (ORCPT ); Tue, 16 Apr 2019 08:52:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:51990 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726907AbfDPMw6 (ORCPT ); Tue, 16 Apr 2019 08:52:58 -0400 Received: from tleilax.poochiereds.net (cpe-71-70-156-158.nc.res.rr.com [71.70.156.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id A7E7E205ED; Tue, 16 Apr 2019 12:52:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555419177; bh=cgmnpUYN59xRLt29SVBJOm5HkbEX+Qt0L0c273Tr1J0=; h=From:To:Cc:Subject:Date:From; b=NamviCY0QlnVH8otT2eroFMPCnEYvGKln9Y8fGg9SZq6QMrvw6c9amwjRMG2rEBH0 qDtAYu3FeSlFqecrj1lMP79sJ9FvQEurmyFwJdBVh/RcBdFKinnDu7rSJtbwGJ9rHB 64ca81GsctntNDPQdv8VOyVV7ByWaZujtJr3UaPc= From: Jeff Layton To: zyan@redhat.com, sage@redhat.com, idryomov@gmail.com Cc: ceph-devel@vger.kernel.org Subject: [PATCH] ceph: use d_lock to protect dentry name in ceph_fill_trace Date: Tue, 16 Apr 2019 08:52:55 -0400 Message-Id: <20190416125255.10212-1-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP It's not safe to run strncmp on the dentry name locklessly like this, as it could end up being altered via rename. Add a helper function that takes the d_lock in order to do the comparison. Signed-off-by: Jeff Layton Reviewed-by: "Yan, Zheng" --- fs/ceph/inode.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/fs/ceph/inode.c b/fs/ceph/inode.c index b33ba16f7ae8..9c93c108180d 100644 --- a/fs/ceph/inode.c +++ b/fs/ceph/inode.c @@ -1163,6 +1163,18 @@ static int splice_dentry(struct dentry **pdn, struct inode *in) return 0; } +static bool +dentry_is_snapdir(struct ceph_fs_client *fsc, struct dentry *dentry) +{ + int ret; + + spin_lock(&dentry->d_lock); + ret = strncmp(dentry->d_name.name, fsc->mount_options->snapdir_name, + dentry->d_name.len); + spin_unlock(&dentry->d_lock); + return !ret; +} + /* * Incorporate results into the local cache. This is either just * one inode, or a directory, dentry, and possibly linked-to inode (e.g., @@ -1285,9 +1297,8 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req) if (rinfo->head->is_dentry && !test_bit(CEPH_MDS_R_ABORTED, &req->r_req_flags) && test_bit(CEPH_MDS_R_PARENT_LOCKED, &req->r_req_flags) && - (rinfo->head->is_target || strncmp(req->r_dentry->d_name.name, - fsc->mount_options->snapdir_name, - req->r_dentry->d_name.len))) { + (rinfo->head->is_target || + !dentry_is_snapdir(fsc, req->r_dentry))) { /* * lookup link rename : null -> possibly existing inode * mknod symlink mkdir : null -> new inode