From patchwork Wed Nov 30 00:56:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovskiy X-Patchwork-Id: 9453489 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id ED46A60235 for ; Wed, 30 Nov 2016 02:30:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D6CF72818E for ; Wed, 30 Nov 2016 02:30:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAD602833B; Wed, 30 Nov 2016 02:30:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4FCAE2818E for ; Wed, 30 Nov 2016 02:30:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753427AbcK3Ca6 (ORCPT ); Tue, 29 Nov 2016 21:30:58 -0500 Received: from mail-co1nam03on0096.outbound.protection.outlook.com ([104.47.40.96]:17028 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752099AbcK3Ca4 (ORCPT ); Tue, 29 Nov 2016 21:30:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=hoBj63SFXNxn3o0dmh3ZsYzhC4fhS6H/JiOSSj4Suvg=; b=BEwiVE4l+f31DYREU++pFWckdq/pAnKkt2H8l+pgxviLzxoqdKvgAtcjp2oWPC1LrM//Vadgo/RgQ1+utZ0Ze2jR1+TfulkKKYHooDlYVsd4S4FgPsZVwyXghxrX/qJgiyahBGhb5KIGoDMx7+vWE2SvIo0JX/Snft1OF5qtZvA= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pshilov@microsoft.com; Received: from ubuntu-vm.corp.microsoft.com (2001:4898:80e8::63b) by BN6PR03MB2546.namprd03.prod.outlook.com (10.173.142.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.747.10; Wed, 30 Nov 2016 00:57:06 +0000 From: Pavel Shilovsky To: Subject: [PATCH 5/5] CIFS: Fix a possible double locking of mutex during reconnect Date: Tue, 29 Nov 2016 16:56:56 -0800 Message-ID: <1480467416-13636-6-git-send-email-pshilov@microsoft.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1480467416-13636-1-git-send-email-pshilov@microsoft.com> References: <1480467416-13636-1-git-send-email-pshilov@microsoft.com> MIME-Version: 1.0 X-Originating-IP: [2001:4898:80e8::63b] X-ClientProxiedBy: CY4PR08CA0032.namprd08.prod.outlook.com (10.173.247.146) To BN6PR03MB2546.namprd03.prod.outlook.com (10.173.142.149) X-MS-Office365-Filtering-Correlation-Id: 7fad44e0-56b5-4058-2880-08d418bbceae X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001); SRVR:BN6PR03MB2546; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2546; 3:JRICuoilWlc2v8jGtgRRWbJ8mdLYO6m8XETfo82hR5KC1b57Ly/+/rw4vDKYBafZPgFlcCasAaAJk4cEUCBksOlUVTagLcKHndhzOeli+LAQrjM4nDhynHTvWXwjBcu+EQI5l+/ZIPqQ4j+e044oZZgyzSjuq2Z0zr9WB68K5M149wvc8RbOzCVAqHztueP7EntMHYg9pYVUE4R78sa5Ug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L13+J1UqW7uf639W095EM444+Vhg0/6aatWXNKQYcjeMRURD3LUDoGPE9eFlY2hAdjsrmAYmr5gE/4TfktSFMH8lXoqBGRtg9FJOPF7d167QoiyaNS8C6VxCDzIBpc8/9rLLLUGhQp9PkCPtp7C42Y7rXHTyMAkDGJXU8B/khI/AGg6k2DVs1L3jBslbLuCiiEQDhGB52gRbOM9I0e83mDdwvgs8p75EfXnfz5B7kvPA1EpteMIGvMQSDlNL8VaonGpD1oooPI4U8XouyceLW+qFkiSGTD0QnFXdexSSE72oEFftOkO+Cl4GQktNg/NuMwuhE2lFsbGKTGOqoJ6M9YIuh X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(158342451672863)(9452136761055); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026)(6041248)(20161123560025)(20161123558021)(20161123564025)(20161123562025)(20161123555025)(6072148)(6047074); SRVR:BN6PR03MB2546; BCL:0; PCL:0; RULEID:; SRVR:BN6PR03MB2546; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2546; 4:+xmHJ4ANWUiEehwFB6XNs2x+pD8JSIAHGOHYAzyGlwyFLn8ICkG/+Q3Wmk/gx5zf7SEKTwBU7w/YaOmLvHn/oJKJSAGvfXc82m/NPE1FqdBEyzx9rjFv/Ga89GkLe27y5eNtaovuBwOYQ2napv8V4WObmeu/b8Vdk1lFI/NTqc9FrP2J6JtXLHjIDK2NKFgjQzCgluW3SruTjF+7SiyfGcuP2UrJ+vgTNon/8zlkPl148y2Y4yh6npMdzAfCIgr3RFAaFo/mykK5QZhPqlA1OlkiQp0x+oCDroczBkmWbTMGiMTxE1vkB0BPZK22QP3t3ljnDr4mh5Vrz9NVLjc3bmiYNioPa1SEMnXB+iP5mXC3DLghSI1o02H8BNz6ZlV1p+Nb/yGvAnm+PdhDroJZaxtZyWLwKax/oxeTi2GhX5G6l0fAkO4Ri9WZ5jJyJl9UCR+j3AI+PHJV4JLWCLWZnSwNkQ4SVfnbbf+m5kzQVeHco2ART3cwAkc4/KuSjmwhFWiCh53lTH6TgQiPnvU1gkP5CdmxRnLzOAqDZh0kpESU/ByGf7FSGGPzrpxZZnQ2V99zNMtiAYHe0elG8b+/VUU3N6dMJgdhcJZWohsHpaaaspDdvzQ0UonTyx/btJX3aqNemdcd7BJmy5yJLJkpcMa9x3reB6ac+n8vSymEnSVZUd3P3ktDzSJSOoLC1snQPdQ73blEoB8cfRVvJOyxOsAKYZ5pbGnahYt1QngZX4Q= X-Forefront-PRVS: 0142F22657 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(7916002)(199003)(189002)(69234005)(6486002)(2351001)(450100001)(5005710100001)(733004)(5660300001)(50226002)(50466002)(81156014)(81166006)(7736002)(8676002)(7846002)(39450400002)(5003940100001)(36756003)(107886002)(10290500002)(110136003)(39410400001)(42186005)(86612001)(68736007)(105586002)(6116002)(6916009)(575784001)(33646002)(101416001)(2950100002)(189998001)(106356001)(305945005)(92566002)(38730400001)(6666003)(2906002)(50986999)(97736004)(48376002)(47776003)(10090500001)(76176999)(86362001); DIR:OUT; SFP:1102; SCL:1; SRVR:BN6PR03MB2546; H:ubuntu-vm.corp.microsoft.com; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR03MB2546; 23:FO/JP2rrFaQuaSL9++0iHPsOMRDPlmsIdS7+HEWcO?= =?us-ascii?Q?PjKH0G5E5I1XnM+KyufkakHUc7WFjzc1KlHvvbdu0rYK8H+JsKouQae/4B8P?= =?us-ascii?Q?FZ3INlVooLkFMfe4xO8zeXMjtXz7RlSkwvBfJY0DM2F26Dfa6gKaPlIVzUf2?= =?us-ascii?Q?QEBqF64RagIbzczbYvNQ9Kaw7DI1hjGTP6qggkgAJLWI4QfYl21kh4a24yrY?= =?us-ascii?Q?t4BLB4hVlzMM3xAe5p7E+7deSuneiIaatDaP8o1gSphDHku+QNu2wPd0UJDs?= =?us-ascii?Q?NXWWyJo7BE7tbr0cn76+qJNsfYQAWs77I2MMRBl08cCmDoQqUviPJvOJddMY?= =?us-ascii?Q?v+GexwRBdk4VElMYOCEO25YLRvwUsyn233DMocNAx0XnLluZvP+iEqzYeNK6?= =?us-ascii?Q?le+tU1GzgUBJXaQfXN/z8XHbi22CaI7+91m26IKtcDfYdmkTnC1wvvUKSEKf?= =?us-ascii?Q?lN9fHFf9FSV0lQSYWrVdSveDfePCU7utb7ocNfUIb8qnArnmBz/N2b1fryFc?= =?us-ascii?Q?BMtEJSS0O9RZVMseY2eCKekYVivYs+S7c05Nfi5zpSr8yORtK+ojKyKlsL5F?= =?us-ascii?Q?ERMlal5RK+LReemTMvw58BZpamGkIl+zdJU7u2dam5bsDJ+Tnwb9lWZpD/o0?= =?us-ascii?Q?/EYvmTipeb/YOeBUA47RaECkvR1gFac/jI+bbU0cqm+M4yIr9NVciHVaIOO5?= =?us-ascii?Q?RAIIIWr9rSlzueMVMVm1jHKwMevT8cF+8W/iWKXknM23Ecs/37xQHj6nwVT+?= =?us-ascii?Q?Fa8IF2a47LhewkNZtQwNoGXEpSs+X7csC4zd/dTaQCQzgFnmUZTCO3D+HOm9?= =?us-ascii?Q?A/cgePVl23xB1ZSWxdqtcZFldh+pa2Ci4HjkxDdNcShGlrnVlY5ikCXYWw9s?= =?us-ascii?Q?/+/Z2kNBlox82c3mylaklukUdbECMEGEx/nUyqSDNZjbBkHqgZJgR4lAVrfD?= =?us-ascii?Q?ZuJGlzPQ3UsyXJr/FUUbm9q7q51vr25UwuQPeKg4OifFhun6bUVC/W1R/ouX?= =?us-ascii?Q?djTZX/3sLrYzxuN5UiwoRXYLv+q/KvKIkCYput/3GywMCoyXi7gcjoqgw4xU?= =?us-ascii?Q?fnNdKyWsNC64s/RZUCfHueyc+hBY0j8Ka5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NSPM X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2546; 7:CA3QB3FKG/NcnceXy/aU8ok4Ew9DPSxZiLKGbOzI+/aY6MWqO4mDNSmqPS/uMTOMzZQUjHB3FR61lURL0yPL73bbTpxkE3iDdUYvn17TPcVkkh+G+0/fwoBlKrD82GzmNnaesqJfNx5fomgMDzyjF/NqjPhTsGsh9Fbzreedw/6Wh/JZeM0U1Jztb3MvMQVrOSqpn4tnm/hwMpicQKmH8d6Ow1IbwiiQeNYNBlOVQdlKzCmb7ICa3JBOE6dF8SjP0OCtInSNHg60BptvbcjRJU3UrNg++2mPZ8JpKvJeGYW9mjq3zcpOvU1nYD365I1IUZdbgCTxd7jfyzxbMffHsfercYEh87QxRyuLH1InRitxdVH9PjGymR7jCY8aHQ9TNiM0A6hEKCMcAC8UpXqFkLNU2VOPJsZ4BwRwWWX1W0aZ1R9StJ+7EPsLSNgKCe9riFqM0CBM/bGI8XynN3fB2A== X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2016 00:57:06.9181 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR03MB2546 Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With the current code it is possible to lock a mutex twice when a subsequent reconnects are triggered. On the 1st reconnect we reconnect sessions and tcons and then persistent file handles. If the 2nd reconnect happens during the reconnecting of persistent file handles then the following sequence of calls is observed: cifs_reopen_file -> SMB2_open -> small_smb2_init -> smb2_reconnect -> cifs_reopen_persistent_file_handles -> cifs_reopen_file (again!). So, we are trying to acquire the same cfile->fh_mutex twice which is wrong. Fix this by moving reconnecting of persistent handles to the delayed work (smb2_reconnect_server) and submitting this work every time we reconnect tcon in SMB2 commands handling codepath. Cc: Stable # v4.9+ Signed-off-by: Pavel Shilovsky --- fs/cifs/cifsglob.h | 1 + fs/cifs/file.c | 8 +++++++- fs/cifs/smb2pdu.c | 14 +++++++++----- fs/cifs/smb2pdu.h | 2 ++ 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h index 52368a6..6458a17 100644 --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -925,6 +925,7 @@ struct cifs_tcon { bool broken_posix_open; /* e.g. Samba server versions < 3.3.2, 3.2.9 */ bool broken_sparse_sup; /* if server or share does not support sparse */ bool need_reconnect:1; /* connection reset, tid now invalid */ + bool need_reopen_files:1; /* need to reopen tcon file handles */ bool use_resilient:1; /* use resilient instead of durable handles */ bool use_persistent:1; /* use persistent instead of durable handles */ #ifdef CONFIG_CIFS_SMB2 diff --git a/fs/cifs/file.c b/fs/cifs/file.c index 7f5f617..18a1e1d 100644 --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -777,6 +777,11 @@ cifs_reopen_persistent_handles(struct cifs_tcon *tcon) struct list_head *tmp1; struct list_head tmp_list; + if (!tcon->use_persistent || !tcon->need_reopen_files) + return; + + tcon->need_reopen_files = false; + cifs_dbg(FYI, "Reopen persistent handles"); INIT_LIST_HEAD(&tmp_list); @@ -793,7 +798,8 @@ cifs_reopen_persistent_handles(struct cifs_tcon *tcon) list_for_each_safe(tmp, tmp1, &tmp_list) { open_file = list_entry(tmp, struct cifsFileInfo, rlist); - cifs_reopen_file(open_file, false /* do not flush */); + if (cifs_reopen_file(open_file, false /* do not flush */)) + tcon->need_reopen_files = true; list_del_init(&open_file->rlist); cifsFileInfo_put(open_file); } diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index 8fecf4b..7b13f7b 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -250,16 +250,19 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon) } cifs_mark_open_files_invalid(tcon); + if (tcon->use_persistent) + tcon->need_reopen_files = true; rc = SMB2_tcon(0, tcon->ses, tcon->treeName, tcon, nls_codepage); mutex_unlock(&tcon->ses->session_mutex); - if (tcon->use_persistent) - cifs_reopen_persistent_handles(tcon); - cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc); if (rc) goto out; + + if (smb2_command != SMB2_INTERNAL_CMD) + mod_delayed_work(cifsiod_wq, &server->reconnect, 0); + atomic_inc(&tconInfoReconnectCount); out: /* @@ -1990,7 +1993,7 @@ void smb2_reconnect_server(struct work_struct *work) spin_lock(&cifs_tcp_ses_lock); list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) { list_for_each_entry(tcon, &ses->tcon_list, tcon_list) { - if (tcon->need_reconnect) { + if (tcon->need_reconnect || tcon->need_reopen_files) { tcon->tc_count++; list_add_tail(&tcon->rlist, &tmp_list); tcon_exist = true; @@ -2007,7 +2010,8 @@ void smb2_reconnect_server(struct work_struct *work) spin_unlock(&cifs_tcp_ses_lock); list_for_each_entry_safe(tcon, tcon2, &tmp_list, rlist) { - smb2_reconnect(SMB2_ECHO, tcon); + if (!smb2_reconnect(SMB2_INTERNAL_CMD, tcon)) + cifs_reopen_persistent_handles(tcon); list_del_init(&tcon->rlist); cifs_put_tcon(tcon); } diff --git a/fs/cifs/smb2pdu.h b/fs/cifs/smb2pdu.h index fd3709e..dc0d141 100644 --- a/fs/cifs/smb2pdu.h +++ b/fs/cifs/smb2pdu.h @@ -80,6 +80,8 @@ #define SMB2_SET_INFO cpu_to_le16(SMB2_SET_INFO_HE) #define SMB2_OPLOCK_BREAK cpu_to_le16(SMB2_OPLOCK_BREAK_HE) +#define SMB2_INTERNAL_CMD cpu_to_le16(0xFFFF) + #define NUMBER_OF_SMB2_COMMANDS 0x0013 /* BB FIXME - analyze following length BB */