Messages in this thread Patch in this message | | | Date | Thu, 6 Jul 2000 14:37:57 +0200 | Subject | 2.2.x: bugs in tasklist_lock usage? | From | <> |
| |
Hi all
In many files & functions of the kernel that use the tasklist_lock it unlocks this lock before it stops using references to the task pointer It has been get with the kernel lock (fs/proc/array.c is a file with many examples). I think this way the task could exit on other processor and then the references will be bogus.
An example this is the function linux-2.2.x/fs/proc/array.c:get_env(), and even they notice it:
read_unlock(&tasklist_lock); /* FIXME!! This should be done after the last use */
I have made a propossal patch of how I think it should be (see below)
__please_reply_this_questions__:
- Is it a real bug?
- Have I fixed it correctly?
Please CC: your comments to uaca@alumni.uv.es
The example code patch follows:
--- array.c Wed Jun 7 23:26:44 2000 +++ array.c.modified Thu Jul 6 14:21:12 2000 @@ -483,14 +483,25 @@ static int get_env(int pid, char * buffer) { struct task_struct *p; - + int retval; + read_lock(&tasklist_lock); p = find_task_by_pid(pid); - read_unlock(&tasklist_lock); /* FIXME!! This should be done after the last use */ - if (!p || !p->mm) + /* If unlock the tasklist_lock before use this, the task could exit + * on other processor and then the references be bogus, this also + * happens on other functions that use the tasklist_lock + */ + if (!p && !p->mm) { /* We need both p and p->mm valid (non-NULL) pointers */ + read_unlock(&tasklist_lock); return 0; - return get_array(p, p->mm->env_start, p->mm->env_end, buffer); + } + + /* Seems get_array() can't sleep */ + retval= get_array(p, p->mm->env_start, p->mm->env_end, buffer); + read_unlock(&tasklist_lock); + + return retval; } static int get_arg(int pid, char * buffer)
Debian/GNU Linux: a dream come true ----------------------------------------------------------------------------- "Computers are useless. They can only give answers." Pablo Picasso ---> Visita http://www.valux.org/ para saber acerca de la <--- ---> Asociación Valenciana de Usuarios de Linux <---
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |