Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp3664080ima; Mon, 4 Feb 2019 03:04:36 -0800 (PST) X-Google-Smtp-Source: ALg8bN6zPTv/E1Bq7dew8+oiAF6z0IhZ/u/8gNexpzQhB74Zvew7B4LHY1LnK2z7t1maLTp5EJxc X-Received: by 2002:a62:fc52:: with SMTP id e79mr51222172pfh.8.1549278276605; Mon, 04 Feb 2019 03:04:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549278276; cv=none; d=google.com; s=arc-20160816; b=eb6A9dgeR2AtbxJMm6udncebHRyjfLn2h+qAZB27PSHevJoZ0wOhbp918Dh8Id8hML Amf0hOyZyCOd2fIApgrCPaFUUWpwdjRzmoHbjtyI24nyv34rVVRY7GcDWVElqK9grFQb ARgPHx5PDCMdh3F7K9Xqv3/SiPHDx+wGLUxvlI2hgQJSv121Q8EfdoplOOCLj45u6N32 OxZV/DCDgS3XDkz2mYRURKi7Icm2NOnZX7YGx3VeZyyHpMTz9ZbtvwMJTK5GEbWymMHW l08TcDKXTpwl8xsAYcTvLlMeu+u2CwI57/2spQhRkICTCaMUwG43RWDaVqBx61cKJtzm kX/Q== 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=p0pa2jDaQmWny9vLqC+vqNg0MhaDMVcIW1gFYLd4zg4=; b=V5GMydaPBdyNw1fCEcvlOu3u+WN/kQU2jUVkAQtRR8YioUdibQWk6Lt0v56OGQxeRu G/k+ZAwDa66kYg3aM/q1Chs1mEqQlCqTCtrB2DcMU0dh1BoshMSbJwPDA/ClGbG7MEZT YgmlJqwUkQkyIhAmUTIo5hk88s/92fghBI4MtFDLhXaM9RciWcLeUSFIp8ixYgODPF0m jQXwg9ECPBrXlDpvoTbHNcDM3M2RQcng8EVWrWvbbgRtgVLqZwHTcsgNuPPT/QTT3c0e JDW8ggotcTUs7dBAW2SqDPwb+AQ0vLeT5SCQmzT70uggcMJteCW87lVZuw6r1/hJyxZh BDxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=DduHUC5k; 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 q73si11732815pfi.205.2019.02.04.03.04.19; Mon, 04 Feb 2019 03:04:36 -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=DduHUC5k; 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 S1731969AbfBDLD2 (ORCPT + 99 others); Mon, 4 Feb 2019 06:03:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:44786 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730692AbfBDKqc (ORCPT ); Mon, 4 Feb 2019 05:46:32 -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 5E9312087C; Mon, 4 Feb 2019 10:46:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549277190; bh=Y4rt3+s0bGClf0+6/XIyTYJxdi/wSI/irW/K7eUhzFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DduHUC5kf+JODoPxKcty5a1NXSMhtrtCuMQBF3urddPUfH1CX3+BZ/yELMSCI9yn3 hBPPHxzhPyRpjO0Pr08XBK+9xMrG8iZ2bfqUyxovvEJ6lYCUvKXm/Dd/Lct/4AHQL4 9+3PlzqN/f6L0ACfrvftYBKVzTNn4obW0NQTSRck= 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.14 44/46] cifs: Always resolve hostname before reconnecting Date: Mon, 4 Feb 2019 11:37:15 +0100 Message-Id: <20190204103616.478506244@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204103608.651205056@linuxfoundation.org> References: <20190204103608.651205056@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.14-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 @@ -51,6 +51,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" @@ -314,6 +315,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 @@ -408,6 +456,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 {