Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp3644563ima; Mon, 4 Feb 2019 02:42:52 -0800 (PST) X-Google-Smtp-Source: ALg8bN6p4bg95Q/itrpV8nm10yI6ivaOGmNIySuNhQDQWeTC4+W+CSouxWFr1YCtCJgur8c79Dva X-Received: by 2002:a17:902:934a:: with SMTP id g10mr48646501plp.172.1549276972495; Mon, 04 Feb 2019 02:42:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549276972; cv=none; d=google.com; s=arc-20160816; b=wTFiDHpnVyC/ztzNdyCTxNUtinTv0tl/5U8G1wMkGTVjZbcAdhFP4b0+uxVw/EvToB C6FAJf4FSbx5dqFVZmSuKuQo76xcsFUYtYw1GtL2/ITmUV0uxht8yGZMYvrr2Al0X5lJ IdVtjGoW2uy6IgKVrsrP+cJoFhaYMxihCy80z63WRVuT67NORE3YfKCVtGYlBE4qDJWA amb4+koGigBu43tEgfyJhcr6qNu4Mzt11WtIzrTtf3JwJwoR17rztfvveivR+ThQXAkR pIS7hmPLzfLRhdi2fXTGvXX9XRVQTw9E0L4Bf3yaIBN5DBntMQVvdT9gQeFYyEU55wfz DkzQ== 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=AWQ1U/a7NarXltwj0qalf3FqqmgzC/Hkd5k7mbx8zh0=; b=qz4tRcAEMd9V5kVZ0n0fwW+L4/SFKdBXxF3dpkjhVavz01hVcZL5gdGMXqQDzjnkP5 RBcO4zQMvBJmJor2OZjTKYM+8Qui3+scKuTHJuda0ia0wFeUjdXq5avKFG9c3dawHXpZ Ho89EAyxiRm8EnFJi8NWdglVfh/RWq0mYrYG925EuEZj2947lcfKthcU+4cLwDZcS3R7 bNJncEmXiCtFPYX6eNiGJpJ97Rgrm3tD1kUKDg8Kgpj5V02x835glkYny6Ezh79tocor vdQ8n8rEiGVXU/5OsURBtaTku/7GMoyebfLW++azFOis4wYvoz4UQUEonfYtuB5xGOXz g3AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=tEyfyi0P; 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 32si6631331pls.84.2019.02.04.02.42.36; Mon, 04 Feb 2019 02:42:52 -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=tEyfyi0P; 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 S1730339AbfBDKll (ORCPT + 99 others); Mon, 4 Feb 2019 05:41:41 -0500 Received: from mail.kernel.org ([198.145.29.99]:39596 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729713AbfBDKlj (ORCPT ); Mon, 4 Feb 2019 05:41:39 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 2A71D2176F; Mon, 4 Feb 2019 10:41:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549276898; bh=6rfpUyAY7X+luXPj//G/GebsZ3ZEIEFDdMJVmX4jgB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tEyfyi0Prk0oMAw7ablEX3xKTq+Mc0H6LcPnd4GMBLroCSLJ8Ns17ef8OkSeBRw41 vEK63XkzmNrtzaLY1sj29n7sB1ts0r4mVbLAbzojFox/ffuLh/P9wKHyb5WJc9P5Ym TUjoyQ+EvX1N8Yj3u8FJutwnBAMX05WdonFhN/Lg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Steve French , Paulo Alcantara , Pavel Shilovsky Subject: [PATCH 4.4 52/65] cifs: Always resolve hostname before reconnecting Date: Mon, 4 Feb 2019 11:36:45 +0100 Message-Id: <20190204103619.236355994@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204103610.583715954@linuxfoundation.org> References: <20190204103610.583715954@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore 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 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paulo Alcantara commit 28eb24ff75c5ac130eb326b3b4d0dcecfc0f427d upstream. In case a hostname resolves to a different IP address (e.g. long running mounts), make sure to resolve it every time prior to calling generic_ip_connect() in reconnect. Suggested-by: Steve French Signed-off-by: Paulo Alcantara Signed-off-by: Steve French Signed-off-by: Pavel Shilovsky Signed-off-by: Greg Kroah-Hartman --- fs/cifs/connect.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -48,6 +48,7 @@ #include "cifs_unicode.h" #include "cifs_debug.h" #include "cifs_fs_sb.h" +#include "dns_resolve.h" #include "ntlmssp.h" #include "nterr.h" #include "rfc1002pdu.h" @@ -304,6 +305,53 @@ static int cifs_setup_volume_info(struct const char *devname); /* + * Resolve hostname and set ip addr in tcp ses. Useful for hostnames that may + * get their ip addresses changed at some point. + * + * This should be called with server->srv_mutex held. + */ +#ifdef CONFIG_CIFS_DFS_UPCALL +static int reconn_set_ipaddr(struct TCP_Server_Info *server) +{ + int rc; + int len; + char *unc, *ipaddr = NULL; + + if (!server->hostname) + return -EINVAL; + + len = strlen(server->hostname) + 3; + + unc = kmalloc(len, GFP_KERNEL); + if (!unc) { + cifs_dbg(FYI, "%s: failed to create UNC path\n", __func__); + return -ENOMEM; + } + snprintf(unc, len, "\\\\%s", server->hostname); + + rc = dns_resolve_server_name_to_ip(unc, &ipaddr); + kfree(unc); + + if (rc < 0) { + cifs_dbg(FYI, "%s: failed to resolve server part of %s to IP: %d\n", + __func__, server->hostname, rc); + return rc; + } + + rc = cifs_convert_address((struct sockaddr *)&server->dstaddr, ipaddr, + strlen(ipaddr)); + kfree(ipaddr); + + return !rc ? -1 : 0; +} +#else +static inline int reconn_set_ipaddr(struct TCP_Server_Info *server) +{ + return 0; +} +#endif + +/* * cifs tcp session reconnection * * mark tcp session as reconnecting so temporarily locked @@ -400,6 +448,11 @@ cifs_reconnect(struct TCP_Server_Info *s rc = generic_ip_connect(server); if (rc) { cifs_dbg(FYI, "reconnect error %d\n", rc); + rc = reconn_set_ipaddr(server); + if (rc) { + cifs_dbg(FYI, "%s: failed to resolve hostname: %d\n", + __func__, rc); + } mutex_unlock(&server->srv_mutex); msleep(3000); } else {