Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp822628ybl; Wed, 11 Dec 2019 08:03:16 -0800 (PST) X-Google-Smtp-Source: APXvYqwO6PTmkvORsYNm3iAjZVs0KFS4vsI4Svvqzd+hSVKFWXfMf6Voq/HZwjPs8AjgP/737tmt X-Received: by 2002:aca:ef85:: with SMTP id n127mr3446276oih.54.1576080195970; Wed, 11 Dec 2019 08:03:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576080195; cv=none; d=google.com; s=arc-20160816; b=dabkJnoGgauPSNaTov5jLpqNKzWFrfOzbvBL3tHI4smnwbbJ1+KDfIYULSfnFZ/aJo kAqiJofgGphk8U+pfPFWzWIq02JWRbn/GcXr1saKg4mrlJ6qiT9yXo6ncoOedRQcQmwi PSOcxHZkdqBqpFteelzY0wxW0HrfL8cuC5sT4CCn2OqgaUXF7P4uT295mOMKdtXVgPBJ 6Wun4r5it8x7sa7WeeMiidGT8n8h0Etx/+5GBNYDLpbOZF7NlNjWj3zwaBIKqYUvwBOU As1e37iDjRWYCdIubcHDuaG/zv+5AJwQ0R216IMry9sAgHojcb2+V8+6B1mMp7OzKVw1 HuRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=6eSOZUMPrxsQUkSHZpl22197uTWm9/6FRPG716rkIg0=; b=rFmuXCIXnrOP50xgg3tju0FdVLK4d0w/Pn2N/UN7qySq4ZwiyZ0jd6svrUNaTVzr5m SJ+StKKItvZPM6ApAW0Y/8Av8TrEXB6tBlqSS/+FM9RmHvEFvjQYIUI49v6gdg86BgpY i+S/VVjKnlAig4aN66kDQxHTpYs67kpyX0IYwzCS7D7xr3Qg7EDUkz3f1fmWXQa0cLFS L8XI7SbXaw3Nz5fOJRTnyh0vcpw8jPqlANB4RxZbKegbTLtcUFogkZzUGXls+Ve/Iplf M9EKYtGQS04i+DzV6H5tyWmnxHl1FycKX3bJX5SOAeCbAtpu/1Og+r1MHiZReTGHDCED AOTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="L5Z/e6s4"; 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 z10si1410730oto.50.2019.12.11.08.02.57; Wed, 11 Dec 2019 08:03:15 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b="L5Z/e6s4"; 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 S1731690AbfLKQAf (ORCPT + 99 others); Wed, 11 Dec 2019 11:00:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:37812 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730658AbfLKPNq (ORCPT ); Wed, 11 Dec 2019 10:13:46 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7191D24658; Wed, 11 Dec 2019 15:13:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576077225; bh=Ub5ExGE3yROl1e8ccWTvteE7ijPy+bCAT24O0VvYNd8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L5Z/e6s4niHsPAmeP5ICSZxQpPD6JsC1Zis/B0Jnd0p/pDg5sQcntbQUMvvvoH3x3 6dJcn7xrpYTg+uB90o9ooQU4aJEmacASKBj5AJvxb1nNvuYnfK+Cbe+WidJscsI4Je MBE11H4lfF58345MFozoW/OzXPvooj0qGhDyyhO0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Shilovsky , Aurelien Aptel , Steve French Subject: [PATCH 5.3 064/105] CIFS: Fix NULL-pointer dereference in smb2_push_mandatory_locks Date: Wed, 11 Dec 2019 16:05:53 +0100 Message-Id: <20191211150247.321102026@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.153659747@linuxfoundation.org> References: <20191211150221.153659747@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pavel Shilovsky commit 6f582b273ec23332074d970a7fb25bef835df71f upstream. Currently when the client creates a cifsFileInfo structure for a newly opened file, it allocates a list of byte-range locks with a pointer to the new cfile and attaches this list to the inode's lock list. The latter happens before initializing all other fields, e.g. cfile->tlink. Thus a partially initialized cifsFileInfo structure becomes available to other threads that walk through the inode's lock list. One example of such a thread may be an oplock break worker thread that tries to push all cached byte-range locks. This causes NULL-pointer dereference in smb2_push_mandatory_locks() when accessing cfile->tlink: [598428.945633] BUG: kernel NULL pointer dereference, address: 0000000000000038 ... [598428.945749] Workqueue: cifsoplockd cifs_oplock_break [cifs] [598428.945793] RIP: 0010:smb2_push_mandatory_locks+0xd6/0x5a0 [cifs] ... [598428.945834] Call Trace: [598428.945870] ? cifs_revalidate_mapping+0x45/0x90 [cifs] [598428.945901] cifs_oplock_break+0x13d/0x450 [cifs] [598428.945909] process_one_work+0x1db/0x380 [598428.945914] worker_thread+0x4d/0x400 [598428.945921] kthread+0x104/0x140 [598428.945925] ? process_one_work+0x380/0x380 [598428.945931] ? kthread_park+0x80/0x80 [598428.945937] ret_from_fork+0x35/0x40 Fix this by reordering initialization steps of the cifsFileInfo structure: initialize all the fields first and then add the new byte-range lock list to the inode's lock list. Cc: Stable Signed-off-by: Pavel Shilovsky Reviewed-by: Aurelien Aptel Signed-off-by: Steve French Signed-off-by: Greg Kroah-Hartman --- fs/cifs/file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) --- a/fs/cifs/file.c +++ b/fs/cifs/file.c @@ -313,9 +313,6 @@ cifs_new_fileinfo(struct cifs_fid *fid, INIT_LIST_HEAD(&fdlocks->locks); fdlocks->cfile = cfile; cfile->llist = fdlocks; - cifs_down_write(&cinode->lock_sem); - list_add(&fdlocks->llist, &cinode->llist); - up_write(&cinode->lock_sem); cfile->count = 1; cfile->pid = current->tgid; @@ -339,6 +336,10 @@ cifs_new_fileinfo(struct cifs_fid *fid, oplock = 0; } + cifs_down_write(&cinode->lock_sem); + list_add(&fdlocks->llist, &cinode->llist); + up_write(&cinode->lock_sem); + spin_lock(&tcon->open_file_lock); if (fid->pending_open->oplock != CIFS_OPLOCK_NO_CHANGE && oplock) oplock = fid->pending_open->oplock;