Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2026266imm; Tue, 10 Jul 2018 11:51:32 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfIQdPCl5H9FZbl/GzfjjKhuNi+73wUcMK0qOh0nHIjMnO5K7/vEzCkbLYMNifWVvFhO0Im X-Received: by 2002:a17:902:1007:: with SMTP id b7-v6mr25529421pla.277.1531248692567; Tue, 10 Jul 2018 11:51:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531248692; cv=none; d=google.com; s=arc-20160816; b=H5htVypZaJbX8L9vd/Xs48RvJEPk61lHSARusztvFIqcTM4vNrANpJ1XQrCN9ZDcYS w9ck5sIT2qQbsTVdjNh9WfNBJWkxOSAq8C/AqkA6C7uhAZEEe0eOokr0KBaUVadFfRuq JQgPUSIZyRc6wqG/CdVvuUfaDjsNhG1G3ddwHXiLNg+4iHXX3L9Typ1ZJXGI2V3hlyw/ mcm2tG52vvmSd0Nz04ESq6b/snHts3xfptZ7xtY57rAgPYjzUCPeazrvXZEpanzzH7Sm 8JEOrtEY9uJIe3LNgOZKKQyjD/UVlNLicw0KzFt+3wTwkRjYP2qhBKqpiELg7PGzrSML PEFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=BBB9s3qPYLxx+ZPX8BNUxYTKFkjP3VCTu9Ho/rrAoYQ=; b=nisS/KHqXZmiB0VB1/EjFpNF8lq/6pHYunHWp2E4gnODHNYfqjIQnRHPORIA48fIyM K8RLlSCg5hl+864ljRDm1gOMBnWAP7n08u2PKVzL2SW1rAFxIaWV/Z4Qo/GTqAmQu07V 8dp8kYrBFPUZFTx5lL0WvlS66tnZFdthtXJHfLAFV6aSYSFOo5a5AB3ato23gI5RoJ3c a6hWzbBpqVg5rMaLH8sj4U7RpY4BcoVCx4b0lV4I+3ze4LSkKRIYnp6eS80o0idSDW7R iOaObgPP7Vlg0ljSZe+5DepuXIkqRJIZPAeicd75pmz5yuOzRuWD+ACucNao9d8KpAZA S/8w== ARC-Authentication-Results: i=1; mx.google.com; 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 i16-v6si17060126pgn.252.2018.07.10.11.51.17; Tue, 10 Jul 2018 11:51:32 -0700 (PDT) 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; 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 S2387955AbeGJSaL (ORCPT + 99 others); Tue, 10 Jul 2018 14:30:11 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45504 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732596AbeGJSaJ (ORCPT ); Tue, 10 Jul 2018 14:30:09 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E825DEB8; Tue, 10 Jul 2018 18:29:57 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Paulo Alcantara , Aurelien Aptel , Steve French Subject: [PATCH 4.9 24/52] cifs: Fix infinite loop when using hard mount option Date: Tue, 10 Jul 2018 20:24:52 +0200 Message-Id: <20180710182451.773789863@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180710182449.285532226@linuxfoundation.org> References: <20180710182449.285532226@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 7ffbe65578b44fafdef577a360eb0583929f7c6e upstream. For every request we send, whether it is SMB1 or SMB2+, we attempt to reconnect tcon (cifs_reconnect_tcon or smb2_reconnect) before carrying out the request. So, while server->tcpStatus != CifsNeedReconnect, we wait for the reconnection to succeed on wait_event_interruptible_timeout(). If it returns, that means that either the condition was evaluated to true, or timeout elapsed, or it was interrupted by a signal. Since we're not handling the case where the process woke up due to a received signal (-ERESTARTSYS), the next call to wait_event_interruptible_timeout() will _always_ fail and we end up looping forever inside either cifs_reconnect_tcon() or smb2_reconnect(). Here's an example of how to trigger that: $ mount.cifs //foo/share /mnt/test -o username=foo,password=foo,vers=1.0,hard (break connection to server before executing bellow cmd) $ stat -f /mnt/test & sleep 140 [1] 2511 $ ps -aux -q 2511 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 2511 0.0 0.0 12892 1008 pts/0 S 12:24 0:00 stat -f /mnt/test $ kill -9 2511 (wait for a while; process is stuck in the kernel) $ ps -aux -q 2511 USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 2511 83.2 0.0 12892 1008 pts/0 R 12:24 30:01 stat -f /mnt/test By using 'hard' mount point means that cifs.ko will keep retrying indefinitely, however we must allow the process to be killed otherwise it would hang the system. Signed-off-by: Paulo Alcantara Cc: stable@vger.kernel.org Reviewed-by: Aurelien Aptel Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/cifs/cifssmb.c | 10 ++++++++-- fs/cifs/smb2pdu.c | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -150,8 +150,14 @@ cifs_reconnect_tcon(struct cifs_tcon *tc * greater than cifs socket timeout which is 7 seconds */ while (server->tcpStatus == CifsNeedReconnect) { - wait_event_interruptible_timeout(server->response_q, - (server->tcpStatus != CifsNeedReconnect), 10 * HZ); + rc = wait_event_interruptible_timeout(server->response_q, + (server->tcpStatus != CifsNeedReconnect), + 10 * HZ); + if (rc < 0) { + cifs_dbg(FYI, "%s: aborting reconnect due to a received" + " signal by the process\n", __func__); + return -ERESTARTSYS; + } /* are we still trying to reconnect? */ if (server->tcpStatus != CifsNeedReconnect) --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -155,7 +155,7 @@ out: static int smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon) { - int rc = 0; + int rc; struct nls_table *nls_codepage; struct cifs_ses *ses; struct TCP_Server_Info *server; @@ -166,10 +166,10 @@ smb2_reconnect(__le16 smb2_command, stru * for those three - in the calling routine. */ if (tcon == NULL) - return rc; + return 0; if (smb2_command == SMB2_TREE_CONNECT) - return rc; + return 0; if (tcon->tidStatus == CifsExiting) { /* @@ -212,8 +212,14 @@ smb2_reconnect(__le16 smb2_command, stru return -EAGAIN; } - wait_event_interruptible_timeout(server->response_q, - (server->tcpStatus != CifsNeedReconnect), 10 * HZ); + rc = wait_event_interruptible_timeout(server->response_q, + (server->tcpStatus != CifsNeedReconnect), + 10 * HZ); + if (rc < 0) { + cifs_dbg(FYI, "%s: aborting reconnect due to a received" + " signal by the process\n", __func__); + return -ERESTARTSYS; + } /* are we still trying to reconnect? */ if (server->tcpStatus != CifsNeedReconnect) @@ -231,7 +237,7 @@ smb2_reconnect(__le16 smb2_command, stru } if (!tcon->ses->need_reconnect && !tcon->need_reconnect) - return rc; + return 0; nls_codepage = load_nls_default();