Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2281303ybl; Thu, 19 Dec 2019 10:57:38 -0800 (PST) X-Google-Smtp-Source: APXvYqzi7rYlsAjlSdDqIBRL0VtOyKBl4T4W6+U3k8iOOhE/JNdJebJOe7xvDkp8jST4lk/YhKLz X-Received: by 2002:a05:6808:8d0:: with SMTP id k16mr2960608oij.68.1576781857981; Thu, 19 Dec 2019 10:57:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576781857; cv=none; d=google.com; s=arc-20160816; b=hRjboeL4XoRLlf47Rj71iRtKqmGeipW0ofFk8LpeUcbJVSiUcSR9bku8Z0VA6zg4xp vWQB+NlDUYrAnoYzQczCTVN6b7NRfwb4/D/u34u2YU8PjNLihaPW3hAOu5stJ2Tl4GG6 ep2iOcYLRzy/XdwS8HYHlt0KrgQuCeOpbPVisDWdebrkUsnqmBKU6atOsS0stVfsS+7c bBt9icdTorq35Y2s/7gGx3ZpfjL0gTFUEsnGsKzin9xaLxy9/vkAf059PBZVXhY8mHop 2NuralnDiFaKEqL05z92VYqIl6NEqOVzL2WPDGLP0RWR74fF8RTFNYpmDi9NFpyv8Beh a6vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=P6UeB7uUbyQbrfzRQMEbrrDi4L7+MnsGzvBaw6+huyQ=; b=n+9Xi++1dUfinJPrWm+EoPrfugXWQXtspuu0IfT68LGJ4P+NbhPcmLaIYUVE6ffHLv K3PFanvKwTf2nV/vv6AYRr6yIP8Fz0EoVipGMnxHqTuRxwUwKm4EFXGIUg6B9u8EQmmo lFJG6dWBPGqrgCh4zijQSEu90tlXnRkwfSyBlReRYODLa4Ik8ZBs8GLGB2ZEJBh7wPBq r41c8UgX0T/Fp7S8aAZDwiYnWUzycQ4P3VJmZn/RWvSTp0BS/fWy490MnlcV3iPaU1VG HS6Gu0UcrL7ux9cGu5QLE5miUcHL3TkVDZ4n7A0/3/++a8ABJ8oZQpsP6qgB9YLSoL6i lqSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rjXW3z8B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z11si3589003oic.119.2019.12.19.10.57.25; Thu, 19 Dec 2019 10:57:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=rjXW3z8B; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730811AbfLSS40 (ORCPT + 99 others); Thu, 19 Dec 2019 13:56:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:52854 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730797AbfLSS4T (ORCPT ); Thu, 19 Dec 2019 13:56:19 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 78830227BF; Thu, 19 Dec 2019 18:56:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576781778; bh=nUJQkdlrLbP8vid/uIYs8cG57aNUfqgBoXs6B9lMV8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rjXW3z8BWSTI+d/Pioz7F1ZuBgUobFjSlSG+aWgE1AES5UNgRVyw+sOrBoPO8KFfM 6BACPrEcoERdytH07gOc6rG0L+zURUiu3mVps+VCF5LWBZU09LrFoEOT4/EdWj5Tyl NJHQ7mXN2/GRkp0JV36WSBjy/clGGymjzTr+Rc50= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Paulo Alcantara (SUSE)" , Matthew Ruffell , Steve French Subject: [PATCH 5.4 38/80] cifs: Fix retrieval of DFS referrals in cifs_mount() Date: Thu, 19 Dec 2019 19:34:30 +0100 Message-Id: <20191219183107.931508671@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191219183031.278083125@linuxfoundation.org> References: <20191219183031.278083125@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Paulo Alcantara (SUSE) commit 5bb30a4dd60e2a10a4de9932daff23e503f1dd2b upstream. Make sure that DFS referrals are sent to newly resolved root targets as in a multi tier DFS setup. Signed-off-by: Paulo Alcantara (SUSE) Link: https://lkml.kernel.org/r/05aa2995-e85e-0ff4-d003-5bb08bd17a22@canonical.com Cc: stable@vger.kernel.org Tested-by: Matthew Ruffell Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/cifs/connect.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -4709,6 +4709,17 @@ static int is_path_remote(struct cifs_sb } #ifdef CONFIG_CIFS_DFS_UPCALL +static inline void set_root_tcon(struct cifs_sb_info *cifs_sb, + struct cifs_tcon *tcon, + struct cifs_tcon **root) +{ + spin_lock(&cifs_tcp_ses_lock); + tcon->tc_count++; + tcon->remap = cifs_remap(cifs_sb); + spin_unlock(&cifs_tcp_ses_lock); + *root = tcon; +} + int cifs_mount(struct cifs_sb_info *cifs_sb, struct smb_vol *vol) { int rc = 0; @@ -4810,18 +4821,10 @@ int cifs_mount(struct cifs_sb_info *cifs /* Cache out resolved root server */ (void)dfs_cache_find(xid, ses, cifs_sb->local_nls, cifs_remap(cifs_sb), root_path + 1, NULL, NULL); - /* - * Save root tcon for additional DFS requests to update or create a new - * DFS cache entry, or even perform DFS failover. - */ - spin_lock(&cifs_tcp_ses_lock); - tcon->tc_count++; - tcon->dfs_path = root_path; + kfree(root_path); root_path = NULL; - tcon->remap = cifs_remap(cifs_sb); - spin_unlock(&cifs_tcp_ses_lock); - root_tcon = tcon; + set_root_tcon(cifs_sb, tcon, &root_tcon); for (count = 1; ;) { if (!rc && tcon) { @@ -4858,6 +4861,15 @@ int cifs_mount(struct cifs_sb_info *cifs mount_put_conns(cifs_sb, xid, server, ses, tcon); rc = mount_get_conns(vol, cifs_sb, &xid, &server, &ses, &tcon); + /* + * Ensure that DFS referrals go through new root server. + */ + if (!rc && tcon && + (tcon->share_flags & (SHI1005_FLAGS_DFS | + SHI1005_FLAGS_DFS_ROOT))) { + cifs_put_tcon(root_tcon); + set_root_tcon(cifs_sb, tcon, &root_tcon); + } } if (rc) { if (rc == -EACCES || rc == -EOPNOTSUPP)