Patch "binder: validate alloc->mm in ->mmap() handler" has been added to the 5.15-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    binder: validate alloc->mm in ->mmap() handler

to the 5.15-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     binder-validate-alloc-mm-in-mmap-handler.patch
and it can be found in the queue-5.15 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit fb3a616383db1095d3df8b5122410d5006464e79
Author: Carlos Llamas <cmllamas@xxxxxxxxxx>
Date:   Fri Nov 4 23:12:35 2022 +0000

    binder: validate alloc->mm in ->mmap() handler
    
    [ Upstream commit 3ce00bb7e91cf57d723905371507af57182c37ef ]
    
    Since commit 1da52815d5f1 ("binder: fix alloc->vma_vm_mm null-ptr
    dereference") binder caches a pointer to the current->mm during open().
    This fixes a null-ptr dereference reported by syzkaller. Unfortunately,
    it also opens the door for a process to update its mm after the open(),
    (e.g. via execve) making the cached alloc->mm pointer invalid.
    
    Things get worse when the process continues to mmap() a vma. From this
    point forward, binder will attempt to find this vma using an obsolete
    alloc->mm reference. Such as in binder_update_page_range(), where the
    wrong vma is obtained via vma_lookup(), yet binder proceeds to happily
    insert new pages into it.
    
    To avoid this issue fail the ->mmap() callback if we detect a mismatch
    between the vma->vm_mm and the original alloc->mm pointer. This prevents
    alloc->vm_addr from getting set, so that any subsequent vma_lookup()
    calls fail as expected.
    
    Fixes: 1da52815d5f1 ("binder: fix alloc->vma_vm_mm null-ptr dereference")
    Reported-by: Jann Horn <jannh@xxxxxxxxxx>
    Cc: <stable@xxxxxxxxxxxxxxx> # 5.15+
    Signed-off-by: Carlos Llamas <cmllamas@xxxxxxxxxx>
    Acked-by: Todd Kjos <tkjos@xxxxxxxxxx>
    Link: https://lore.kernel.org/r/20221104231235.348958-1-cmllamas@xxxxxxxxxx
    Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/drivers/android/binder_alloc.c b/drivers/android/binder_alloc.c
index 8ed450125c92..6acfb896b2e5 100644
--- a/drivers/android/binder_alloc.c
+++ b/drivers/android/binder_alloc.c
@@ -753,6 +753,12 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
 	const char *failure_string;
 	struct binder_buffer *buffer;
 
+	if (unlikely(vma->vm_mm != alloc->vma_vm_mm)) {
+		ret = -EINVAL;
+		failure_string = "invalid vma->vm_mm";
+		goto err_invalid_mm;
+	}
+
 	mutex_lock(&binder_alloc_mmap_lock);
 	if (alloc->buffer_size) {
 		ret = -EBUSY;
@@ -799,6 +805,7 @@ int binder_alloc_mmap_handler(struct binder_alloc *alloc,
 	alloc->buffer_size = 0;
 err_already_mapped:
 	mutex_unlock(&binder_alloc_mmap_lock);
+err_invalid_mm:
 	binder_alloc_debug(BINDER_DEBUG_USER_ERROR,
 			   "%s: %d %lx-%lx %s failed %d\n", __func__,
 			   alloc->pid, vma->vm_start, vma->vm_end,



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux