From patchwork Tue Jan 4 12:33:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1575225 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=EUVR3VYL; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSsVk6fdLz9t25 for ; Tue, 4 Jan 2022 23:34:06 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1n4j0p-0005x5-22; Tue, 04 Jan 2022 12:33:59 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1n4j0n-0005wb-9o for kernel-team@lists.ubuntu.com; Tue, 04 Jan 2022 12:33:57 +0000 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 181163F0EA for ; Tue, 4 Jan 2022 12:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1641299637; bh=XofOGHETTHEVh5dPcmgrZOvlfhG7QdfVAHoAB1cPthI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=EUVR3VYLBmEdmcEyZetz5X5I+uhebnPNr0gpRizbOE1K2mvQf5ZiWrnUPr4bKOka2 VSutsGkXGIDTiFLJ3YMbM1HpJbh55bYUtKb0v83Yk2sx2ykuFAfYIA9503hbKdPTnJ baXNxg9aTuBuABu+wUi0Asj34Uvjpm3b+yncVpMl4cVgg0gv1baqakVygFIkC5zQQF j6PUtlAeN9+Xm/V81sYlYda/4royZNGo7ihJ8r9TrGLvM42PTK/A1XGK0+51IYSoH0 PkQsWUgGcctClMuni8IL8xeFad0wIDPxYY6P8Pq5gh3BlKtDVtKbelIuirlET5GpeX SLkjrbkryp3Rg== Received: by mail-pj1-f72.google.com with SMTP id a4-20020a17090a70c400b001b21d9c8bc8so25888785pjm.7 for ; Tue, 04 Jan 2022 04:33:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XofOGHETTHEVh5dPcmgrZOvlfhG7QdfVAHoAB1cPthI=; b=wyCMsm0/VFIZsoFCcPdL5hsYae1PyXbiUV24hDucUL++Hd+UnHfeoBdwq84i6RMsQ6 gvfJU6kPxCCuUx2Raux2U9wz5U+4DRHJHKahEg72hx6LVzFl52VyS++XEtXhSmKxUMyz 3YX6bwWct7ZNgmKy3P0lpOGs/TsYY+Ix9cl+NwDaB4K78JkHHRO1BHqiQYIPxpYcAwCH kXcfXrmaF8kekQBTgAwcGZxb/PtBtdtSZQr7tcfxcljXf3ceT9hgTEBaKsz2BdDTBB2m r+tt9bhNMlDI5mRoooJ0Zcv8NsSofPKHCoywsbk1i/A+L9Hn5Gbs/Ko2x5KBkpsrrPhC zrnA== X-Gm-Message-State: AOAM5323KQa6y+bt5b/jq424/uW0/R89MOoV+pv6nhLmZ8t+0p4qdAQP ltqez+2UniQV8iudn3yTD3xdWR9nGL2CQoSUjKK0AYN1+PfhOYsJ23Jsff4Ur2RvCa5LsZN0q2K pe9qva3YqMVbIOqWfTjK8VHmua3jteaDT+3V8KGGp8A== X-Received: by 2002:a62:7a42:0:b0:4ba:5289:1f18 with SMTP id v63-20020a627a42000000b004ba52891f18mr50187393pfc.54.1641299635401; Tue, 04 Jan 2022 04:33:55 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+u/+WuLXsPN4TxI8myAmdKs/SgyzP6PgoINmksR5fzyo9Pvw5jwNZJLw0r2KCFVUeQe3HKA== X-Received: by 2002:a62:7a42:0:b0:4ba:5289:1f18 with SMTP id v63-20020a627a42000000b004ba52891f18mr50187371pfc.54.1641299635119; Tue, 04 Jan 2022 04:33:55 -0800 (PST) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id q2sm43280854pfu.66.2022.01.04.04.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 04:33:54 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/3] cifs: use the expiry output of dns_query to schedule next resolution Date: Tue, 4 Jan 2022 05:33:45 -0700 Message-Id: <20220104123347.13691-2-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220104123347.13691-1-tim.gardner@canonical.com> References: <20220104123347.13691-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Shyam Prasad N BugLink: https://bugs.launchpad.net/bugs/1954926 We recently fixed DNS resolution of the server hostname during reconnect. However, server IP address may change, even when the old one continues to server (although sub-optimally). We should schedule the next DNS resolution based on the TTL of the DNS record used for the last resolution. This way, we resolve the server hostname again when a DNS record expires. Signed-off-by: Shyam Prasad N Reviewed-by: Paulo Alcantara (SUSE) Cc: # v5.11+ Signed-off-by: Steve French (backported from commit 506c1da44fee32ba1d3a70413289ad58c772bba6) [rtg - dropped changes to fs/cifs/misc.c] Signed-off-by: Tim Gardner --- fs/cifs/cifs_dfs_ref.c | 2 +- fs/cifs/cifsglob.h | 4 +++ fs/cifs/connect.c | 55 +++++++++++++++++++++++++++++++++++++++--- fs/cifs/dns_resolve.c | 10 +++++--- fs/cifs/dns_resolve.h | 2 +- 5 files changed, 64 insertions(+), 9 deletions(-) diff --git a/fs/cifs/cifs_dfs_ref.c b/fs/cifs/cifs_dfs_ref.c index 42125601ebb10..ab770f33b97ac 100644 --- a/fs/cifs/cifs_dfs_ref.c +++ b/fs/cifs/cifs_dfs_ref.c @@ -176,7 +176,7 @@ char *cifs_compose_mount_options(const char *sb_mountdata, } } - rc = dns_resolve_server_name_to_ip(name, &srvIP); + rc = dns_resolve_server_name_to_ip(name, &srvIP, NULL); if (rc < 0) { cifs_dbg(FYI, "%s: Failed to resolve server part of %s to IP: %d\n", __func__, name, rc); diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 65a3f079f0734..d2fe3cad7864e 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -83,6 +83,9 @@ #define SMB_ECHO_INTERVAL_MAX 600 #define SMB_ECHO_INTERVAL_DEFAULT 60 +/* dns resolution interval in seconds */ +#define SMB_DNS_RESOLVE_INTERVAL_DEFAULT 600 + /* maximum number of PDUs in one compound */ #define MAX_COMPOUND 5 @@ -735,6 +738,7 @@ struct TCP_Server_Info { /* point to the SMBD connection if RDMA is used instead of socket */ struct smbd_connection *smbd_conn; struct delayed_work echo; /* echo ping workqueue job */ + struct delayed_work resolve; /* dns resolution workqueue job */ char *smallbuf; /* pointer to current "small" buffer */ char *bigbuf; /* pointer to current "big" buffer */ /* Total size of this PDU. Only valid from cifs_demultiplex_thread */ diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index e454918a7a52a..04d52b4bbcce1 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -348,6 +348,8 @@ static int reconn_set_ipaddr_from_hostname(struct TCP_Server_Info *server) int rc; int len; char *unc, *ipaddr = NULL; + time64_t expiry, now; + unsigned long ttl = SMB_DNS_RESOLVE_INTERVAL_DEFAULT; if (!server->hostname) return -EINVAL; @@ -361,13 +363,13 @@ static int reconn_set_ipaddr_from_hostname(struct TCP_Server_Info *server) } scnprintf(unc, len, "\\\\%s", server->hostname); - rc = dns_resolve_server_name_to_ip(unc, &ipaddr); + rc = dns_resolve_server_name_to_ip(unc, &ipaddr, &expiry); 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; + goto requeue_resolve; } spin_lock(&cifs_tcp_ses_lock); @@ -376,7 +378,45 @@ static int reconn_set_ipaddr_from_hostname(struct TCP_Server_Info *server) spin_unlock(&cifs_tcp_ses_lock); kfree(ipaddr); - return !rc ? -1 : 0; + /* rc == 1 means success here */ + if (rc) { + now = ktime_get_real_seconds(); + if (expiry && expiry > now) + /* + * To make sure we don't use the cached entry, retry 1s + * after expiry. + */ + ttl = (expiry - now + 1); + } + rc = !rc ? -1 : 0; + +requeue_resolve: + cifs_dbg(FYI, "%s: next dns resolution scheduled for %lu seconds in the future\n", + __func__, ttl); + mod_delayed_work(cifsiod_wq, &server->resolve, (ttl * HZ)); + + return rc; +} + + +static void cifs_resolve_server(struct work_struct *work) +{ + int rc; + struct TCP_Server_Info *server = container_of(work, + struct TCP_Server_Info, resolve.work); + + mutex_lock(&server->srv_mutex); + + /* + * Resolve the hostname again to make sure that IP address is up-to-date. + */ + rc = reconn_set_ipaddr_from_hostname(server); + if (rc) { + cifs_dbg(FYI, "%s: failed to resolve hostname: %d\n", + __func__, rc); + } + + mutex_unlock(&server->srv_mutex); } #ifdef CONFIG_CIFS_DFS_UPCALL @@ -986,6 +1026,7 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server) spin_unlock(&cifs_tcp_ses_lock); cancel_delayed_work_sync(&server->echo); + cancel_delayed_work_sync(&server->resolve); spin_lock(&GlobalMid_Lock); server->tcpStatus = CifsExiting; @@ -2732,6 +2773,7 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect) spin_unlock(&cifs_tcp_ses_lock); cancel_delayed_work_sync(&server->echo); + cancel_delayed_work_sync(&server->resolve); if (from_reconnect) /* @@ -2813,6 +2855,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) INIT_LIST_HEAD(&tcp_ses->tcp_ses_list); INIT_LIST_HEAD(&tcp_ses->smb_ses_list); INIT_DELAYED_WORK(&tcp_ses->echo, cifs_echo_request); + INIT_DELAYED_WORK(&tcp_ses->resolve, cifs_resolve_server); INIT_DELAYED_WORK(&tcp_ses->reconnect, smb2_reconnect_server); mutex_init(&tcp_ses->reconnect_mutex); memcpy(&tcp_ses->srcaddr, &volume_info->srcaddr, @@ -2884,6 +2927,12 @@ cifs_get_tcp_session(struct smb_vol *volume_info) /* queue echo request delayed work */ queue_delayed_work(cifsiod_wq, &tcp_ses->echo, tcp_ses->echo_interval); + /* queue dns resolution delayed work */ + cifs_dbg(FYI, "%s: next dns resolution scheduled for %d seconds in the future\n", + __func__, SMB_DNS_RESOLVE_INTERVAL_DEFAULT); + + queue_delayed_work(cifsiod_wq, &tcp_ses->resolve, (SMB_DNS_RESOLVE_INTERVAL_DEFAULT * HZ)); + return tcp_ses; out_err_crypto_release: diff --git a/fs/cifs/dns_resolve.c b/fs/cifs/dns_resolve.c index 534cbba72789f..8c78b48faf015 100644 --- a/fs/cifs/dns_resolve.c +++ b/fs/cifs/dns_resolve.c @@ -36,6 +36,7 @@ * dns_resolve_server_name_to_ip - Resolve UNC server name to ip address. * @unc: UNC path specifying the server (with '/' as delimiter) * @ip_addr: Where to return the IP address. + * @expiry: Where to return the expiry time for the dns record. * * The IP address will be returned in string form, and the caller is * responsible for freeing it. @@ -43,7 +44,7 @@ * Returns length of result on success, -ve on error. */ int -dns_resolve_server_name_to_ip(const char *unc, char **ip_addr) +dns_resolve_server_name_to_ip(const char *unc, char **ip_addr, time64_t *expiry) { struct sockaddr_storage ss; const char *hostname, *sep; @@ -78,13 +79,14 @@ dns_resolve_server_name_to_ip(const char *unc, char **ip_addr) /* Perform the upcall */ rc = dns_query(current->nsproxy->net_ns, NULL, hostname, len, - NULL, ip_addr, NULL, false); + NULL, ip_addr, expiry, false); if (rc < 0) cifs_dbg(FYI, "%s: unable to resolve: %*.*s\n", __func__, len, len, hostname); else - cifs_dbg(FYI, "%s: resolved: %*.*s to %s\n", - __func__, len, len, hostname, *ip_addr); + cifs_dbg(FYI, "%s: resolved: %*.*s to %s expiry %llu\n", + __func__, len, len, hostname, *ip_addr, + expiry ? (*expiry) : 0); return rc; name_is_IP_address: diff --git a/fs/cifs/dns_resolve.h b/fs/cifs/dns_resolve.h index d3f5d27f4d06e..ff5483d5244d2 100644 --- a/fs/cifs/dns_resolve.h +++ b/fs/cifs/dns_resolve.h @@ -24,7 +24,7 @@ #define _DNS_RESOLVE_H #ifdef __KERNEL__ -extern int dns_resolve_server_name_to_ip(const char *unc, char **ip_addr); +extern int dns_resolve_server_name_to_ip(const char *unc, char **ip_addr, time64_t *expiry); #endif /* KERNEL */ #endif /* _DNS_RESOLVE_H */ From patchwork Tue Jan 4 12:33:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1575228 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=dTAFHDS8; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSsVm5vh4z9t6S for ; Tue, 4 Jan 2022 23:34:08 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1n4j0s-0005yh-7e; Tue, 04 Jan 2022 12:34:02 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1n4j0n-0005wi-Py for kernel-team@lists.ubuntu.com; Tue, 04 Jan 2022 12:33:57 +0000 Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id A2F7B3F1A2 for ; Tue, 4 Jan 2022 12:33:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1641299637; bh=REylsKo8bmwSN86HV4e0CiKc3vW7mISbYMsEY26AU5A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=dTAFHDS8Yh9Wd1FVJoeEJUXom3QeiaES5w6/PxNbL3iqykDiljQcDNtsk97DUQLHu RoCERD2fB4FsZvmI1bJK095OnIi/b8dVNP5A9knmPNB+9aQUbXl0Cb9pjBsMNJVLOV Hb+AdXBOPAiY5eoMguwPf+qW0p6i6f8DmteYluDpH6zGpn7YsY8U/UMSy5c7fPMMqw QgP0Mhm/plccHJXhcI5a1XkoumaK6YxGiz2osZ7u24JbJSeVxkvx8uODyrTrnGypD0 3eq8LHhWZlk/+ovmdoAmkiud1oPTgMXwmmUARRC0y4CJjDtSMoBqPbQQPMXGeT9l2w jvbWhv/f+9THA== Received: by mail-pj1-f70.google.com with SMTP id h33-20020a17090a29a400b001b20b7d48dfso23978043pjd.0 for ; Tue, 04 Jan 2022 04:33:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=REylsKo8bmwSN86HV4e0CiKc3vW7mISbYMsEY26AU5A=; b=Gpm0hpTY8jQ/aJjVafk5PhBfnjVoBxE9Ez/wD4YwID5ggEXoPO/m3+BldNCzRZdx+K pidQqAsSCxIdGMAGbMCrywhufJHDVHj+uYDcUjpPHETfsZ0L64jxBdj9vyYa88PBvXOg ElO45/XDRrjMekZqSo/4biTQjSsDJkA1zY+b/GNsz7E5xhyAUk8mch8bU7AdnRGjc22x BDNgM8Hoh2HeY2i1S8IONzN9aohT6zOROgUp3y3tYXs9YqfhAeSYcCfhByoQjxgzDOEs XSBn5rE5LMwx5NkH6BSO0LzWXbVvkfgy6fyavJ61K7t97Cnj6sLABGsAg1s8rj/GFJbm aRUA== X-Gm-Message-State: AOAM531TvUpdwLplCPq86TfRPGMjJdnIwIG6BNDSxr2sEoRsjcwSExxT x9xOfbZxwDreAMr44N2Z/EdeHjqq6XGxhVTxGmyKKpCoPMRsIKrjzAD5AugntoF7r9ZmX/C9P7l vxcqe4AvQEAv5VSVBXrLMMR3CLFRsvlANAit4b/0Bbw== X-Received: by 2002:a17:90a:e517:: with SMTP id t23mr59922660pjy.49.1641299636064; Tue, 04 Jan 2022 04:33:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpfUzgRfwV+QeE9Ex6tT7fHqcnqB1I/O0Aj20ZBbiesLciCU0HmD55LHnVMlL888W5Jihdtg== X-Received: by 2002:a17:90a:e517:: with SMTP id t23mr59922640pjy.49.1641299635819; Tue, 04 Jan 2022 04:33:55 -0800 (PST) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id q2sm43280854pfu.66.2022.01.04.04.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 04:33:55 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/3] cifs: set a minimum of 120s for next dns resolution Date: Tue, 4 Jan 2022 05:33:46 -0700 Message-Id: <20220104123347.13691-3-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220104123347.13691-1-tim.gardner@canonical.com> References: <20220104123347.13691-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Paulo Alcantara BugLink: https://bugs.launchpad.net/bugs/1954926 With commit 506c1da44fee ("cifs: use the expiry output of dns_query to schedule next resolution") and after triggering the first reconnect, the next async dns resolution of tcp server's hostname would be scheduled based on dns_resolver's key expiry default, which happens to default to 5s on most systems that use key.dns_resolver for upcall. As per key.dns_resolver.conf(5): default_ttl= The number of seconds to set as the expiration on a cached record. This will be overridden if the program manages to re- trieve TTL information along with the addresses (if, for exam- ple, it accesses the DNS directly). The default is 5 seconds. The value must be in the range 1 to INT_MAX. Make the next async dns resolution no shorter than 120s as we do not want to be upcalling too often. Cc: stable@vger.kernel.org Fixes: 506c1da44fee ("cifs: use the expiry output of dns_query to schedule next resolution") Signed-off-by: Paulo Alcantara (SUSE) Reviewed-by: Shyam Prasad N Signed-off-by: Steve French (cherry picked from commit 4ac0536f8874a903a72bddc57eb88db774261e3a) Signed-off-by: Tim Gardner --- fs/cifs/cifsglob.h | 3 ++- fs/cifs/connect.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index d2fe3cad7864e..10934d4d5ce33 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -83,7 +83,8 @@ #define SMB_ECHO_INTERVAL_MAX 600 #define SMB_ECHO_INTERVAL_DEFAULT 60 -/* dns resolution interval in seconds */ +/* dns resolution intervals in seconds */ +#define SMB_DNS_RESOLVE_INTERVAL_MIN 120 #define SMB_DNS_RESOLVE_INTERVAL_DEFAULT 600 /* maximum number of PDUs in one compound */ diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 04d52b4bbcce1..de188a8b282a5 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -386,7 +386,7 @@ static int reconn_set_ipaddr_from_hostname(struct TCP_Server_Info *server) * To make sure we don't use the cached entry, retry 1s * after expiry. */ - ttl = (expiry - now + 1); + ttl = max_t(unsigned long, expiry - now, SMB_DNS_RESOLVE_INTERVAL_MIN) + 1; } rc = !rc ? -1 : 0; From patchwork Tue Jan 4 12:33:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1575227 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=el7ivKnN; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSsVm0yBtz9t4b for ; Tue, 4 Jan 2022 23:34:08 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1n4j0s-0005zI-Lg; Tue, 04 Jan 2022 12:34:02 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1n4j0o-0005wp-Le for kernel-team@lists.ubuntu.com; Tue, 04 Jan 2022 12:33:58 +0000 Received: from mail-pj1-f69.google.com (mail-pj1-f69.google.com [209.85.216.69]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 76A373F0EA for ; Tue, 4 Jan 2022 12:33:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1641299638; bh=8Afp8gPh/frqsgzGXD0Jgnpdvuap9sKvJ38GJVzpdVY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=el7ivKnNcF2h5xGeAII/h/QrU4+ppEw/9t3yh9p3TjEM5qfS0ig4DUK0RKjOO/JTT K5XLm4j2ReBg/giRw8uL0Notzv/RsfNyxcsYGZcopIg4jnDhtscarp8OyUITlbRYaG ZGcMU7/A7FILBjjlEsVQEJ9+RFTgc/zUS+HY8V+S3PyCqazVxbP6R2YexyOxjhSBPc RISAEp4fPeBSioVWl+Jd1IU+s3/XUgtl+gnWMcDqMLushNO//0GsC0pmCXLPQOoohj ihi5FGirguIPJCwFgckvn9HTFaBpC1+FvjKvq0XBNFQx0PHEGTKVFsbbrtG/qYCyGE y/39X8aKv4SBQ== Received: by mail-pj1-f69.google.com with SMTP id f11-20020a17090a664b00b001b0fbffc9d6so24074442pjm.1 for ; Tue, 04 Jan 2022 04:33:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8Afp8gPh/frqsgzGXD0Jgnpdvuap9sKvJ38GJVzpdVY=; b=xt4Muc9kotd2GAe2/eOm3Ol19K5qR7D/oDbVRq1+TRx2I6GjoqFPjGs7AaTA5ZeM4k Ym/Qds2NyzOWjykgXz0629YrwqLLG+lqDW8bv3brQf/5CGjQf9TIb/UW91OxOdolwkbE Sx1pTJKvuxkfay5LRupQF4HUTbEqakaS6A/qoi6CDJI7YGGNQWNhajFlqxlbJRYlx3hK As6edt9n3EXa+9pNBipZhloBZCs8F2XeIZ4Ztzt9yYKQwgTUz426Yhl9ZGZpvuVKJ+pt MZdyfTJHMpk+rOg79A+et4jr3/muZvuSMvrJeNY3rg9vhkFXpW3Of/FPlIt74X2yaUFf +jZQ== X-Gm-Message-State: AOAM533w+7aEC+z63fMwIoru4hSXUJGKwWd3RUTSxtqhpYjaXn4OVz3s lH97BK0JKFv+eCpkKbfCG6sqE91WIZ8kDhiMjTQTFEELkIofOAdHq8UP66N78Us0e4rtn6c0RWI 6TH5giocoe1/22oASXzo1s7XQtjGCIH64KYN+CEMkvg== X-Received: by 2002:a17:90a:6a4c:: with SMTP id d12mr60744665pjm.9.1641299636871; Tue, 04 Jan 2022 04:33:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyx9dlgBarGwmkmm2sa8Ncz/va1hvKYgVBoVIt1oxn7Mgn5bHFAglhbk4fafxWLp/BLeZcZtw== X-Received: by 2002:a17:90a:6a4c:: with SMTP id d12mr60744637pjm.9.1641299636515; Tue, 04 Jan 2022 04:33:56 -0800 (PST) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id q2sm43280854pfu.66.2022.01.04.04.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jan 2022 04:33:56 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/3] cifs: To match file servers, make sure the server hostname matches Date: Tue, 4 Jan 2022 05:33:47 -0700 Message-Id: <20220104123347.13691-4-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220104123347.13691-1-tim.gardner@canonical.com> References: <20220104123347.13691-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Shyam Prasad N BugLink: https://bugs.launchpad.net/bugs/1954926 commit 7be3248f313930ff3d3436d4e9ddbe9fccc1f541 upstream. We generally rely on a bunch of factors to differentiate between servers. For example, IP address, port etc. For certain server types (like Azure), it is important to make sure that the server hostname matches too, even if the both hostnames currently resolve to the same IP address. Signed-off-by: Shyam Prasad N Cc: stable@vger.kernel.org Signed-off-by: Steve French Signed-off-by: Tim Gardner [rtg - backported by the Microsoft team. They dropped changes to fs/cifs/fs_connect.[ch], added a structure tag to fs/cifs/cifsglob.h: struct smb_vol, misc changes to fs/cifs/connect.c to reflect the intent of the original upstream patch] --- fs/cifs/cifsglob.h | 1 + fs/cifs/connect.c | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 10934d4d5ce33..9607f623c1357 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -538,6 +538,7 @@ struct smb_vol { char *username; char *password; char *domainname; + char *server_hostname; char *UNC; char *iocharset; /* local code page for mapping to and from Unicode */ char source_rfc1001_name[RFC1001_NAME_LEN_WITH_NULL]; /* clnt nb name */ diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index de188a8b282a5..dfcac2489b46b 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -1101,7 +1101,6 @@ static void clean_demultiplex_info(struct TCP_Server_Info *server) */ } - kfree(server->hostname); kfree(server); length = atomic_dec_return(&tcpSesAllocCount); @@ -1653,6 +1652,11 @@ cifs_parse_devname(const char *devname, struct smb_vol *vol) if (!pos) return -EINVAL; + /* record the server hostname */ + vol->server_hostname = kstrndup(devname + 2, pos - devname - 2, GFP_KERNEL); + if (!vol->server_hostname) + return -ENOMEM; + /* skip past delimiter */ ++pos; @@ -2510,6 +2514,12 @@ cifs_parse_mount_options(const char *mountdata, const char *devname, goto cifs_parse_mount_err; } #endif + + if (!vol->server_hostname) { + cifs_dbg(VFS, "CIFS mount error: Unable to parse server name in device string!\n"); + goto cifs_parse_mount_err; + } + if (!vol->UNC) { cifs_dbg(VFS, "CIFS mount error: No usable UNC path provided in device string!\n"); goto cifs_parse_mount_err; @@ -2712,6 +2722,9 @@ static int match_server(struct TCP_Server_Info *server, struct smb_vol *vol) if (!net_eq(cifs_net_ns(server), current->nsproxy->net_ns)) return 0; + if (strcasecmp(server->hostname, vol->server_hostname)) + return 0; + if (!match_address(server, addr, (struct sockaddr *)&vol->srcaddr)) return 0; @@ -2796,6 +2809,7 @@ cifs_put_tcp_session(struct TCP_Server_Info *server, int from_reconnect) kfree(server->session_key.response); server->session_key.response = NULL; server->session_key.len = 0; + kfree(server->hostname); task = xchg(&server->tsk, NULL); if (task) @@ -2821,14 +2835,15 @@ cifs_get_tcp_session(struct smb_vol *volume_info) goto out_err; } + tcp_ses->hostname = kstrdup(volume_info->server_hostname, GFP_KERNEL); + if (!tcp_ses->hostname) { + rc = -ENOMEM; + goto out_err; + } + tcp_ses->ops = volume_info->ops; tcp_ses->vals = volume_info->vals; cifs_set_net_ns(tcp_ses, get_net(current->nsproxy->net_ns)); - tcp_ses->hostname = extract_hostname(volume_info->UNC); - if (IS_ERR(tcp_ses->hostname)) { - rc = PTR_ERR(tcp_ses->hostname); - goto out_err_crypto_release; - } tcp_ses->noblockcnt = volume_info->rootfs; tcp_ses->noblocksnd = volume_info->noblocksnd || volume_info->rootfs; @@ -2942,8 +2957,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info) out_err: if (tcp_ses) { - if (!IS_ERR(tcp_ses->hostname)) - kfree(tcp_ses->hostname); + kfree(tcp_ses->hostname); if (tcp_ses->ssocket) sock_release(tcp_ses->ssocket); kfree(tcp_ses); @@ -4272,6 +4286,7 @@ cifs_cleanup_volume_info_contents(struct smb_vol *volume_info) kfree(volume_info->username); kzfree(volume_info->password); kfree(volume_info->UNC); + kfree(volume_info->server_hostname); kfree(volume_info->domainname); kfree(volume_info->iocharset); kfree(volume_info->prepath); @@ -4541,6 +4556,12 @@ static int update_vol_info(const struct dfs_cache_tgt_iterator *tgt_it, kfree(vol->UNC); vol->UNC = new_unc; + if (fake_vol->server_hostname) { + kfree(vol->server_hostname); + vol->server_hostname = fake_vol->server_hostname; + fake_vol->server_hostname = NULL; + } + if (fake_vol->prepath) { kfree(vol->prepath); vol->prepath = fake_vol->prepath; @@ -5342,6 +5363,7 @@ cifs_construct_tcon(struct cifs_sb_info *cifs_sb, kuid_t fsuid) vol_info->linux_uid = fsuid; vol_info->cred_uid = fsuid; vol_info->UNC = master_tcon->treeName; + vol_info->server_hostname = master_tcon->ses->server->hostname; vol_info->retry = master_tcon->retry; vol_info->nocase = master_tcon->nocase; vol_info->nohandlecache = master_tcon->nohandlecache;