From patchwork Fri Jul 14 08:56:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Prasad N X-Patchwork-Id: 1807677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=WXd5h1sm; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4R2QMQ3ZP0z20c1 for ; Fri, 14 Jul 2023 18:56:50 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234916AbjGNI4r (ORCPT ); Fri, 14 Jul 2023 04:56:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234861AbjGNI4r (ORCPT ); Fri, 14 Jul 2023 04:56:47 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D32D198A for ; Fri, 14 Jul 2023 01:56:46 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6686ef86110so1085255b3a.2 for ; Fri, 14 Jul 2023 01:56:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689325005; x=1689929805; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=YvM1hWXocwOKRbWO7noznsaoRmtbEVDUR9rHc9KMkoc=; b=WXd5h1smw+kNcnCCw8CoeKepBavQMUqAnON/M/u4cPrnd68xp1lTezrdEr4RZwwUDG GyPL7kQlEyxwZsWg65mY6yuty1uuZjg9sWF/lcp63ziEBLmDKiaIn52CFeOSsA+XQfdk +6Agtn2ta/eupQorGDFrQT/+HGCRhXyO/ww/4/afHmLsL9B/zOnAThHNEOb+HV4cIlAw vh/jtqzSwyDP4GqLvMXt6P6AsCz/ZWaCmYgDA1NwVIQlv0AvzVckFknmkzZR5Ooyhtx0 h+92hJmjZZxrb+fgGsV5z8g8m2mBDIl9eecFDSyqjpDyk7iFxDxVFLnTmD4M3369UrY2 TWpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689325005; x=1689929805; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=YvM1hWXocwOKRbWO7noznsaoRmtbEVDUR9rHc9KMkoc=; b=gqSVZUubuN1TLygOHRjo0teHr4pBRXxkqa/Uo5XWmVCGdO9/Ymt/7SsBRhDDwqzDm3 8CDlPu3aq5a0hTgz1eEJozmPoucijVhOIqBfY46hT2CLdbtw4OWpXsS6uvGJgUS6ig1D fiqA1vcWxl4TCV+1Sc4of3mX6NsVvjw3Tg2KokqbHWt1cPtW6ArYpK3OvtvVo0ANDKx6 Z3GaSbda8+b+HwmsG+2MY/cjL/JNMAiZtE7EYdWRVaf9KIs5MN+7gKaOHTG9bsNRU3R8 u3Muqd9Buq0H5NmNTs/UlHVxz1F8gPgH9kDEbzESyUdxB5isLWNtUKKsFO75UwF5/xjC AzkQ== X-Gm-Message-State: ABy/qLYZ2eMkK1kb17tMqxRJgGBWsaElXquOjQ9KM8BcWMm8dULqFic2 p+ONhRLbu5JngXZkfVt1kiil8voU9EZVEg== X-Google-Smtp-Source: APBJJlFPHCCWLOkMnieQEvpNilH8A0NnevZjQ6A0NMVh2nXzwPinfHcZOO29/f31ilKWhQpDo9JCdg== X-Received: by 2002:a05:6a00:2196:b0:682:759c:644d with SMTP id h22-20020a056a00219600b00682759c644dmr3654707pfi.27.1689325005275; Fri, 14 Jul 2023 01:56:45 -0700 (PDT) Received: from lindev-local-latest.corp.microsoft.com ([2404:f801:8028:1:7e0e:5dff:fea8:2c14]) by smtp.gmail.com with ESMTPSA id c11-20020aa78c0b000000b006765cb32558sm6702838pfd.139.2023.07.14.01.56.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 01:56:44 -0700 (PDT) From: Shyam Prasad N X-Google-Original-From: Shyam Prasad N To: linux-cifs@vger.kernel.org, smfrench@gmail.com, bharathsm.hsk@gmail.com, pc@cjr.nz Cc: Shyam Prasad N Subject: [PATCH 1/2] cifs: fix mid leak during reconnection after timeout threshold Date: Fri, 14 Jul 2023 08:56:33 +0000 Message-Id: <20230714085634.10808-1-sprasad@microsoft.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org When the number of responses with status of STATUS_IO_TIMEOUT exceeds a specified threshold (NUM_STATUS_IO_TIMEOUT), we reconnect the connection. But we do not return the mid, or the credits returned for the mid, or reduce the number of in-flight requests. This bug could result in the server->in_flight count to go bad, and also cause a leak in the mids. This change moves the check to a few lines below where the response is decrypted, even of the response is read from the transform header. This way, the code for returning the mids can be reused. Also, the cifs_reconnect was reconnecting just the transport connection before. In case of multi-channel, this may not be what we want to do after several timeouts. Changed that to reconnect the session and the tree too. Also renamed NUM_STATUS_IO_TIMEOUT to a more appropriate name MAX_STATUS_IO_TIMEOUT. Fixes: 8e670f77c4a5 ("Handle STATUS_IO_TIMEOUT gracefully") Signed-off-by: Shyam Prasad N --- fs/smb/client/connect.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index 9d16626e7a66..87047bd38485 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -60,7 +60,7 @@ extern bool disable_legacy_dialects; #define TLINK_IDLE_EXPIRE (600 * HZ) /* Drop the connection to not overload the server */ -#define NUM_STATUS_IO_TIMEOUT 5 +#define MAX_STATUS_IO_TIMEOUT 5 static int ip_connect(struct TCP_Server_Info *server); static int generic_ip_connect(struct TCP_Server_Info *server); @@ -1118,6 +1118,7 @@ cifs_demultiplex_thread(void *p) struct mid_q_entry *mids[MAX_COMPOUND]; char *bufs[MAX_COMPOUND]; unsigned int noreclaim_flag, num_io_timeout = 0; + bool pending_reconnect = false; noreclaim_flag = memalloc_noreclaim_save(); cifs_dbg(FYI, "Demultiplex PID: %d\n", task_pid_nr(current)); @@ -1157,6 +1158,8 @@ cifs_demultiplex_thread(void *p) cifs_dbg(FYI, "RFC1002 header 0x%x\n", pdu_length); if (!is_smb_response(server, buf[0])) continue; + + pending_reconnect = false; next_pdu: server->pdu_size = pdu_length; @@ -1214,10 +1217,13 @@ cifs_demultiplex_thread(void *p) if (server->ops->is_status_io_timeout && server->ops->is_status_io_timeout(buf)) { num_io_timeout++; - if (num_io_timeout > NUM_STATUS_IO_TIMEOUT) { - cifs_reconnect(server, false); + if (num_io_timeout > MAX_STATUS_IO_TIMEOUT) { + cifs_server_dbg(VFS, + "Number of request timeouts exceeded %d. Reconnecting", + MAX_STATUS_IO_TIMEOUT); + + pending_reconnect = true; num_io_timeout = 0; - continue; } } @@ -1264,6 +1270,11 @@ cifs_demultiplex_thread(void *p) buf = server->smallbuf; goto next_pdu; } + + /* do this reconnect at the very end after processing all MIDs */ + if (pending_reconnect) + cifs_reconnect(server, true); + } /* end while !EXITING */ /* buffer usually freed in free_mid - need to free it here on exit */ From patchwork Fri Jul 14 08:56:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Prasad N X-Patchwork-Id: 1807678 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2620:137:e000::1:20; helo=out1.vger.email; envelope-from=linux-cifs-owner@vger.kernel.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=X5H8zuYp; dkim-atps=neutral Received: from out1.vger.email (out1.vger.email [IPv6:2620:137:e000::1:20]) by legolas.ozlabs.org (Postfix) with ESMTP id 4R2QMV22Zzz20c1 for ; Fri, 14 Jul 2023 18:56:54 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234861AbjGNI4x (ORCPT ); Fri, 14 Jul 2023 04:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235359AbjGNI4w (ORCPT ); Fri, 14 Jul 2023 04:56:52 -0400 Received: from mail-ot1-x32b.google.com (mail-ot1-x32b.google.com [IPv6:2607:f8b0:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6158A2120 for ; Fri, 14 Jul 2023 01:56:49 -0700 (PDT) Received: by mail-ot1-x32b.google.com with SMTP id 46e09a7af769-6b9b52724ccso864925a34.1 for ; Fri, 14 Jul 2023 01:56:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689325008; x=1689929808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mttjMBzUqoIKG1b+qmHt6r2ztAyfJL97O64smzTfDxs=; b=X5H8zuYpiXvfLa4PERizv5uEvtXD1WYfAuGw/tTzEWZmae6KsSbogZsUJ5MNfBz30e ExuV+IZKWvch5sZpEPZ2mcoXUNQmvXI0xpkSHjTplA12sUFeuEfD7gKOfK1P+Bf4qoDb rdZtgLu73gjKB3D2gjpytjwsyFMAv+yq/hNYsuv4ABkIs5q49t541A3o8opAE5Xzz+PT n/7QdlkQS9f3Ev1UaOg9ouwPfEjvSEsY/nlS26EwXGQZBP7kSk3kw23sF/KNGiuJKBiF D6G1UOoeJLf+hEPiVSs8/qkwM4/WoxCB14mZ2HCEMc8OLiwMDLG24Gh3EpyNNALE/YwP Jcaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689325008; x=1689929808; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mttjMBzUqoIKG1b+qmHt6r2ztAyfJL97O64smzTfDxs=; b=GHmdSb+3GXN9sAKbAtCPtzVpn+Sct94FBc/UFolpAId2H9BR40N3ewb1tp3wvo0yFy XTDeSu3aX/Q/UrKNBEiHU6I5+8UT2RnQVXou00dN+gdBAe3yW2XkSkTG2sj7n71Bsf7O YYFEG7Ao2IvlL3aAdbKO2jZcRJYs/NqecBovkabnMcyrdcO2/R8pMyv04SUCmwg5ImIo oLbaRuGHhzg51cfXWPfgo9lEZ1LRgp6lA4bGzmwoHBvH4pEkPL3g5il6n3OUJlWdPOE+ N0Tt3m3CNb5TaUtMSetz4h27yR5IvFsbxpfTPysUJQSsn4sSk30LRasUOyhcC+Zg+fqZ Excg== X-Gm-Message-State: ABy/qLZJaLGgbLTD+Umf+sMr9yC7mbhaLb/7wOIbIbTHrEuc5WfKh8jP iYEJlhP2oya/agXJKPedVxPwNtWCfidTrg== X-Google-Smtp-Source: APBJJlH0h1lAWoRaz/cEJbH3GX83mhWVuSzan5f0iz2uhjzLVO6fKwG5TbR499+BdTWi/AiCAiZRfw== X-Received: by 2002:a05:6358:5916:b0:130:e0a9:a7b4 with SMTP id g22-20020a056358591600b00130e0a9a7b4mr5668568rwf.13.1689325008015; Fri, 14 Jul 2023 01:56:48 -0700 (PDT) Received: from lindev-local-latest.corp.microsoft.com ([2404:f801:8028:1:7e0e:5dff:fea8:2c14]) by smtp.gmail.com with ESMTPSA id c11-20020aa78c0b000000b006765cb32558sm6702838pfd.139.2023.07.14.01.56.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Jul 2023 01:56:47 -0700 (PDT) From: Shyam Prasad N X-Google-Original-From: Shyam Prasad N To: linux-cifs@vger.kernel.org, smfrench@gmail.com, bharathsm.hsk@gmail.com, pc@cjr.nz Cc: Shyam Prasad N Subject: [PATCH 2/2] cifs: is_network_name_deleted should return a bool Date: Fri, 14 Jul 2023 08:56:34 +0000 Message-Id: <20230714085634.10808-2-sprasad@microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230714085634.10808-1-sprasad@microsoft.com> References: <20230714085634.10808-1-sprasad@microsoft.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org Currently, is_network_name_deleted and it's implementations do not return anything if the network name did get deleted. So the function doesn't fully achieve what it advertizes. Changed the function to return a bool instead. It will now return true if the error returned is STATUS_NETWORK_NAME_DELETED and the share (tree id) was found to be connected. It returns false otherwise. Signed-off-by: Shyam Prasad N --- fs/smb/client/cifsglob.h | 2 +- fs/smb/client/connect.c | 11 ++++++++--- fs/smb/client/smb2ops.c | 8 +++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index b212a4e16b39..bde9de6665a7 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -532,7 +532,7 @@ struct smb_version_operations { /* Check for STATUS_IO_TIMEOUT */ bool (*is_status_io_timeout)(char *buf); /* Check for STATUS_NETWORK_NAME_DELETED */ - void (*is_network_name_deleted)(char *buf, struct TCP_Server_Info *srv); + bool (*is_network_name_deleted)(char *buf, struct TCP_Server_Info *srv); }; struct smb_version_values { diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index 87047bd38485..6756ce4ff641 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -1233,9 +1233,14 @@ cifs_demultiplex_thread(void *p) if (mids[i] != NULL) { mids[i]->resp_buf_size = server->pdu_size; - if (bufs[i] && server->ops->is_network_name_deleted) - server->ops->is_network_name_deleted(bufs[i], - server); + if (bufs[i] != NULL) { + if (server->ops->is_network_name_deleted && + server->ops->is_network_name_deleted(bufs[i], + server)) { + cifs_server_dbg(FYI, + "Share deleted. Reconnect needed"); + } + } if (!mids[i]->multiRsp || mids[i]->multiEnd) mids[i]->callback(mids[i]); diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 153b300621eb..d32477315abc 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -2391,7 +2391,7 @@ smb2_is_status_io_timeout(char *buf) return false; } -static void +static bool smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server) { struct smb2_hdr *shdr = (struct smb2_hdr *)buf; @@ -2400,7 +2400,7 @@ smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server) struct cifs_tcon *tcon; if (shdr->Status != STATUS_NETWORK_NAME_DELETED) - return; + return false; /* If server is a channel, select the primary channel */ pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server; @@ -2415,11 +2415,13 @@ smb2_is_network_name_deleted(char *buf, struct TCP_Server_Info *server) spin_unlock(&cifs_tcp_ses_lock); pr_warn_once("Server share %s deleted.\n", tcon->tree_name); - return; + return true; } } } spin_unlock(&cifs_tcp_ses_lock); + + return false; } static int