login
Header Space

 
 

Re: on CONFIG_MM_OWNER=y, kernel panic is possible.

Previous thread: unkillable process during core dump by Alexander V. Lukyanov on Tuesday, May 6, 2008 - 12:58 am. (1 message)

Next thread: AIM7 40% regression with 2.6.26-rc1 by Zhang, Yanmin on Tuesday, May 6, 2008 - 1:48 am. (140 messages)
To: Lee Schermerhorn <Lee.Schermerhorn@...>, KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>, Balbir Singh <balbir@...>, LKML <linux-kernel@...>, linux-mm <linux-mm@...>, Andrew Morton <akpm@...>
Cc: <kosaki.motohiro@...>
Date: Tuesday, May 6, 2008 - 1:40 am

on CONFIG_MM_OWNER=y (that is automatically turned on by mem-cgroup),
kernel panic is possible by following scenario in mm_update_next_owner().

1. mm_update_next_owner() is called.
2. found caller task in do_each_thread() loop.
3. thus, BUG_ON(c == p) is true, it become kernel panic.

end up, We should left out current task.


Signed-off-by: KOSAKI Motohiro &lt;kosaki.motohiro@jp.fujitsu.com&gt;
CC: Lee Schermerhorn &lt;Lee.Schermerhorn@hp.com&gt;
CC: KAMEZAWA Hiroyuki &lt;kamezawa.hiroyu@jp.fujitsu.com&gt;
CC: Balbir Singh &lt;balbir@linux.vnet.ibm.com&gt;

---
 kernel/exit.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: b/kernel/exit.c
===================================================================
--- a/kernel/exit.c     2008-05-04 22:57:23.000000000 +0900
+++ b/kernel/exit.c     2008-05-06 15:01:26.000000000 +0900
@@ -627,7 +627,7 @@ retry:
         * here often
         */
        do_each_thread(g, c) {
-               if (c-&gt;mm == mm)
+               if ((c != p) &amp;&amp; (c-&gt;mm == mm))
                        goto assign_new_owner;
        } while_each_thread(g, c);


--
To: KOSAKI Motohiro <kosaki.motohiro@...>
Cc: Lee Schermerhorn <Lee.Schermerhorn@...>, KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>, LKML <linux-kernel@...>, linux-mm <linux-mm@...>, Andrew Morton <akpm@...>
Date: Tuesday, May 6, 2008 - 1:48 am

That is not possible. If you look at where mm_update_next_owner() is called
from, we call it from

exit_mm() and exec_mmap()

In both cases, we ensure that the task's mm has changed (to NULL and the new mm
respectively), before we call mm_update_next_owner(), hence c-&gt;mm can never be
equal to p-&gt;mm.

-- 
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL
--
To: <balbir@...>
Cc: <kosaki.motohiro@...>, Lee Schermerhorn <Lee.Schermerhorn@...>, KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>, LKML <linux-kernel@...>, linux-mm <linux-mm@...>, Andrew Morton <akpm@...>
Date: Tuesday, May 6, 2008 - 2:03 am

if so, following patch is needed instead.



---
 fs/exec.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Index: b/fs/exec.c
===================================================================
--- a/fs/exec.c 2008-05-04 22:57:09.000000000 +0900
+++ b/fs/exec.c 2008-05-06 15:40:35.000000000 +0900
@@ -735,7 +735,7 @@ static int exec_mmap(struct mm_struct *m
        tsk-&gt;active_mm = mm;
        activate_mm(active_mm, mm);
        task_unlock(tsk);
-       mm_update_next_owner(mm);
+       mm_update_next_owner(old_mm);
        arch_pick_mmap_layout(mm);
        if (old_mm) {
                up_read(&amp;old_mm-&gt;mmap_sem);


--
To: KOSAKI Motohiro <kosaki.motohiro@...>
Cc: Lee Schermerhorn <Lee.Schermerhorn@...>, KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>, LKML <linux-kernel@...>, linux-mm <linux-mm@...>, Andrew Morton <akpm@...>, Paul Menage <menage@...>
Date: Tuesday, May 6, 2008 - 2:32 am

Yes, good catch.

Acked-by: Balbir Singh &lt;balbir@linux.vnet.ibm.com&gt;

I'll go ahead and do some more testing on top of it. CC'ing Paul Menage as well.

-- 
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL
--
To: <balbir@...>
Cc: <kosaki.motohiro@...>, Lee Schermerhorn <Lee.Schermerhorn@...>, KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>, LKML <linux-kernel@...>, linux-mm <linux-mm@...>, Andrew Morton <akpm@...>
Date: Tuesday, May 6, 2008 - 2:18 am

and, one more.

comment of owner member of mm_struct is bogus.
that is not guranteed point to thread-group-leader.


Signed-off-by: KOSAKI Motohiro &lt;kosaki.motohiro@jp.fujitsu.com&gt;

---
 include/linux/mm_types.h |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Index: b/include/linux/mm_types.h
===================================================================
--- a/include/linux/mm_types.h  2008-05-04 22:56:52.000000000 +0900
+++ b/include/linux/mm_types.h  2008-05-06 15:53:04.000000000 +0900
@@ -231,8 +231,7 @@ struct mm_struct {
        rwlock_t                ioctx_list_lock;        /* aio lock */
        struct kioctx           *ioctx_list;
 #ifdef CONFIG_MM_OWNER
-       struct task_struct *owner;      /* The thread group leader that */
-                                       /* owns the mm_struct.          */
+       struct task_struct *owner;      /* point to one of task that owns the mm_struct. */
 #endif

 #ifdef CONFIG_PROC_FS



--
To: KOSAKI Motohiro <kosaki.motohiro@...>
Cc: Lee Schermerhorn <Lee.Schermerhorn@...>, KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>, LKML <linux-kernel@...>, linux-mm <linux-mm@...>, Andrew Morton <akpm@...>
Date: Tuesday, May 6, 2008 - 2:28 am

How about just, the task that owns the mm_struct? One of, implies multiple owners.


-- 
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL
--
To: <balbir@...>
Cc: <kosaki.motohiro@...>, Lee Schermerhorn <Lee.Schermerhorn@...>, KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>, LKML <linux-kernel@...>, linux-mm <linux-mm@...>, Andrew Morton <akpm@...>
Date: Tuesday, May 6, 2008 - 2:43 am

Ah, below is better?

/* point to any one of task that related the mm_struct. */


my intention is only remove "thread group leader" word.
other things, I obey your favor. 

Cheers!



--
To: KOSAKI Motohiro <kosaki.motohiro@...>
Cc: <balbir@...>, Lee Schermerhorn <Lee.Schermerhorn@...>, KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>, LKML <linux-kernel@...>, linux-mm <linux-mm@...>, Andrew Morton <akpm@...>
Date: Tuesday, May 6, 2008 - 11:37 pm

On Mon, May 5, 2008 at 11:43 PM, KOSAKI Motohiro

I'd word it as

/*
 * "owner" points to a task that is regarded as the canonical
 * user/owner of this mm. All of the following must be true in
 * order for it to be changed:
 *
 * current == mm-&gt;owner
 * current-&gt;mm != mm
 * new_owner-&gt;mm == mm
 * new_owner-&gt;alloc_lock is held
 */

Paul
--
To: Paul Menage <menage@...>, <balbir@...>, Andrew Morton <akpm@...>
Cc: <kosaki.motohiro@...>, Lee Schermerhorn <Lee.Schermerhorn@...>, KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>, LKML <linux-kernel@...>, linux-mm <linux-mm@...>
Date: Wednesday, May 7, 2008 - 7:55 pm

Wow, Thank you a lot!
new version attached.

Cheers!


-----------------------------------------------------------
When mm destruct happend, We should pass mm_update_next_owner() 
old mm.
but unfortunately new mm is passed in exec_mmap().

thus, kernel panic is possible when multi thread process use exec().


and, owner member comment description is wrong.
mm-&gt;owner don't not necessarily point to thread group leader.


Signed-off-by: KOSAKI Motohiro &lt;kosaki.motohiro@jp.fujitsu.com&gt;
CC: Balbir Singh &lt;balbir@linux.vnet.ibm.com&gt;
CC: "Paul Menage" &lt;menage@google.com&gt;
CC: "KAMEZAWA Hiroyuki" &lt;kamezawa.hiroyu@jp.fujitsu.com&gt;

---
 fs/exec.c                |    2 +-
 include/linux/mm_types.h |   13 +++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

Index: b/fs/exec.c
===================================================================
--- a/fs/exec.c	2008-05-04 22:57:09.000000000 +0900
+++ b/fs/exec.c	2008-05-06 15:40:35.000000000 +0900
@@ -735,7 +735,7 @@ static int exec_mmap(struct mm_struct *m
 	tsk-&gt;active_mm = mm;
 	activate_mm(active_mm, mm);
 	task_unlock(tsk);
-	mm_update_next_owner(mm);
+	mm_update_next_owner(old_mm);
 	arch_pick_mmap_layout(mm);
 	if (old_mm) {
 		up_read(&amp;old_mm-&gt;mmap_sem);
Index: b/include/linux/mm_types.h
===================================================================
--- a/include/linux/mm_types.h	2008-05-08 09:20:13.000000000 +0900
+++ b/include/linux/mm_types.h	2008-05-08 09:22:13.000000000 +0900
@@ -231,8 +231,17 @@ struct mm_struct {
 	rwlock_t		ioctx_list_lock;	/* aio lock */
 	struct kioctx		*ioctx_list;
 #ifdef CONFIG_MM_OWNER
-	struct task_struct *owner;	/* The thread group leader that */
-					/* owns the mm_struct.		*/
+        /*
+         * "owner" points to a task that is regarded as the canonical
+         * user/owner of this mm. All of the following must be true in
+         * order for it to be changed:
+         *
+         * current == mm-&gt;owner
+         ...
To: KOSAKI Motohiro <kosaki.motohiro@...>
Cc: Paul Menage <menage@...>, Andrew Morton <akpm@...>, Lee Schermerhorn <Lee.Schermerhorn@...>, KAMEZAWA Hiroyuki <kamezawa.hiroyu@...>, LKML <linux-kernel@...>, linux-mm <linux-mm@...>
Date: Thursday, May 8, 2008 - 9:53 am

Looks good to me, but I've not tested it

Acked-by: Balbir Singh &lt;balbir@linux.vnet.ibm.com&gt;

-- 
	Warm Regards,
	Balbir Singh
	Linux Technology Center
	IBM, ISTL
--
Previous thread: unkillable process during core dump by Alexander V. Lukyanov on Tuesday, May 6, 2008 - 12:58 am. (1 message)

Next thread: AIM7 40% regression with 2.6.26-rc1 by Zhang, Yanmin on Tuesday, May 6, 2008 - 1:48 am. (140 messages)
speck-geostationary