From 3f85007dfb37badab0def30cf7bb40b0bdb2ccd8 Mon Sep 17 00:00:00 2001 From: Chaskiel M Grundman Date: Tue, 20 Mar 2007 18:48:52 +0000 Subject: [PATCH] STABLE14-linux-task-pointer-safety-20070320 hold applicable locks while futzing with task list (cherry picked from commit 29951ff73ccc82746f8f842131a76e30b47d5310) --- src/afs/LINUX/osi_groups.c | 25 ++++++++++++++++++- src/rx/LINUX/rx_knet.c | 50 ++++++++++++++++++++------------------ 2 files changed, 51 insertions(+), 24 deletions(-) diff --git a/src/afs/LINUX/osi_groups.c b/src/afs/LINUX/osi_groups.c index 997ec7a684..c0d8270279 100644 --- a/src/afs/LINUX/osi_groups.c +++ b/src/afs/LINUX/osi_groups.c @@ -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); } diff --git a/src/rx/LINUX/rx_knet.c b/src/rx/LINUX/rx_knet.c index 8587b0d0ac..f1b366769a 100644 --- a/src/rx/LINUX/rx_knet.c +++ b/src/rx/LINUX/rx_knet.c @@ -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);