Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1193168ybn; Wed, 2 Oct 2019 12:13:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqzKhClMuP+uG0TujqLoG6wwbmiOneLPx7QPBAPsmQwxJMaVI92GdpwMBrhJzPODnBJ5bqB7 X-Received: by 2002:a17:906:5109:: with SMTP id w9mr4405178ejk.282.1570043623647; Wed, 02 Oct 2019 12:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570043623; cv=none; d=google.com; s=arc-20160816; b=TMd+7e91aX8IHy+F9KtC/zMyl3abKRMjjZHdiKQCYaJo+OCwyLGJQxcbfRRlD8hj+Z 3BfAYG75RietUZr2tQHHKexww9x8zG9YOTySHQ/faw0SgCKtCDWTR6yFyL05uS6uONNh G4qU+sgqRkFjNKF39zYvSQwbwT5ds/JwoDlQQa2iFmXGufUdpx9bIbwvl36Yyf3ric2Q m/ee89UqGlSVMTYy9iAKz0pHYq/roIPEW4oLznOWhtLRhwtkD142ACKdSblyV288PvmO +pe3NPay+mHHrRvD+agFd97HIqfte+YMlkgNJzDpypl3grW1fkhY6wwlYg6WB3Bu1DlU jJgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=7zNh8lIAbZe8ukjnfdQk4fB75nXQCY5A8uqsG8eeCTs=; b=ND0qB/enIG7D7a0TKms4fi+s/ox+MR1nJAIB05ry5w4vy5xO0l2Hr0kvN80wRW9ixA UPS1SWdKaBGEE8Uc+GFhrxW4Zyu7ZeEMxdYl8HcyO+l032BcemiZAOItqYikV/4R7ZBX Td+Q8YfstMnTXATnbyhzcrQ0lcfXXwkSwFX5amCp7cqtC5LqdJv8FyVn5ht4MN3a/b7x C3bq2wEWyx81Ox09HDOMmT2tdSEBEknew853dyTr/6KmshO/c62hnrzMHe5bF7p25rbb AOHxRUeYYNS3ZUfyxSnhB0P+xXS3qdpgdmIEWhiYIDhuAQHpe6muD8SC5/qmIuFNV3Y3 tPjA== 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 c60si18401edd.327.2019.10.02.12.13.19; Wed, 02 Oct 2019 12:13:43 -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 S1730069AbfJBTMH (ORCPT + 99 others); Wed, 2 Oct 2019 15:12:07 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35604 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729207AbfJBTIM (ORCPT ); Wed, 2 Oct 2019 15:08:12 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iFjyr-00036L-UV; Wed, 02 Oct 2019 20:08:10 +0100 Received: from ben by deadeye with local (Exim 4.92.1) (envelope-from ) id 1iFjyp-0003eV-09; Wed, 02 Oct 2019 20:08:07 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Ronnie Sahlberg" , "Steve French" , "Pavel Shilovsky" Date: Wed, 02 Oct 2019 20:06:51 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 58/87] cifs: add spinlock for the openFileList to cifsInodeInfo In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.75-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Ronnie Sahlberg commit 487317c99477d00f22370625d53be3239febabbe upstream. We can not depend on the tcon->open_file_lock here since in multiuser mode we may have the same file/inode open via multiple different tcons. The current code is race prone and will crash if one user deletes a file at the same time a different user opens/create the file. To avoid this we need to have a spinlock attached to the inode and not the tcon. RHBZ: 1580165 Signed-off-by: Ronnie Sahlberg Signed-off-by: Steve French Reviewed-by: Pavel Shilovsky [bwh: Backported to 3.16: adjust context, indentation] Signed-off-by: Ben Hutchings --- fs/cifs/cifsfs.c | 1 + fs/cifs/cifsglob.h | 5 +++++ fs/cifs/file.c | 8 ++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -260,6 +260,7 @@ cifs_alloc_inode(struct super_block *sb) cifs_inode->uniqueid = 0; cifs_inode->createtime = 0; cifs_inode->epoch = 0; + spin_lock_init(&cifs_inode->open_file_lock); #ifdef CONFIG_CIFS_SMB2 generate_random_uuid(cifs_inode->lease_key); #endif --- a/fs/cifs/cifsglob.h +++ b/fs/cifs/cifsglob.h @@ -1116,6 +1116,7 @@ struct cifsInodeInfo { struct rw_semaphore lock_sem; /* protect the fields above */ /* BB add in lists for dirty pages i.e. write caching info for oplock */ struct list_head openFileList; + spinlock_t open_file_lock; /* protects openFileList */ __u32 cifsAttrs; /* e.g. DOS archive bit, sparse, compressed, system */ unsigned int oplock; /* oplock/lease level we have */ unsigned int epoch; /* used to track lease state changes */ @@ -1485,10 +1486,14 @@ require use of the stronger protocol */ * tcp_ses_lock protects: * list operations on tcp and SMB session lists * tcon->open_file_lock protects the list of open files hanging off the tcon + * inode->open_file_lock protects the openFileList hanging off the inode * cfile->file_info_lock protects counters and fields in cifs file struct * f_owner.lock protects certain per file struct operations * mapping->page_lock protects certain per page operations * + * Note that the cifs_tcon.open_file_lock should be taken before + * not after the cifsInodeInfo.open_file_lock + * * Semaphores * ---------- * sesSem operations on smb session --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -337,10 +337,12 @@ cifs_new_fileinfo(struct cifs_fid *fid, list_add(&cfile->tlist, &tcon->openFileList); /* if readable file instance put first in list*/ + spin_lock(&cinode->open_file_lock); if (file->f_mode & FMODE_READ) list_add(&cfile->flist, &cinode->openFileList); else list_add_tail(&cfile->flist, &cinode->openFileList); + spin_unlock(&cinode->open_file_lock); spin_unlock(&tcon->open_file_lock); if (fid->purge_cache) @@ -412,7 +414,9 @@ void _cifsFileInfo_put(struct cifsFileIn cifs_add_pending_open_locked(&fid, cifs_file->tlink, &open); /* remove it from the lists */ + spin_lock(&cifsi->open_file_lock); list_del(&cifs_file->flist); + spin_unlock(&cifsi->open_file_lock); list_del(&cifs_file->tlist); if (list_empty(&cifsi->openFileList)) { @@ -1850,10 +1854,10 @@ refind_writable: if (!rc) return inv_file; else { - spin_lock(&tcon->open_file_lock); + spin_lock(&cifs_inode->open_file_lock); list_move_tail(&inv_file->flist, &cifs_inode->openFileList); - spin_unlock(&tcon->open_file_lock); + spin_unlock(&cifs_inode->open_file_lock); cifsFileInfo_put(inv_file); ++refind; inv_file = NULL;