Blame SOURCES/rhbz1051649.8.patch

f43afa
From ae91e3d552aff4f0e74662d055dae06ea55eb6bc Mon Sep 17 00:00:00 2001
f43afa
From: "Frank Ch. Eigler" <fche@redhat.com>
f43afa
Date: Thu, 27 Mar 2014 21:29:04 -0400
f43afa
Subject: [PATCH] PR16766: kernel crash for failed-init module-notification
f43afa
f43afa
Suppress the module_notifier callback for cases of failure of the
f43afa
main generated systemtap module-initialization code, which checks
f43afa
build-ids, privileges, etc. etc.; we don't want any module-notifier
f43afa
callbacks after an error.
f43afa
f43afa
* runtime/transport/transport.c: Don't call module-notifier stuff
f43afa
  if initialization failed.
f43afa
* translate.cxx (emit_module_refresh): Emit code to suppress callback
f43afa
  payload if somehow the notifier got activated anyway.
f43afa
---
f43afa
 runtime/transport/transport.c | 20 ++++++++++++--------
f43afa
 translate.cxx                 | 11 +++++++++++
f43afa
 2 files changed, 23 insertions(+), 8 deletions(-)
f43afa
f43afa
diff --git a/runtime/transport/transport.c b/runtime/transport/transport.c
f43afa
index 1800764..e4d4d8e 100644
f43afa
--- a/runtime/transport/transport.c
f43afa
+++ b/runtime/transport/transport.c
f43afa
@@ -135,16 +135,20 @@ static void _stp_handle_start(struct _stp_msg_start *st)
f43afa
 
f43afa
 		_stp_target = st->target;
f43afa
 		st->res = systemtap_module_init();
f43afa
-		if (st->res == 0)
f43afa
+		if (st->res == 0) {
f43afa
 			_stp_probes_started = 1;
f43afa
 
f43afa
-                /* Register the module notifier. */
f43afa
-                if (!_stp_module_notifier_active) {
f43afa
-                        int rc = register_module_notifier(& _stp_module_notifier_nb);
f43afa
-                        if (rc == 0)
f43afa
-                                _stp_module_notifier_active = 1;
f43afa
-                        else
f43afa
-                                _stp_warn ("Cannot register module notifier (%d)\n", rc);
f43afa
+                        /* Register the module notifier ... */
f43afa
+                        /* NB: but not if the module_init stuff
f43afa
+                           failed: something nasty has happened, and
f43afa
+                           we want no further probing started.  PR16766 */
f43afa
+                        if (!_stp_module_notifier_active) {
f43afa
+                                int rc = register_module_notifier(& _stp_module_notifier_nb);
f43afa
+                                if (rc == 0)
f43afa
+                                        _stp_module_notifier_active = 1;
f43afa
+                                else
f43afa
+                                        _stp_warn ("Cannot register module notifier (%d)\n", rc);
f43afa
+                        }
f43afa
                 }
f43afa
 
f43afa
 		/* Called from the user context in response to a proc
f43afa
diff --git a/translate.cxx b/translate.cxx
f43afa
index 9903751..17dedd4 100644
f43afa
--- a/translate.cxx
f43afa
+++ b/translate.cxx
f43afa
@@ -1881,8 +1881,19 @@ c_unparser::emit_module_refresh ()
f43afa
 {
f43afa
   o->newline() << "static void systemtap_module_refresh (void) {";
f43afa
   o->newline(1) << "int i=0, j=0;"; // for derived_probe_group use
f43afa
+
f43afa
+  /* If we're not in STARTING/RUNNING state, don't try doing any work.
f43afa
+     PR16766 */
f43afa
+  o->newline() << "int state = atomic_read (session_state());";
f43afa
+  o->newline() << "if (state != STAP_SESSION_RUNNING && state != STAP_SESSION_STARTING) {";
f43afa
+  // cannot _stp_warn etc. since we're not in probe context
f43afa
+  o->newline(1) << "printk (KERN_ERR \"stap module notifier triggered in unexpected state %d\", state);";
f43afa
+  o->newline() << "return;";
f43afa
+  o->newline(-1) << "}";
f43afa
+
f43afa
   o->newline() << "(void) i;";
f43afa
   o->newline() << "(void) j;";
f43afa
+
f43afa
   vector<derived_probe_group*> g = all_session_groups (*session);
f43afa
   for (unsigned i=0; i
f43afa
     {
f43afa
-- 
f43afa
1.8.3.1
f43afa