Skip to content

Commit faf3c92

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
mm: fix vma_start_write_killable() signal handling
If we get a signal, we need to restore the vm_refcnt. We don't think that the refcount can actually be decremented to zero here as it requires the VMA to be detached, and the vma_mark_detached() uses TASK_UNINTERRUPTIBLE. However, that's a bit subtle, so handle it as if the refcount was zero at the start of this function. Link: https://lkml.kernel.org/r/20251128040100.3022561-1-willy@infradead.org Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reported-by: syzbot+5b19bad23ac7f44bf8b8@syzkaller.appspotmail.com Fixes: 2197bb6 ("mm: add vma_start_write_killable()") Reviewed-by: Suren Baghdasaryan <surenb@google.com> Reviewed-by: Vlastimil Babka <vbabka@suse.cz> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com> Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent b60a3ef commit faf3c92

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

mm/mmap_lock.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ static inline int __vma_enter_locked(struct vm_area_struct *vma,
7474
refcount_read(&vma->vm_refcnt) == tgt_refcnt,
7575
state);
7676
if (err) {
77+
if (refcount_sub_and_test(VMA_LOCK_OFFSET, &vma->vm_refcnt)) {
78+
/*
79+
* The wait failed, but the last reader went away
80+
* as well. Tell the caller the VMA is detached.
81+
*/
82+
WARN_ON_ONCE(!detaching);
83+
err = 0;
84+
}
7785
rwsem_release(&vma->vmlock_dep_map, _RET_IP_);
7886
return err;
7987
}

0 commit comments

Comments
 (0)