1 From 6330d5534786d5315d56d558aa6d20740f97d80a Mon Sep 17 00:00:00 2001
2 From: Kees Cook <keescook@chromium.org>
3 Date: Mon, 6 Mar 2017 12:42:12 -0800
4 Subject: pstore: Shut down worker when unregistering
6 From: Kees Cook <keescook@chromium.org>
8 commit 6330d5534786d5315d56d558aa6d20740f97d80a upstream.
10 When built as a module and running with update_ms >= 0, pstore will Oops
11 during module unload since the work timer is still running. This makes sure
12 the worker is stopped before unloading.
14 Signed-off-by: Kees Cook <keescook@chromium.org>
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
18 fs/pstore/platform.c | 10 +++++++++-
19 1 file changed, 9 insertions(+), 1 deletion(-)
21 --- a/fs/pstore/platform.c
22 +++ b/fs/pstore/platform.c
23 @@ -709,6 +709,7 @@ int pstore_register(struct pstore_info *
24 if (psi->flags & PSTORE_FLAGS_PMSG)
25 pstore_register_pmsg();
27 + /* Start watching for new records, if desired. */
28 if (pstore_update_ms >= 0) {
29 pstore_timer.expires = jiffies +
30 msecs_to_jiffies(pstore_update_ms);
31 @@ -731,6 +732,11 @@ EXPORT_SYMBOL_GPL(pstore_register);
33 void pstore_unregister(struct pstore_info *psi)
35 + /* Stop timer and make sure all work has finished. */
36 + pstore_update_ms = -1;
37 + del_timer_sync(&pstore_timer);
38 + flush_work(&pstore_work);
40 if (psi->flags & PSTORE_FLAGS_PMSG)
41 pstore_unregister_pmsg();
42 if (psi->flags & PSTORE_FLAGS_FTRACE)
43 @@ -830,7 +836,9 @@ static void pstore_timefunc(unsigned lon
44 schedule_work(&pstore_work);
47 - mod_timer(&pstore_timer, jiffies + msecs_to_jiffies(pstore_update_ms));
48 + if (pstore_update_ms >= 0)
49 + mod_timer(&pstore_timer,
50 + jiffies + msecs_to_jiffies(pstore_update_ms));
53 module_param(backend, charp, 0444);