Fix mm->owner point to a tsk that has been free
PATCH 1/1 Fix mm->owner point to a tsk that has been free
From: guomin chen <[email protected]>
When mm->owner is modified by exit_mm, if the new owner directly calls unuse_mm to exit, it will cause Use-After-Free. Due to the unuse_mm() directly sets tsk->mm=NULL.
Under normal circumstances,When do_exit exits, mm->owner will be updated on exit_mm(). but when the kernel process calls unuse_mm() and then exits,mm->owner cannot be updated. And it will point to a task that has been released.
The current issue flow is as follows: (Process A,B,C use the same mm)
Process C Process A Process B
qemu-system-x86_64: kernel:vhost_net kernel: vhost_net
open /dev/vhost-net
VHOST_SET_OWNER create kthread vhost-%d create kthread vhost-%d
network init use_mm() use_mm()
... ...
Abnormal exited
...
do_exit
exit_mm()
update mm->owner to A
exit_files()
close_files()
kthread_should_stop() unuse_mm()
Stop Process A tsk->mm=NULL
do_exit()
can't update owner
A exit completed vhost-%d rcv first package
vhost-%d build rcv buffer for vq page fault
access mm & mm->owner NOW,mm->owner still pointer A kernel UAF
stop Process B
Although I am having this issue on vhost_net,But it affects all users of unuse_mm.
--- mm/mmu_context.c | 1 + 1 file changed, 1 insertion(+)
mm/mmu_context.c +1 -0
@@ -60,5 +60,6 @@ void unuse_mm(struct mm_struct *mm)/* active_mm is still 'mm' */ enter_lazy_tlb (mm, tsk);task_unlock (tsk); +mm_update_next_owner (mm); }EXPORT_SYMBOL_GPL (unuse_mm);
Signature · 1 line
1.8.3.1
Quoted 37 lines · On Tue 18-12-18 13:24:44, [email protected] wrote:
From: guomin chen <[email protected]>
When
mm->owneris modified byexit_mm, if the new owner directly callsunuse_mmto exit, it will cause Use-After-Free. Due to theunuse_mm()directly sets tsk->mm=NULL.Under normal circumstances,When
do_exitexits,mm->ownerwill be updated onexit_mm(). but when the kernel process callsunuse_mm()and then exits,mm->owner cannot be updated. And it will point to a task that has been released.The current issue flow is as follows: (Process A,B,C use the same mm)
Process C Process A Process B
qemu-system-x86_64: kernel:vhost_net kernel:vhost_net
open/dev/vhost-net
VHOST_SET_OWNERcreate kthread vhost-%d create kthread vhost-%d
network inituse_mm()use_mm()
... ...
Abnormal exited
...
do_exit
exit_mm()
updatemm->ownerto A
exit_files()
close_files()
kthread_should_stop()unuse_mm()
Stop Process A tsk->mm=NULL
do_exit()
can't update owner
A exit completed vhost-%d rcv first package
vhost-%d build rcv buffer for vq page fault
access mm &mm->ownerNOW,mm->owner still pointer A kernel UAF
stop Process B
Quoted 2 lines
Although I am having this issue on vhost_net,But it affects all users of
unuse_mm.
I am confused. How can we ever assign the owner to a kernel thread. We skip those explicitly. It simply doesn't make any sense to have an owner a kernel thread.
Signature · 2 lines
Michal Hocko SUSE Labs
Oh, yes, the patch 39af176 has been skip the kthread on mm_update_next_owner .
Thanks for your tips.
thanks and regards
Quoted 49 lines · Michal Hocko <[email protected]> 于2018年12月18日周二 下午5:52写道:
Quoted 23 lines · On Tue 18-12-18 13:24:44, [email protected] wrote:
From: guomin chen <[email protected]>
When
mm->owneris modified byexit_mm, if the new owner directly callsunuse_mmto exit, it will cause Use-After-Free. Due to theunuse_mm()directly sets tsk->mm=NULL.Under normal circumstances,When
do_exitexits,mm->ownerwill be updated onexit_mm(). but when the kernel process callsunuse_mm()and then exits,mm->owner cannot be updated. And it will point to a task that has been released.The current issue flow is as follows: (Process A,B,C use the same mm)
Process C Process A Process B
qemu-system-x86_64: kernel:vhost_net kernel:vhost_net
open/dev/vhost-net
VHOST_SET_OWNERcreate kthread vhost-%d create kthread vhost-%d
network inituse_mm()use_mm()
... ...
Abnormal exited
...
do_exit
exit_mm()
updatemm->ownerto AQuoted 8 lines
exit_files()
close_files()
kthread_should_stop()unuse_mm()
Stop Process A tsk->mm=NULL
do_exit()
can't update owner
A exit completed vhost-%d rcv first package
vhost-%d build rcv buffer forvq
Quoted 8 lines
page fault access mm & mm->owner NOW,mm->owner still pointer A kernel UAF stop Process BAlthough I am having this issue on vhost_net,But it affects all users of
unuse_mm.I am confused. How can we ever assign the owner to a kernel thread. We skip those explicitly. It simply doesn't make any sense to have an owner a kernel thread.
--
Michal Hocko
SUSE Labs
Quoted 2 lines · gchen chen
Oh, yes, the patch 39af176 has been skip the kthread on
mm_update_next_owner.
Actually f87fb599ae4