Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp3647702ima; Mon, 4 Feb 2019 02:46:30 -0800 (PST) X-Google-Smtp-Source: ALg8bN4Pbe0Mie73BQQUeNk00G+pEsZTFOhfR06oHaqEascW7HXLpEloN4E7hZo9pSfeTRxA8pWK X-Received: by 2002:a62:34c6:: with SMTP id b189mr51779515pfa.229.1549277190523; Mon, 04 Feb 2019 02:46:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549277190; cv=none; d=google.com; s=arc-20160816; b=c4cNip1srWij4cOYTOrdZnas+XyXK9DYj9r6Tzzeqzko80sogJJVfh9Esxhav2ImFF 8eH9ghI6C+sgfWWYp4/sIkj7OuBMiHCl66S1YQto3PLdHATI5B0ufQBIYm83luk5laR8 EuYMMXUAFchCVG9EtI282bpmd3RVIQy0aM2bBl+qNtxTmOfpEDtjrSp92iRJcgZES+NW EDNN5oJ1GCBIyyc4xHHtxyvV8g9Slj7fAAUFcd1baes0Eh9SiZ0+Jb1cADtr9eO/HtdF NIYMov1e+OU5mMR9aB31DY4fV0s7WKfxady/w7//Sn8FkaCLDk+urck94lD8/RHWNfQy G4IQ== 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=NqBq2Lm58v1ZovG16+RTMYpcSqG+ARv4L5ElkyRGDHE=; b=sKR1je7LnRTYBNwW8nXLgZm4yUg8e7P/u20Me+9RZ5M8G+0xmAUJh8OmdvexnLtL6c RVdji1gLxm6SkGDivrgF+0axv44YuJGDCUM1wlOgbMTiJCiYDTGKnlUrp+j+TgtX6Z5w aN8N/MgiMOjIV34VxVET+/Q/NV5tusgNWNuNUKfTnL/5UBuPuLvrodFt/WDDcuxCB+82 Cz4ohKo+r/US9fFg4jnaBbUNurM/QKV42o8tD4bSK+hdTKBUFM5w6vY5jSfxPsyhGk5w wW6YpGe3p+Kt2vNcuT27l2cW/UB7o9Q8ROHlxpGl+EvydCMO4N1O8eKaNXW8dhWxlc9N T9Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="H/etelr1"; 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 c65si15856602pfe.202.2019.02.04.02.46.14; Mon, 04 Feb 2019 02:46:30 -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="H/etelr1"; 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 S1730913AbfBDKoI (ORCPT + 99 others); Mon, 4 Feb 2019 05:44:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:41912 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730904AbfBDKoH (ORCPT ); Mon, 4 Feb 2019 05:44:07 -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 AC1602176F; Mon, 4 Feb 2019 10:44:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549277046; bh=AGCopbv6BMuAN7X/AjqYNBPq+CuqCmIi/udBfkgk7Kc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H/etelr1LKpxAh5nhETh7mhYKlPCCYsH3rcq69rgB34PT5RAlJTyQ7uhi86/bii0o 86vGKIgu3uOxjiP9auIXde8tsMB8a+wtXtXQt/J3U92ayDZTD515PcXcR0ADXQlMtU fDe4A8WQvk9XmjkM87Z3myxsM2g1QVLH+C+ynixQ= 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.9 27/30] cifs: Always resolve hostname before reconnecting Date: Mon, 4 Feb 2019 11:37:05 +0100 Message-Id: <20190204103610.367598416@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204103605.271746870@linuxfoundation.org> References: <20190204103605.271746870@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.9-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" @@ -307,6 +308,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 @@ -403,6 +451,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 {