linux-task-pointer-safety-20070320
authorChaskiel M Grundman <cg2v@andrew.cmu.edu>
Tue, 20 Mar 2007 18:45:58 +0000 (18:45 +0000)
committerDerrick Brashear <shadow@dementia.org>
Tue, 20 Mar 2007 18:45:58 +0000 (18:45 +0000)
hold applicable locks while futzing with task list

src/afs/LINUX/osi_groups.c
src/rx/LINUX/rx_knet.c

index 997ec7a..c0d8270 100644 (file)
@@ -617,13 +617,36 @@ struct key_type key_type_afs_pag =
     .destroy     = afs_pag_destroy,
 };
 
+#ifdef EXPORTED_TASKLIST_LOCK
+extern rwlock_t tasklist_lock __attribute__((weak));
+#endif
+
 void osi_keyring_init(void)
 {
     struct task_struct *p;
-
+#ifdef EXPORTED_TASKLIST_LOCK
+    if (&tasklist_lock)
+      read_lock(&tasklist_lock);
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
+#ifdef EXPORTED_TASKLIST_LOCK
+    else
+#endif
+      rcu_read_lock();
+#endif
     p = find_task_by_pid(1);
     if (p && p->user->session_keyring)
        __key_type_keyring = p->user->session_keyring->type;
+#ifdef EXPORTED_TASKLIST_LOCK
+    if (&tasklist_lock)
+       read_unlock(&tasklist_lock);
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
+#ifdef EXPORTED_TASKLIST_LOCK
+    else
+#endif
+      rcu_read_unlock();
+#endif
 
     register_key_type(&key_type_afs_pag);
 }
index 8587b0d..f1b3667 100644 (file)
@@ -213,30 +213,34 @@ osi_StopListener(void)
     struct task_struct *listener;
     extern int rxk_ListenerPid;
 
+    while (rxk_ListenerPid) {
 #ifdef EXPORTED_TASKLIST_LOCK
-    if (&tasklist_lock)
-      read_lock(&tasklist_lock);
+       if (&tasklist_lock)
+          read_lock(&tasklist_lock);
 #endif
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
 #ifdef EXPORTED_TASKLIST_LOCK
-    else
+       else
 #endif
-      rcu_read_lock();
+          rcu_read_lock();
 #endif
-    listener = find_task_by_pid(rxk_ListenerPid);
+       listener = find_task_by_pid(rxk_ListenerPid);
+        if (listener) {
+           flush_signals(listener);
+           force_sig(SIGKILL, listener);
+       }
 #ifdef EXPORTED_TASKLIST_LOCK
-    if (&tasklist_lock)
-       read_unlock(&tasklist_lock);
+       if (&tasklist_lock)
+           read_unlock(&tasklist_lock);
 #endif
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
 #ifdef EXPORTED_TASKLIST_LOCK
-    else
+       else
 #endif
-      rcu_read_unlock();
+          rcu_read_unlock();
 #endif
-    while (rxk_ListenerPid) {
-       flush_signals(listener);
-       force_sig(SIGKILL, listener);
+       if (!listener)
+           break;
        afs_osi_Sleep(&rxk_ListenerPid);
     }
     sock_release(rx_socket);