linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kees Cook <keescook@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>,
	Anton Vorontsov <anton@enomsg.org>,
	Colin Cross <ccross@android.com>, Tony Luck <tony.luck@intel.com>,
	Luis Henriques <lhenriques@suse.com>
Subject: [PATCH 06/10] pstore: Add proper unregister lock checking
Date: Wed,  6 May 2020 08:21:10 -0700	[thread overview]
Message-ID: <20200506152114.50375-7-keescook@chromium.org> (raw)
In-Reply-To: <20200506152114.50375-1-keescook@chromium.org>

The pstore backend lock wasn't being used during pstore_unregister().
Add sanity check and locking.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 fs/pstore/platform.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c
index d0ce22237589..03bc847a6951 100644
--- a/fs/pstore/platform.c
+++ b/fs/pstore/platform.c
@@ -69,8 +69,9 @@ static void pstore_dowork(struct work_struct *);
 static DECLARE_WORK(pstore_work, pstore_dowork);
 
 /*
- * psinfo_lock just protects "psinfo" during
- * calls to pstore_register()
+ * psinfo_lock protects "psinfo" during calls to
+ * pstore_register(), pstore_unregister(), and
+ * the filesystem mount/unmount routines.
  */
 static DEFINE_MUTEX(psinfo_lock);
 struct pstore_info *psinfo;
@@ -626,6 +627,18 @@ EXPORT_SYMBOL_GPL(pstore_register);
 
 void pstore_unregister(struct pstore_info *psi)
 {
+	/* It's okay to unregister nothing. */
+	if (!psi)
+		return;
+
+	mutex_lock(&psinfo_lock);
+
+	/* Only one backend can be registered at a time. */
+	if (WARN_ON(psi != psinfo)) {
+		mutex_unlock(&psinfo_lock);
+		return;
+	}
+
 	/* Stop timer and make sure all work has finished. */
 	pstore_update_ms = -1;
 	del_timer_sync(&pstore_timer);
@@ -644,6 +657,7 @@ void pstore_unregister(struct pstore_info *psi)
 
 	psinfo = NULL;
 	backend = NULL;
+	mutex_unlock(&psinfo_lock);
 }
 EXPORT_SYMBOL_GPL(pstore_unregister);
 
-- 
2.20.1


  parent reply	other threads:[~2020-05-06 15:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-06 15:21 [PATCH 00/10] pstore: Remove filesystem records when backend is unregistered Kees Cook
2020-05-06 15:21 ` [PATCH 01/10] pstore: Drop useless try_module_get() for backend Kees Cook
2020-05-06 15:21 ` [PATCH 02/10] pstore: Rename "pstore_lock" to "psinfo_lock" Kees Cook
2020-05-06 15:21 ` [PATCH 03/10] pstore: Convert "psinfo" locking to mutex Kees Cook
2020-05-06 15:21 ` [PATCH 04/10] pstore: Rename "allpstore" to "records_list" Kees Cook
2020-05-06 15:21 ` [PATCH 05/10] pstore: Convert "records_list" locking to mutex Kees Cook
2020-05-06 15:21 ` Kees Cook [this message]
2020-05-06 15:21 ` [PATCH 07/10] pstore: Refactor pstorefs record list removal Kees Cook
2020-05-06 15:21 ` [PATCH 08/10] pstore: Add locking around superblock changes Kees Cook
2020-05-06 15:21 ` [PATCH 09/10] pstore: Do not leave timer disabled for next backend Kees Cook
2020-05-06 15:21 ` [PATCH 10/10] pstore: Remove filesystem records when backend is unregistered Kees Cook

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200506152114.50375-7-keescook@chromium.org \
    --to=keescook@chromium.org \
    --cc=anton@enomsg.org \
    --cc=ccross@android.com \
    --cc=lhenriques@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tony.luck@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).