29 Jul, 2020

1 commit

  • commit f867c771f98891841c217fa8459244ed0dd28921 upstream.

    syzbot is reporting that mmput() from shrinker function has a risk of
    deadlock [1], for delayed_uprobe_add() from update_ref_ctr() calls
    kzalloc(GFP_KERNEL) with delayed_uprobe_lock held, and
    uprobe_clear_state() from __mmput() also holds delayed_uprobe_lock.

    Commit a1b2289cef92ef0e ("android: binder: drop lru lock in isolate
    callback") replaced mmput() with mmput_async() in order to avoid sleeping
    with spinlock held. But this patch replaces mmput() with mmput_async() in
    order not to start __mmput() from shrinker context.

    [1] https://syzkaller.appspot.com/bug?id=bc9e7303f537c41b2b0cc2dfcea3fc42964c2d45

    Reported-by: syzbot
    Reported-by: syzbot
    Signed-off-by: Tetsuo Handa
    Reviewed-by: Michal Hocko
    Acked-by: Todd Kjos
    Acked-by: Christian Brauner
    Cc: stable
    Link: https://lore.kernel.org/r/4ba9adb2-43f5-2de0-22de-f6075c1fab50@i-love.sakura.ne.jp
    Signed-off-by: Greg Kroah-Hartman

    Tetsuo Handa
     

01 Jul, 2020

1 commit

  • commit d35d3660e065b69fdb8bf512f3d899f350afce52 upstream.

    The binder driver makes the assumption proc->context pointer is invariant after
    initialization (as documented in the kerneldoc header for struct proc).
    However, in commit f0fe2c0f050d ("binder: prevent UAF for binderfs devices II")
    proc->context is set to NULL during binder_deferred_release().

    Another proc was in the middle of setting up a transaction to the dying
    process and crashed on a NULL pointer deref on "context" which is a local
    set to &proc->context:

    new_ref->data.desc = (node == context->binder_context_mgr_node) ? 0 : 1;

    Here's the stack:

    [ 5237.855435] Call trace:
    [ 5237.855441] binder_get_ref_for_node_olocked+0x100/0x2ec
    [ 5237.855446] binder_inc_ref_for_node+0x140/0x280
    [ 5237.855451] binder_translate_binder+0x1d0/0x388
    [ 5237.855456] binder_transaction+0x2228/0x3730
    [ 5237.855461] binder_thread_write+0x640/0x25bc
    [ 5237.855466] binder_ioctl_write_read+0xb0/0x464
    [ 5237.855471] binder_ioctl+0x30c/0x96c
    [ 5237.855477] do_vfs_ioctl+0x3e0/0x700
    [ 5237.855482] __arm64_sys_ioctl+0x78/0xa4
    [ 5237.855488] el0_svc_common+0xb4/0x194
    [ 5237.855493] el0_svc_handler+0x74/0x98
    [ 5237.855497] el0_svc+0x8/0xc

    The fix is to move the kfree of the binder_device to binder_free_proc()
    so the binder_device is freed when we know there are no references
    remaining on the binder_proc.

    Fixes: f0fe2c0f050d ("binder: prevent UAF for binderfs devices II")
    Acked-by: Christian Brauner
    Signed-off-by: Todd Kjos
    Cc: stable
    Link: https://lore.kernel.org/r/20200622200715.114382-1-tkjos@google.com
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     

25 Mar, 2020

1 commit

  • [ Upstream commit 211b64e4b5b6bd5fdc19cd525c2cc9a90e6b0ec9 ]

    Binderfs binder-control devices are cleaned up via binderfs_evict_inode
    too() which will use refcount_dec_and_test(). However, we missed to set
    the refcount for binderfs binder-control devices and so we underflowed
    when the binderfs instance got unmounted. Pretty obvious oversight and
    should have been part of the more general UAF fix. The good news is that
    having test cases (suprisingly) helps.

    Technically, we could detect that we're about to cleanup the
    binder-control dentry in binderfs_evict_inode() and then simply clean it
    up. But that makes the assumption that the binder driver itself will
    never make use of a binderfs binder-control device after the binderfs
    instance it belongs to has been unmounted and the superblock for it been
    destroyed. While it is unlikely to ever come to this let's be on the
    safe side. Performance-wise this also really doesn't matter since the
    binder-control device is only every really when creating the binderfs
    filesystem or creating additional binder devices. Both operations are
    pretty rare.

    Fixes: f0fe2c0f050d ("binder: prevent UAF for binderfs devices II")
    Link: https://lore.kernel.org/r/CA+G9fYusdfg7PMfC9Xce-xLT7NiyKSbgojpK35GOm=Pf9jXXrA@mail.gmail.com
    Reported-by: Naresh Kamboju
    Cc: stable@vger.kernel.org
    Signed-off-by: Christian Brauner
    Acked-by: Todd Kjos
    Link: https://lore.kernel.org/r/20200311105309.1742827-1-christian.brauner@ubuntu.com
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Sasha Levin

    Christian Brauner
     

12 Mar, 2020

2 commits

  • commit f0fe2c0f050d31babcad7d65f1d550d462a40064 upstream.

    This is a necessary follow up to the first fix I proposed and we merged
    in 2669b8b0c79 ("binder: prevent UAF for binderfs devices"). I have been
    overly optimistic that the simple fix I proposed would work. But alas,
    ihold() + iput() won't work since the inodes won't survive the
    destruction of the superblock.
    So all we get with my prior fix is a different race with a tinier
    race-window but it doesn't solve the issue. Fwiw, the problem lies with
    generic_shutdown_super(). It even has this cozy Al-style comment:

    if (!list_empty(&sb->s_inodes)) {
    printk("VFS: Busy inodes after unmount of %s. "
    "Self-destruct in 5 seconds. Have a nice day...\n",
    sb->s_id);
    }

    On binder_release(), binder_defer_work(proc, BINDER_DEFERRED_RELEASE) is
    called which punts the actual cleanup operation to a workqueue. At some
    point, binder_deferred_func() will be called which will end up calling
    binder_deferred_release() which will retrieve and cleanup the
    binder_context attach to this struct binder_proc.

    If we trace back where this binder_context is attached to binder_proc we
    see that it is set in binder_open() and is taken from the struct
    binder_device it is associated with. This obviously assumes that the
    struct binder_device that context is attached to is _never_ freed. While
    that might be true for devtmpfs binder devices it is most certainly
    wrong for binderfs binder devices.

    So, assume binder_open() is called on a binderfs binder devices. We now
    stash away the struct binder_context associated with that struct
    binder_devices:
    proc->context = &binder_dev->context;
    /* binderfs stashes devices in i_private */
    if (is_binderfs_device(nodp)) {
    binder_dev = nodp->i_private;
    info = nodp->i_sb->s_fs_info;
    binder_binderfs_dir_entry_proc = info->proc_log_dir;
    } else {
    .
    .
    .
    proc->context = &binder_dev->context;

    Now let's assume that the binderfs instance for that binder devices is
    shutdown via umount() and/or the mount namespace associated with it goes
    away. As long as there is still an fd open for that binderfs binder
    device things are fine. But let's assume we now close the last fd for
    that binderfs binder device. Now binder_release() is called and punts to
    the workqueue. Assume that the workqueue has quite a bit of stuff to do
    and doesn't get to cleaning up the struct binder_proc and the associated
    struct binder_context with it for that binderfs binder device right
    away. In the meantime, the VFS is killing the super block and is
    ultimately calling sb->evict_inode() which means it will call
    binderfs_evict_inode() which does:

    static void binderfs_evict_inode(struct inode *inode)
    {
    struct binder_device *device = inode->i_private;
    struct binderfs_info *info = BINDERFS_I(inode);

    clear_inode(inode);

    if (!S_ISCHR(inode->i_mode) || !device)
    return;

    mutex_lock(&binderfs_minors_mutex);
    --info->device_count;
    ida_free(&binderfs_minors, device->miscdev.minor);
    mutex_unlock(&binderfs_minors_mutex);

    kfree(device->context.name);
    kfree(device);
    }

    thereby freeing the struct binder_device including struct
    binder_context.

    Now the workqueue finally has time to get around to cleaning up struct
    binder_proc and is now trying to access the associate struct
    binder_context. Since it's already freed it will OOPs.

    Fix this by introducing a refounct on binder devices.

    This is an alternative fix to 51d8a7eca677 ("binder: prevent UAF read in
    print_binder_transaction_log_entry()").

    Fixes: 3ad20fe393b3 ("binder: implement binderfs")
    Fixes: 2669b8b0c798 ("binder: prevent UAF for binderfs devices")
    Fixes: 03e2e07e3814 ("binder: Make transaction_log available in binderfs")
    Related : 51d8a7eca677 ("binder: prevent UAF read in print_binder_transaction_log_entry()")
    Cc: stable@vger.kernel.org
    Signed-off-by: Christian Brauner
    Acked-by: Todd Kjos
    Link: https://lore.kernel.org/r/20200303164340.670054-1-christian.brauner@ubuntu.com
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Greg Kroah-Hartman

    Christian Brauner
     
  • commit 2669b8b0c798fbe1a31d49e07aa33233d469ad9b upstream.

    On binder_release(), binder_defer_work(proc, BINDER_DEFERRED_RELEASE) is
    called which punts the actual cleanup operation to a workqueue. At some
    point, binder_deferred_func() will be called which will end up calling
    binder_deferred_release() which will retrieve and cleanup the
    binder_context attach to this struct binder_proc.

    If we trace back where this binder_context is attached to binder_proc we
    see that it is set in binder_open() and is taken from the struct
    binder_device it is associated with. This obviously assumes that the
    struct binder_device that context is attached to is _never_ freed. While
    that might be true for devtmpfs binder devices it is most certainly
    wrong for binderfs binder devices.

    So, assume binder_open() is called on a binderfs binder devices. We now
    stash away the struct binder_context associated with that struct
    binder_devices:
    proc->context = &binder_dev->context;
    /* binderfs stashes devices in i_private */
    if (is_binderfs_device(nodp)) {
    binder_dev = nodp->i_private;
    info = nodp->i_sb->s_fs_info;
    binder_binderfs_dir_entry_proc = info->proc_log_dir;
    } else {
    .
    .
    .
    proc->context = &binder_dev->context;

    Now let's assume that the binderfs instance for that binder devices is
    shutdown via umount() and/or the mount namespace associated with it goes
    away. As long as there is still an fd open for that binderfs binder
    device things are fine. But let's assume we now close the last fd for
    that binderfs binder device. Now binder_release() is called and punts to
    the workqueue. Assume that the workqueue has quite a bit of stuff to do
    and doesn't get to cleaning up the struct binder_proc and the associated
    struct binder_context with it for that binderfs binder device right
    away. In the meantime, the VFS is killing the super block and is
    ultimately calling sb->evict_inode() which means it will call
    binderfs_evict_inode() which does:

    static void binderfs_evict_inode(struct inode *inode)
    {
    struct binder_device *device = inode->i_private;
    struct binderfs_info *info = BINDERFS_I(inode);

    clear_inode(inode);

    if (!S_ISCHR(inode->i_mode) || !device)
    return;

    mutex_lock(&binderfs_minors_mutex);
    --info->device_count;
    ida_free(&binderfs_minors, device->miscdev.minor);
    mutex_unlock(&binderfs_minors_mutex);

    kfree(device->context.name);
    kfree(device);
    }

    thereby freeing the struct binder_device including struct
    binder_context.

    Now the workqueue finally has time to get around to cleaning up struct
    binder_proc and is now trying to access the associate struct
    binder_context. Since it's already freed it will OOPs.

    Fix this by holding an additional reference to the inode that is only
    released once the workqueue is done cleaning up struct binder_proc. This
    is an easy alternative to introducing separate refcounting on struct
    binder_device which we can always do later if it becomes necessary.

    This is an alternative fix to 51d8a7eca677 ("binder: prevent UAF read in
    print_binder_transaction_log_entry()").

    Fixes: 3ad20fe393b3 ("binder: implement binderfs")
    Fixes: 03e2e07e3814 ("binder: Make transaction_log available in binderfs")
    Related : 51d8a7eca677 ("binder: prevent UAF read in print_binder_transaction_log_entry()")
    Cc: stable@vger.kernel.org
    Signed-off-by: Christian Brauner
    Acked-by: Todd Kjos
    Signed-off-by: Greg Kroah-Hartman
    Signed-off-by: Greg Kroah-Hartman

    Christian Brauner
     

01 Feb, 2020

1 commit

  • commit eb143f8756e77c8fcfc4d574922ae9efd3a43ca9 upstream.

    Since commit 43e23b6c0b01 ("debugfs: log errors when something goes wrong")
    debugfs logs attempts to create existing files.

    However binder attempts to create multiple debugfs files with
    the same name when a single PID has multiple contexts, this leads
    to log spamming during an Android boot (17 such messages during
    boot on my system).

    Fix this by checking if we already know the PID and only create
    the debugfs entry for the first context per PID.

    Do the same thing for binderfs for symmetry.

    Signed-off-by: Martin Fuzzey
    Acked-by: Todd Kjos
    Fixes: 43e23b6c0b01 ("debugfs: log errors when something goes wrong")
    Cc: stable
    Link: https://lore.kernel.org/r/1578671054-5982-1-git-send-email-martin.fuzzey@flowbird.group
    Signed-off-by: Greg Kroah-Hartman

    Martin Fuzzey
     

18 Dec, 2019

1 commit

  • commit 16981742717b04644a41052570fb502682a315d2 upstream.

    For BINDER_TYPE_PTR and BINDER_TYPE_FDA transactions, the
    num_valid local was calculated incorrectly causing the
    range check in binder_validate_ptr() to miss out-of-bounds
    offsets.

    Fixes: bde4a19fc04f ("binder: use userspace pointer as base of buffer space")
    Signed-off-by: Todd Kjos
    Cc: stable
    Link: https://lore.kernel.org/r/20191213202531.55010-1-tkjos@google.com
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     

13 Dec, 2019

3 commits

  • commit 2a9edd056ed4fbf9d2e797c3fc06335af35bccc4 upstream.

    The old loop wouldn't stop when reaching `start` if `start==NULL`, instead
    continuing backwards to index -1 and crashing.

    Luckily you need to be highly privileged to map things at NULL, so it's not
    a big problem.

    Fix it by adjusting the loop so that the loop variable is always in bounds.

    This patch is deliberately minimal to simplify backporting, but IMO this
    function could use a refactor. The jump labels in the second loop body are
    horrible (the error gotos should be jumping to free_range instead), and
    both loops would look nicer if they just iterated upwards through indices.
    And the up_read()+mmput() shouldn't be duplicated like that.

    Cc: stable@vger.kernel.org
    Fixes: 457b9a6f09f0 ("Staging: android: add binder driver")
    Signed-off-by: Jann Horn
    Acked-by: Christian Brauner
    Link: https://lore.kernel.org/r/20191018205631.248274-3-jannh@google.com
    Signed-off-by: Greg Kroah-Hartman

    Jann Horn
     
  • commit a7a74d7ff55a0c657bc46238b050460b9eacea95 upstream.

    binder_alloc_mmap_handler() attempts to detect the use of ->mmap() on a
    binder_proc whose binder_alloc has already been initialized by checking
    whether alloc->buffer is non-zero.

    Before commit 880211667b20 ("binder: remove kernel vm_area for buffer
    space"), alloc->buffer was a kernel mapping address, which is always
    non-zero, but since that commit, it is a userspace mapping address.

    A sufficiently privileged user can map /dev/binder at NULL, tricking
    binder_alloc_mmap_handler() into assuming that the binder_proc has not been
    mapped yet. This leads to memory unsafety.
    Luckily, no context on Android has such privileges, and on a typical Linux
    desktop system, you need to be root to do that.

    Fix it by using the mapping size instead of the mapping address to
    distinguish the mapped case. A valid VMA can't have size zero.

    Fixes: 880211667b20 ("binder: remove kernel vm_area for buffer space")
    Cc: stable@vger.kernel.org
    Signed-off-by: Jann Horn
    Acked-by: Christian Brauner
    Link: https://lore.kernel.org/r/20191018205631.248274-2-jannh@google.com
    Signed-off-by: Greg Kroah-Hartman

    Jann Horn
     
  • commit 8eb52a1ee37aafd9b796713aa0b3ab9cbc455be3 upstream.

    binder_alloc_print_pages() iterates over
    alloc->pages[0..alloc->buffer_size-1] under alloc->mutex.
    binder_alloc_mmap_handler() writes alloc->pages and alloc->buffer_size
    without holding that lock, and even writes them before the last bailout
    point.

    Unfortunately we can't take the alloc->mutex in the ->mmap() handler
    because mmap_sem can be taken while alloc->mutex is held.
    So instead, we have to locklessly check whether the binder_alloc has been
    fully initialized with binder_alloc_get_vma(), like in
    binder_alloc_new_buf_locked().

    Fixes: 8ef4665aa129 ("android: binder: Add page usage in binder stats")
    Cc: stable@vger.kernel.org
    Signed-off-by: Jann Horn
    Acked-by: Christian Brauner
    Link: https://lore.kernel.org/r/20191018205631.248274-1-jannh@google.com
    Signed-off-by: Greg Kroah-Hartman

    Jann Horn
     

17 Oct, 2019

1 commit

  • binder_mmap() tries to prevent the creation of overly big binder mappings
    by silently truncating the size of the VMA to 4MiB. However, this violates
    the API contract of mmap(). If userspace attempts to create a large binder
    VMA, and later attempts to unmap that VMA, it will call munmap() on a range
    beyond the end of the VMA, which may have been allocated to another VMA in
    the meantime. This can lead to userspace memory corruption.

    The following sequence of calls leads to a segfault without this commit:

    int main(void) {
    int binder_fd = open("/dev/binder", O_RDWR);
    if (binder_fd == -1) err(1, "open binder");
    void *binder_mapping = mmap(NULL, 0x800000UL, PROT_READ, MAP_SHARED,
    binder_fd, 0);
    if (binder_mapping == MAP_FAILED) err(1, "mmap binder");
    void *data_mapping = mmap(NULL, 0x400000UL, PROT_READ|PROT_WRITE,
    MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
    if (data_mapping == MAP_FAILED) err(1, "mmap data");
    munmap(binder_mapping, 0x800000UL);
    *(char*)data_mapping = 1;
    return 0;
    }

    Cc: stable@vger.kernel.org
    Signed-off-by: Jann Horn
    Acked-by: Todd Kjos
    Acked-by: Christian Brauner
    Link: https://lore.kernel.org/r/20191016150119.154756-1-jannh@google.com
    Signed-off-by: Greg Kroah-Hartman

    Jann Horn
     

10 Oct, 2019

2 commits

  • binder_alloc_buffer_lookup() doesn't exist and is named
    "binder_alloc_prepare_to_free()". Correct the code comments to reflect
    this.

    Signed-off-by: Joel Fernandes (Google)
    Reviewed-by: Christian Brauner
    Link: https://lore.kernel.org/r/20190930201250.139554-1-joel@joelfernandes.org
    Signed-off-by: Greg Kroah-Hartman

    Joel Fernandes (Google)
     
  • When a binder transaction is initiated on a binder device coming from a
    binderfs instance, a pointer to the name of the binder device is stashed
    in the binder_transaction_log_entry's context_name member. Later on it
    is used to print the name in print_binder_transaction_log_entry(). By
    the time print_binder_transaction_log_entry() accesses context_name
    binderfs_evict_inode() might have already freed the associated memory
    thereby causing a UAF. Do the simple thing and prevent this by copying
    the name of the binder device instead of stashing a pointer to it.

    Reported-by: Jann Horn
    Fixes: 03e2e07e3814 ("binder: Make transaction_log available in binderfs")
    Link: https://lore.kernel.org/r/CAG48ez14Q0-F8LqsvcNbyR2o6gPW8SHXsm4u5jmD9MpsteM2Tw@mail.gmail.com
    Signed-off-by: Christian Brauner
    Reviewed-by: Joel Fernandes (Google)
    Acked-by: Todd Kjos
    Reviewed-by: Hridya Valsaraju
    Link: https://lore.kernel.org/r/20191008130159.10161-1-christian.brauner@ubuntu.com
    Signed-off-by: Greg Kroah-Hartman

    Christian Brauner
     

04 Sep, 2019

6 commits

  • Currently /sys/kernel/debug/binder/proc contains
    the debug data for every binder_proc instance.
    This patch makes this information also available
    in a binderfs instance mounted with a mount option
    "stats=global" in addition to debugfs. The patch does
    not affect the presence of the file in debugfs.

    If a binderfs instance is mounted at path /dev/binderfs,
    this file would be present at /dev/binderfs/binder_logs/proc.
    This change provides an alternate way to access this file when debugfs
    is not mounted.

    Acked-by: Christian Brauner
    Signed-off-by: Hridya Valsaraju
    Link: https://lore.kernel.org/r/20190903161655.107408-5-hridya@google.com
    Signed-off-by: Greg Kroah-Hartman

    Hridya Valsaraju
     
  • Currently, the binder transaction log files 'transaction_log'
    and 'failed_transaction_log' live in debugfs at the following locations:

    /sys/kernel/debug/binder/failed_transaction_log
    /sys/kernel/debug/binder/transaction_log

    This patch makes these files also available in a binderfs instance
    mounted with the mount option "stats=global".
    It does not affect the presence of these files in debugfs.
    If a binderfs instance is mounted at path /dev/binderfs, the location of
    these files will be as follows:

    /dev/binderfs/binder_logs/failed_transaction_log
    /dev/binderfs/binder_logs/transaction_log

    This change provides an alternate option to access these files when
    debugfs is not mounted.

    Acked-by: Christian Brauner
    Signed-off-by: Hridya Valsaraju
    Link: https://lore.kernel.org/r/20190903161655.107408-4-hridya@google.com
    Signed-off-by: Greg Kroah-Hartman

    Hridya Valsaraju
     
  • The following binder stat files currently live in debugfs.

    /sys/kernel/debug/binder/state
    /sys/kernel/debug/binder/stats
    /sys/kernel/debug/binder/transactions

    This patch makes these files available in a binderfs instance
    mounted with the mount option 'stats=global'. For example, if a binderfs
    instance is mounted at path /dev/binderfs, the above files will be
    available at the following locations:

    /dev/binderfs/binder_logs/state
    /dev/binderfs/binder_logs/stats
    /dev/binderfs/binder_logs/transactions

    This provides a way to access them even when debugfs is not mounted.

    Acked-by: Christian Brauner
    Signed-off-by: Hridya Valsaraju
    Acked-by: Christian Brauner
    Link: https://lore.kernel.org/r/20190903161655.107408-3-hridya@google.com
    Signed-off-by: Greg Kroah-Hartman

    Hridya Valsaraju
     
  • Currently, all binder state and statistics live in debugfs.
    We need this information even when debugfs is not mounted.
    This patch adds the mount option 'stats' to enable a binderfs
    instance to have binder debug information present in the same.
    'stats=global' will enable the global binder statistics. In
    the future, 'stats=local' will enable binder statistics local
    to the binderfs instance. The two modes 'global' and 'local'
    will be mutually exclusive. 'stats=global' option is only available
    for a binderfs instance mounted in the initial user namespace.
    An attempt to use the option to mount a binderfs instance in
    another user namespace will return an EPERM error.

    Signed-off-by: Hridya Valsaraju
    Acked-by: Christian Brauner
    Link: https://lore.kernel.org/r/20190903161655.107408-2-hridya@google.com
    Signed-off-by: Greg Kroah-Hartman

    Hridya Valsaraju
     
  • Currently, since each binderfs instance needs its own
    private binder devices, every time a binderfs instance is
    mounted, all the default binder devices need to be created
    via the BINDER_CTL_ADD IOCTL. This patch aims to
    add a solution to automatically create the default binder
    devices for each binderfs instance that gets mounted.
    To achieve this goal, when CONFIG_ANDROID_BINDERFS is set,
    the default binder devices specified by CONFIG_ANDROID_BINDER_DEVICES
    are created in each binderfs instance instead of global devices
    being created by the binder driver.

    Co-developed-by: Christian Brauner
    Signed-off-by: Christian Brauner
    Signed-off-by: Hridya Valsaraju
    Reviewed-by: Joel Fernandes (Google)
    Link: https://lore.kernel.org/r/20190808222727.132744-2-hridya@google.com
    Link: https://lore.kernel.org/r/20190904110704.8606-2-christian.brauner@ubuntu.com
    Signed-off-by: Greg Kroah-Hartman

    Hridya Valsaraju
     
  • Length of a binderfs device name cannot exceed BINDERFS_MAX_NAME.
    This patch adds a check in binderfs_init() to ensure the same
    for the default binder devices that will be created in every
    binderfs instance.

    Co-developed-by: Christian Brauner
    Signed-off-by: Christian Brauner
    Signed-off-by: Hridya Valsaraju
    Reviewed-by: Joel Fernandes (Google)
    Link: https://lore.kernel.org/r/20190808222727.132744-3-hridya@google.com
    Link: https://lore.kernel.org/r/20190904110704.8606-3-christian.brauner@ubuntu.com
    Signed-off-by: Greg Kroah-Hartman

    Hridya Valsaraju
     

24 Jul, 2019

2 commits

  • Currently, a transaction to context manager from its own process
    is prevented by checking if its binder_proc struct is the same as
    that of the sender. However, this would not catch cases where the
    process opens the binder device again and uses the new fd to send
    a transaction to the context manager.

    Reported-by: syzbot+8b3c354d33c4ac78bfad@syzkaller.appspotmail.com
    Signed-off-by: Hridya Valsaraju
    Acked-by: Todd Kjos
    Cc: stable
    Link: https://lore.kernel.org/r/20190715191804.112933-1-hridya@google.com
    Signed-off-by: Greg Kroah-Hartman

    Hridya Valsaraju
     
  • In case the target node requests a security context, the
    extra_buffers_size is increased with the size of the security context.
    But, that size is not available for use by regular scatter-gather
    buffers; make sure the ending of that buffer is marked correctly.

    Acked-by: Todd Kjos
    Fixes: ec74136ded79 ("binder: create node flag to request sender's security context")
    Signed-off-by: Martijn Coenen
    Cc: stable@vger.kernel.org # 5.1+
    Link: https://lore.kernel.org/r/20190709110923.220736-1-maco@android.com
    Signed-off-by: Greg Kroah-Hartman

    Martijn Coenen
     

01 Jul, 2019

1 commit

  • The buffer copy functions assumed the caller would ensure
    correct alignment and that the memory to be copied was
    completely within the binder buffer. There have been
    a few cases discovered by syzkallar where a malformed
    transaction created by a user could violated the
    assumptions and resulted in a BUG_ON.

    The fix is to remove the BUG_ON and always return the
    error to be handled appropriately by the caller.

    Acked-by: Martijn Coenen
    Reported-by: syzbot+3ae18325f96190606754@syzkaller.appspotmail.com
    Fixes: bde4a19fc04f ("binder: use userspace pointer as base of buffer space")
    Suggested-by: Dan Carpenter
    Signed-off-by: Todd Kjos
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     

23 Jun, 2019

1 commit


22 Jun, 2019

1 commit

  • syzkallar found a 32-byte memory leak in a rarely executed error
    case. The transaction complete work item was not freed if put_user()
    failed when writing the BR_TRANSACTION_COMPLETE to the user command
    buffer. Fixed by freeing it before put_user() is called.

    Reported-by: syzbot+182ce46596c3f2e1eb24@syzkaller.appspotmail.com
    Signed-off-by: Todd Kjos
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     

13 Jun, 2019

1 commit

  • There is a race between the binder driver cleaning
    up a completed transaction via binder_free_transaction()
    and a user calling binder_ioctl(BC_FREE_BUFFER) to
    release a buffer. It doesn't matter which is first but
    they need to be protected against running concurrently
    which can result in a UAF.

    Signed-off-by: Todd Kjos
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     

05 Jun, 2019

1 commit

  • Based on 1 normalized pattern(s):

    this software is licensed under the terms of the gnu general public
    license version 2 as published by the free software foundation and
    may be copied distributed and modified under those terms this
    program is distributed in the hope that it will be useful but
    without any warranty without even the implied warranty of
    merchantability or fitness for a particular purpose see the gnu
    general public license for more details

    extracted by the scancode license scanner the SPDX license identifier

    GPL-2.0-only

    has been chosen to replace the boilerplate/reference in 285 file(s).

    Signed-off-by: Thomas Gleixner
    Reviewed-by: Alexios Zavras
    Reviewed-by: Allison Randal
    Cc: linux-spdx@vger.kernel.org
    Link: https://lkml.kernel.org/r/20190529141900.642774971@linutronix.de
    Signed-off-by: Greg Kroah-Hartman

    Thomas Gleixner
     

21 May, 2019

1 commit


08 May, 2019

1 commit

  • …/git/gregkh/char-misc

    Pull char/misc update part 2 from Greg KH:
    "Here is the "real" big set of char/misc driver patches for 5.2-rc1

    Loads of different driver subsystem stuff in here, all over the places:
    - thunderbolt driver updates
    - habanalabs driver updates
    - nvmem driver updates
    - extcon driver updates
    - intel_th driver updates
    - mei driver updates
    - coresight driver updates
    - soundwire driver cleanups and updates
    - fastrpc driver updates
    - other minor driver updates
    - chardev minor fixups

    Feels like this tree is getting to be a dumping ground of "small
    driver subsystems" these days. Which is fine with me, if it makes
    things easier for those subsystem maintainers.

    All of these have been in linux-next for a while with no reported
    issues"

    * tag 'char-misc-5.2-rc1-part2' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc: (255 commits)
    intel_th: msu: Add current window tracking
    intel_th: msu: Add a sysfs attribute to trigger window switch
    intel_th: msu: Correct the block wrap detection
    intel_th: Add switch triggering support
    intel_th: gth: Factor out trace start/stop
    intel_th: msu: Factor out pipeline draining
    intel_th: msu: Switch over to scatterlist
    intel_th: msu: Replace open-coded list_{first,last,next}_entry variants
    intel_th: Only report useful IRQs to subdevices
    intel_th: msu: Start handling IRQs
    intel_th: pci: Use MSI interrupt signalling
    intel_th: Communicate IRQ via resource
    intel_th: Add "rtit" source device
    intel_th: Skip subdevices if their MMIO is missing
    intel_th: Rework resource passing between glue layers and core
    intel_th: SPDX-ify the documentation
    intel_th: msu: Fix single mode with IOMMU
    coresight: funnel: Support static funnel
    dt-bindings: arm: coresight: Unify funnel DT binding
    coresight: replicator: Add new device id for static replicator
    ...

    Linus Torvalds
     

26 Apr, 2019

1 commit

  • When allocating space in the target buffer for the security context,
    make sure the extra_buffers_size doesn't overflow. This can only
    happen if the given size is invalid, but an overflow can turn it
    into a valid size. Fail the transaction if an overflow is detected.

    Signed-off-by: Todd Kjos
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     

25 Apr, 2019

1 commit

  • Restore the behavior of locking mmap_sem for reading in
    binder_alloc_free_page(), as was first done in commit 3013bf62b67a
    ("binder: reduce mmap_sem write-side lock"). That change was
    inadvertently reverted by commit 5cec2d2e5839 ("binder: fix race between
    munmap() and direct reclaim").

    In addition, change the name of the label for the error path to
    accurately reflect that we're taking the lock for reading.

    Backporting note: This fix is only needed when *both* of the commits
    mentioned above are applied. That's an unlikely situation since they
    both landed during the development of v5.1 but only one of them is
    targeted for stable.

    Fixes: 5cec2d2e5839 ("binder: fix race between munmap() and direct reclaim")
    Signed-off-by: Tyler Hicks
    Acked-by: Todd Kjos
    Signed-off-by: Greg Kroah-Hartman

    Tyler Hicks
     

21 Mar, 2019

2 commits

  • An munmap() on a binder device causes binder_vma_close() to be called
    which clears the alloc->vma pointer.

    If direct reclaim causes binder_alloc_free_page() to be called, there
    is a race where alloc->vma is read into a local vma pointer and then
    used later after the mm->mmap_sem is acquired. This can result in
    calling zap_page_range() with an invalid vma which manifests as a
    use-after-free in zap_page_range().

    The fix is to check alloc->vma after acquiring the mmap_sem (which we
    were acquiring anyway) and skip zap_page_range() if it has changed
    to NULL.

    Signed-off-by: Todd Kjos
    Reviewed-by: Joel Fernandes (Google)
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     
  • The selinux-testsuite found an issue resulting in a BUG_ON()
    where a conditional relied on a size_t going negative when
    checking the validity of a buffer offset.

    Fixes: 7a67a39320df ("binder: add function to copy binder object from buffer")
    Reported-by: Paul Moore
    Tested-by: Paul Moore
    Signed-off-by: Todd Kjos
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     

19 Feb, 2019

1 commit

  • binder has used write-side mmap_sem semaphore to release memory
    mapped at address space of the process. However, right lock to
    release pages is down_read, not down_write because page table lock
    already protects the race for parallel freeing.

    Please do not use mmap_sem write-side lock which is well known
    contented lock.

    Cc: Todd Kjos
    Cc: Martijn Coenen
    Cc: Arve Hjønnevåg
    Signed-off-by: Minchan Kim
    Signed-off-by: Greg Kroah-Hartman

    Minchan Kim
     

15 Feb, 2019

1 commit


14 Feb, 2019

1 commit

  • Fixes sparse issues reported by the kbuild test robot running
    on https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/char-misc.git
    char-misc-testing: bde4a19fc04f5 ("binder: use userspace pointer as base
    of buffer space")

    Error output (drivers/android/binder_alloc_selftest.c):
    sparse: warning: incorrect type in assignment (different address spaces)
    sparse: expected void *page_addr
    sparse: got void [noderef] *user_data
    sparse: error: subtraction of different types can't work

    Fixed by adding necessary "__user" tags.

    Reported-by: kbuild test robot
    Signed-off-by: Todd Kjos
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     

12 Feb, 2019

5 commits

  • Now that alloc->buffer points to the userspace vm_area
    rename buffer->data to buffer->user_data and rename
    local pointers that hold user addresses. Also use the
    "__user" tag to annotate all user pointers so sparse
    can flag cases where user pointer vaues are copied to
    kernel pointers. Refactor code to use offsets instead
    of user pointers.

    Signed-off-by: Todd Kjos
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     
  • Remove user_buffer_offset since there is no kernel
    buffer pointer anymore.

    Signed-off-by: Todd Kjos
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     
  • Remove the kernel's vm_area and the code that maps
    buffer pages into it.

    Signed-off-by: Todd Kjos
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     
  • Refactor the functions to validate and fixup struct
    binder_buffer pointer objects to avoid using vm_area
    pointers. Instead copy to/from kernel space using
    binder_alloc_copy_to_buffer() and
    binder_alloc_copy_from_buffer(). The following
    functions were refactored:

    refactor binder_validate_ptr()
    binder_validate_fixup()
    binder_fixup_parent()

    Signed-off-by: Todd Kjos
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos
     
  • When creating or tearing down a transaction, the binder driver
    examines objects in the buffer and takes appropriate action.
    To do this without needing to dereference pointers into the
    buffer, the local copies of the objects are needed. This patch
    introduces a function to validate and copy binder objects
    from the buffer to a local structure.

    Signed-off-by: Todd Kjos
    Signed-off-by: Greg Kroah-Hartman

    Todd Kjos