STABLE14-linux-task-pointer-safety-20070320

hold applicable locks while futzing with task list


(cherry picked from commit 29951ff73ccc82746f8f842131a76e30b47d5310)
This commit is contained in:
Chaskiel M Grundman 2007-03-20 18:48:52 +00:00 committed by Derrick Brashear
parent 021b05f99d
commit 3f85007dfb
2 changed files with 51 additions and 24 deletions

View 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);
}

View File

@ -213,30 +213,34 @@ osi_StopListener(void)
struct task_struct *listener;
extern int rxk_ListenerPid;
#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
listener = find_task_by_pid(rxk_ListenerPid);
#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
while (rxk_ListenerPid) {
flush_signals(listener);
force_sig(SIGKILL, listener);
#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
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);
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
#ifdef EXPORTED_TASKLIST_LOCK
else
#endif
rcu_read_unlock();
#endif
if (!listener)
break;
afs_osi_Sleep(&rxk_ListenerPid);
}
sock_release(rx_socket);