general protection fault in unlink_file_vma
Subsystems (2)
Hi:
Quoted 6 lines · Hillf Danton
Tue, 08 Sep 2020 17:19:17 -0700
Quoted 5 lines
syzbot found the following issue on:
general protection fault, probably for non-canonical address 0xe00eeaee0000003b: 0000 [#1] PREEMPT SMP KASAN KASAN: maybe wild-memory-access in range[0x00777770000001d8-0x00777770000001df]
...
Quoted 8 lines
Quoted 1 line
entry_SYSCALL_64_after_hwframe+0x44/0xa9Looks like
d70cec898324("mm: mmap: merge vma aftercall_mmap()if possible") added an extra fput.
mm/mmap.c unsigned long mmap_region(struct file *f · line 1786
Quoted 7 lines
mm/mmap.c +0
-1@@ -1781,7 +1781,6 @@ unsigned long mmap_region(struct file *f merge =vma_merge (mm, prev, vma->vm_start, vma->vm_end, vma->vm_flags,NULL , vma->vm_file, vma->vm_pgoff,NULL ,NULL_VM_UFFD_CTX );if (merge) { -fput (file);vm_area_free (vma); vma = merge;/* Update vm_flags and possible addr to pick up the change. We don't
I reviewed the code carefully these days and I found vma_merge() do only fput() the vm_file of the linked vma in remove_next cases. This gpf is much likely because the ->mmap() callback can change vma->vm_file and fput the original file. But my previous commit failed to catch this case and always fput() the original file, hence add an extra fput().
The below patch would make the things right:
mm/mmap.c +5 -1
@@ -1816,7 +1816,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr, merge =vma_merge (mm, prev, vma->vm_start, vma->vm_end, vma->vm_flags,NULL , vma->vm_file, vma->vm_pgoff,NULL ,NULL_VM_UFFD_CTX );if (merge) { -fput (file); +/* ->mmap() can change vma->vm_file and fput the original file. So +* fput the vma->vm_file here or we would add an extra fput for file +* and cause general protection fault ultimately. +*/ +fput (vma->vm_file);vm_area_free (vma); vma = merge;/* Update vm_flags and possible addr to pick up the change. We don't
It's very nice of you if you could help test this patch as I can't reproduce it in my product environment. And many thanks for a possible Tested-by tag.
Thanks again.
Quoted 24 lines · On Sun, 13 Sep 2020 09:17:26 +0000 linmiaohe wrote:
I reviewed the code carefully these days and I found
vma_merge()do onlyfput()thevm_fileof the linked vma inremove_nextcases. This gpf is much likely because the ->mmap() callback can changevma->vm_fileand fput the original file. But my previous commit failed to catch this case and alwaysfput()the original file, hence add an extrafput().
The below patch would make the things right:mm/mmap.c +5
-1@@ -1816,7 +1816,11 @@ unsigned long mmap_region(struct file *file, unsigned long addr, merge =vma_merge (mm, prev, vma->vm_start, vma->vm_end, vma->vm_flags,NULL , vma->vm_file, vma->vm_pgoff,NULL ,NULL_VM_UFFD_CTX );if (merge) { -fput (file); +/* ->mmap() can change vma->vm_file and fput the original file. So +* fput the vma->vm_file here or we would add an extra fput for file +* and cause general protection fault ultimately. +*/ +fput (vma->vm_file);vm_area_free (vma); vma = merge;/* Update vm_flags and possible addr to pick up the change. We don't
Quoted 2 lines
It's very nice of you if you could help test this patch as I can't reproduce it in my product environment. And many thanks for a possible Tested-by tag.
Take another look at the Cc list and the link below.