Fix mm->owner point to a task that does not exists
Subsystems (3)
PATCH 1/1 Fix mm->owner point to a task that does not exists
From: guominchen <[email protected]>
Under normal circumstances,When do_exit exits, mm->owner will be updated, but when the kernel process calls unuse_mm and exits, mm->owner cannot be updated. And will point to a task that has been released.
Below is my issue on vhost_net:
A, B are two kernel processes(such as vhost_worker), C is a user space process(such as qemu), and all three use the mm of the user process C.
Now, because user process C exits abnormally, the owner of this mm becomes A. When A calls unuse_mm and exits, this mm->ower still points to the A that has been released.
When B accesses this mm->owner again, A has been released.
Process A Process B
vhost_worker() vhost_worker()
--------- ---------
use_mm() use_mm()
...
unuse_mm()
tsk->mm=NULL
do_exit() page fault
exit_mm() access mm->ownercan't update owner kernel Oops
unuse_mm()
--- mm/mmu_context.c | 1 - 1 file changed, 1 deletion(-)
mm/mmu_context.c +0 -1
@@ -56,7 +56,6 @@ void unuse_mm(struct mm_struct *mm)task_lock (tsk);sync_mm_rss (mm); - tsk->mm =NULL ;/* active_mm is still 'mm' */ enter_lazy_tlb (mm, tsk);task_unlock (tsk);
Signature · 1 line
1.8.3.1
Quoted 44 lines · On Sun, Dec 09, 2018 at 03:21:17PM +0800, [email protected] wrote:
From: guominchen <[email protected]>
Under normal circumstances,When
do_exitexits,mm->ownerwill be updated, but when the kernel process callsunuse_mmand exits,mm->ownercannot be updated. And will point to a task that has been released.Below is my issue on
vhost_net:
A, B are two kernelprocesses(such as vhost_worker), C is a user space process(such as qemu), and all three use the mm of the user process C.
Now, because user process C exits abnormally, the owner of this mm becomes A. When A callsunuse_mmand exits, thismm->owerstill points to the A that has been released.
When B accesses thismm->owneragain, A has been released.Process A Process B
vhost_worker()vhost_worker()
--------- ---------
use_mm()use_mm()
...
unuse_mm()tsk->mm=NULL do_exit() page fault exit_mm() access mm->ownercan't update owner kernel Oops
unuse_mm()Cc <[email protected]>Cc <[email protected]>Cc "Michael S. Tsirkin" <[email protected]>Cc Jason Wang <[email protected]>Cc <[email protected]>Signed-off-by guominchen <[email protected]>--- mm/mmu_context.c | 1 - 1 file changed, 1 deletion(-)mm/mmu_context.c +0
-0
mm/mmu_context.c void unuse_mm(struct mm_struct *mm) · line 61
Quoted 7 lines
mm/mmu_context.c +0
-1@@ -56,7 +56,6 @@ void unuse_mm(struct mm_struct *mm)task_lock (tsk);sync_mm_rss (mm); - tsk->mm =NULL ;/* active_mm is still 'mm' */ enter_lazy_tlb (mm, tsk);task_unlock (tsk);
So that will work for vhost because we never drop the mm reference before destroying the task. I wonder whether that's true for other users though.
It would seem cleaner to onvoke some callback so tasks such as vhost can drop the reference.
And looking at all this code, I don't understand why is mm->owner safe to change like this:
mm->owner = NULL;
when users seem to use it under RCU.
Quoted 2 lines
Signature · 1 line
1.8.3.1
答复: [PATCH] Fix mm->owner point to a task that does not exists(Internet mail)
Quoted 55 lines
Quoted 44 lines
From: guominchen <[email protected]>
Under normal circumstances,When
do_exitexits,mm->ownerwill be updated, but when the kernel process callsunuse_mmand exits,mm->ownercannot be updated. And will point to a task that has been released.Below is my issue on
vhost_net:
A, B are two kernelprocesses(such as vhost_worker), C is a user space process(such as qemu), and all three use the mm of the user process C.
Now, because user process C exits abnormally, the owner of this mm becomes A. When A callsunuse_mmand exits, thismm->owerstill points to the A that has been released.
When B accesses thismm->owneragain, A has been released.Process A Process B
vhost_worker()vhost_worker()
--------- ---------
use_mm()use_mm()
...
unuse_mm()tsk->mm=NULL do_exit() page fault exit_mm() access mm->ownercan't update owner kernel Oops
unuse_mm()Cc <[email protected]>Cc <[email protected]>Cc "Michael S. Tsirkin" <[email protected]>Cc Jason Wang <[email protected]>Cc <[email protected]>Signed-off-by guominchen <[email protected]>--- mm/mmu_context.c | 1 - 1 file changed, 1 deletion(-)mm/mmu_context.c index renamed from mm/mmu_context.c +0
-03e612ae..185bb23 100644
mm/mmu_context.c void unuse_mm(struct mm_struct *mm) · line 61
Quoted 7 lines
mm/mmu_context.c +0
-1@@ -56,7 +56,6 @@ void unuse_mm(struct mm_struct *mm)task_lock (tsk);sync_mm_rss (mm); - tsk->mm =NULL ;/* active_mm is still 'mm' */ enter_lazy_tlb (mm, tsk);task_unlock (tsk);So that will work for vhost because we never drop the mm reference before destroying the task. I wonder whether that's true for other users though.
Quoted 1 line
It would seem cleaner to onvoke some callback so tasks such as vhost can drop the reference.
Yes, I can remove this call in vhost, but I think use_mm(), and unuse_mm() are called in pairs in order to share mm.
And exit_mm() as a unified mm handler, it doing very well, So we should leave mm to exit_mm() to handle it.
Quoted 3 lines
And looking at all this code, I don't understand why is
mm->ownersafe to change like this:mm->owner = NULL;when users seem to use it under RCU.
I think that mm->owner=NULL just changes the value of the pointer, and the task_struct it points to is present and not released.
Quoted 2 lines
Quoted 2 lines
--
1.8.3.1