1. 01 2月, 2019 1 次提交
  2. 30 1月, 2019 1 次提交
    • C
      binder: fix CONFIG_ANDROID_BINDER_DEVICES · 793c8232
      Christian Brauner 提交于
      Several users have tried to only rely on binderfs to provide binder devices
      and set CONFIG_ANDROID_BINDER_DEVICES="" empty. This is a great use-case of
      binderfs and one that was always intended to work. However, this is
      currently not possible since setting CONFIG_ANDROID_BINDER_DEVICES="" emtpy
      will simply panic the kernel:
      
      kobject: (00000000028c2f79): attempted to be registered with empty name!
      WARNING: CPU: 7 PID: 1703 at lib/kobject.c:228 kobject_add_internal+0x288/0x2b0
      Modules linked in: binder_linux(+) bridge stp llc ipmi_ssif gpio_ich dcdbas coretemp kvm_intel kvm irqbypass serio_raw input_leds lpc_ich i5100_edac mac_hid ipmi_si ipmi_devintf ipmi_msghandler sch_fq_codel ib_i
      CPU: 7 PID: 1703 Comm: modprobe Not tainted 5.0.0-rc2-brauner-binderfs #263
      Hardware name: Dell      DCS XS24-SC2          /XS24-SC2              , BIOS S59_3C20 04/07/2011
      RIP: 0010:kobject_add_internal+0x288/0x2b0
      Code: 12 95 48 c7 c7 78 63 3b 95 e8 77 35 71 ff e9 91 fe ff ff 0f 0b eb a7 0f 0b eb 9a 48 89 de 48 c7 c7 00 63 3b 95 e8 f8 95 6a ff <0f> 0b 41 bc ea ff ff ff e9 6d fe ff ff 41 bc fe ff ff ff e9 62 fe
      RSP: 0018:ffff973f84237a30 EFLAGS: 00010282
      RAX: 0000000000000000 RBX: ffff8b53e2472010 RCX: 0000000000000006
      RDX: 0000000000000007 RSI: 0000000000000086 RDI: ffff8b53edbd63a0
      RBP: ffff973f84237a60 R08: 0000000000000342 R09: 0000000000000004
      R10: ffff973f84237af0 R11: 0000000000000001 R12: 0000000000000000
      R13: ffff8b53e9f1a1e0 R14: 00000000e9f1a1e0 R15: 0000000000a00037
      FS:  00007fbac36f7540(0000) GS:ffff8b53edbc0000(0000) knlGS:0000000000000000
      CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
      CR2: 00007fbac364cfa7 CR3: 00000004a6d48000 CR4: 00000000000406e0
      Call Trace:
       kobject_add+0x71/0xd0
       ? _cond_resched+0x19/0x40
       ? mutex_lock+0x12/0x40
       device_add+0x12e/0x6b0
       device_create_groups_vargs+0xe4/0xf0
       device_create_with_groups+0x3f/0x60
       ? _cond_resched+0x19/0x40
       misc_register+0x140/0x180
       binder_init+0x1ed/0x2d4 [binder_linux]
       ? trace_event_define_fields_binder_transaction_fd_send+0x8e/0x8e [binder_linux]
       do_one_initcall+0x4a/0x1c9
       ? _cond_resched+0x19/0x40
       ? kmem_cache_alloc_trace+0x151/0x1c0
       do_init_module+0x5f/0x216
       load_module+0x223d/0x2b20
       __do_sys_finit_module+0xfc/0x120
       ? __do_sys_finit_module+0xfc/0x120
       __x64_sys_finit_module+0x1a/0x20
       do_syscall_64+0x5a/0x120
       entry_SYSCALL_64_after_hwframe+0x44/0xa9
      RIP: 0033:0x7fbac3202839
      Code: 00 f3 c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 1f f6 2c 00 f7 d8 64 89 01 48
      RSP: 002b:00007ffd1494a908 EFLAGS: 00000246 ORIG_RAX: 0000000000000139
      RAX: ffffffffffffffda RBX: 000055b629ebec60 RCX: 00007fbac3202839
      RDX: 0000000000000000 RSI: 000055b629c20d2e RDI: 0000000000000003
      RBP: 000055b629c20d2e R08: 0000000000000000 R09: 000055b629ec2310
      R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000
      R13: 000055b629ebed70 R14: 0000000000040000 R15: 000055b629ebec60
      
      So check for the empty string since strsep() will otherwise return the
      emtpy string which will cause kobject_add_internal() to panic when trying
      to add a kobject with an emtpy name.
      
      Fixes: ac4812c5 ("binder: Support multiple /dev instances")
      Cc: Martijn Coenen <maco@google.com>
      Signed-off-by: NChristian Brauner <christian.brauner@ubuntu.com>
      Acked-by: NTodd Kjos <tkjos@google.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      793c8232
  3. 19 12月, 2018 2 次提交
    • C
      binder: implement binderfs · 3ad20fe3
      Christian Brauner 提交于
      As discussed at Linux Plumbers Conference 2018 in Vancouver [1] this is the
      implementation of binderfs.
      
      /* Abstract */
      binderfs is a backwards-compatible filesystem for Android's binder ipc
      mechanism. Each ipc namespace will mount a new binderfs instance. Mounting
      binderfs multiple times at different locations in the same ipc namespace
      will not cause a new super block to be allocated and hence it will be the
      same filesystem instance.
      Each new binderfs mount will have its own set of binder devices only
      visible in the ipc namespace it has been mounted in. All devices in a new
      binderfs mount will follow the scheme binder%d and numbering will always
      start at 0.
      
      /* Backwards compatibility */
      Devices requested in the Kconfig via CONFIG_ANDROID_BINDER_DEVICES for the
      initial ipc namespace will work as before. They will be registered via
      misc_register() and appear in the devtmpfs mount. Specifically, the
      standard devices binder, hwbinder, and vndbinder will all appear in their
      standard locations in /dev. Mounting or unmounting the binderfs mount in
      the initial ipc namespace will have no effect on these devices, i.e. they
      will neither show up in the binderfs mount nor will they disappear when the
      binderfs mount is gone.
      
      /* binder-control */
      Each new binderfs instance comes with a binder-control device. No other
      devices will be present at first. The binder-control device can be used to
      dynamically allocate binder devices. All requests operate on the binderfs
      mount the binder-control device resides in.
      Assuming a new instance of binderfs has been mounted at /dev/binderfs
      via mount -t binderfs binderfs /dev/binderfs. Then a request to create a
      new binder device can be made as illustrated in [2].
      Binderfs devices can simply be removed via unlink().
      
      /* Implementation details */
      - dynamic major number allocation:
        When binderfs is registered as a new filesystem it will dynamically
        allocate a new major number. The allocated major number will be returned
        in struct binderfs_device when a new binder device is allocated.
      - global minor number tracking:
        Minor are tracked in a global idr struct that is capped at
        BINDERFS_MAX_MINOR. The minor number tracker is protected by a global
        mutex. This is the only point of contention between binderfs mounts.
      - struct binderfs_info:
        Each binderfs super block has its own struct binderfs_info that tracks
        specific details about a binderfs instance:
        - ipc namespace
        - dentry of the binder-control device
        - root uid and root gid of the user namespace the binderfs instance
          was mounted in
      - mountable by user namespace root:
        binderfs can be mounted by user namespace root in a non-initial user
        namespace. The devices will be owned by user namespace root.
      - binderfs binder devices without misc infrastructure:
        New binder devices associated with a binderfs mount do not use the
        full misc_register() infrastructure.
        The misc_register() infrastructure can only create new devices in the
        host's devtmpfs mount. binderfs does however only make devices appear
        under its own mountpoint and thus allocates new character device nodes
        from the inode of the root dentry of the super block. This will have
        the side-effect that binderfs specific device nodes do not appear in
        sysfs. This behavior is similar to devpts allocated pts devices and
        has no effect on the functionality of the ipc mechanism itself.
      
      [1]: https://goo.gl/JL2tfX
      [2]: program to allocate a new binderfs binder device:
      
           #define _GNU_SOURCE
           #include <errno.h>
           #include <fcntl.h>
           #include <stdio.h>
           #include <stdlib.h>
           #include <string.h>
           #include <sys/ioctl.h>
           #include <sys/stat.h>
           #include <sys/types.h>
           #include <unistd.h>
           #include <linux/android/binder_ctl.h>
      
           int main(int argc, char *argv[])
           {
                   int fd, ret, saved_errno;
                   size_t len;
                   struct binderfs_device device = { 0 };
      
                   if (argc < 2)
                           exit(EXIT_FAILURE);
      
                   len = strlen(argv[1]);
                   if (len > BINDERFS_MAX_NAME)
                           exit(EXIT_FAILURE);
      
                   memcpy(device.name, argv[1], len);
      
                   fd = open("/dev/binderfs/binder-control", O_RDONLY | O_CLOEXEC);
                   if (fd < 0) {
                           printf("%s - Failed to open binder-control device\n",
                                  strerror(errno));
                           exit(EXIT_FAILURE);
                   }
      
                   ret = ioctl(fd, BINDER_CTL_ADD, &device);
                   saved_errno = errno;
                   close(fd);
                   errno = saved_errno;
                   if (ret < 0) {
                           printf("%s - Failed to allocate new binder device\n",
                                  strerror(errno));
                           exit(EXIT_FAILURE);
                   }
      
                   printf("Allocated new binder device with major %d, minor %d, and "
                          "name %s\n", device.major, device.minor,
                          device.name);
      
                   exit(EXIT_SUCCESS);
           }
      
      Cc: Martijn Coenen <maco@android.com>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChristian Brauner <christian.brauner@ubuntu.com>
      Acked-by: NTodd Kjos <tkjos@google.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3ad20fe3
    • T
      binder: fix use-after-free due to ksys_close() during fdget() · 80cd7956
      Todd Kjos 提交于
      44d8047f ("binder: use standard functions to allocate fds")
      exposed a pre-existing issue in the binder driver.
      
      fdget() is used in ksys_ioctl() as a performance optimization.
      One of the rules associated with fdget() is that ksys_close() must
      not be called between the fdget() and the fdput(). There is a case
      where this requirement is not met in the binder driver which results
      in the reference count dropping to 0 when the device is still in
      use. This can result in use-after-free or other issues.
      
      If userpace has passed a file-descriptor for the binder driver using
      a BINDER_TYPE_FDA object, then kys_close() is called on it when
      handling a binder_ioctl(BC_FREE_BUFFER) command. This violates
      the assumptions for using fdget().
      
      The problem is fixed by deferring the close using task_work_add(). A
      new variant of __close_fd() was created that returns a struct file
      with a reference. The fput() is deferred instead of using ksys_close().
      
      Fixes: 44d8047f ("binder: use standard functions to allocate fds")
      Suggested-by: NAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NTodd Kjos <tkjos@google.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      80cd7956
  4. 06 12月, 2018 2 次提交
  5. 27 11月, 2018 2 次提交
    • T
      binder: fix sparse warnings on locking context · 324fa64c
      Todd Kjos 提交于
      Add __acquire()/__release() annnotations to fix warnings
      in sparse context checking
      
      There is one case where the warning was due to a lack of
      a "default:" case in a switch statement where a lock was
      being released in each of the cases, so the default
      case was added.
      Signed-off-by: NTodd Kjos <tkjos@google.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      324fa64c
    • T
      binder: fix race that allows malicious free of live buffer · 7bada55a
      Todd Kjos 提交于
      Malicious code can attempt to free buffers using the BC_FREE_BUFFER
      ioctl to binder. There are protections against a user freeing a buffer
      while in use by the kernel, however there was a window where
      BC_FREE_BUFFER could be used to free a recently allocated buffer that
      was not completely initialized. This resulted in a use-after-free
      detected by KASAN with a malicious test program.
      
      This window is closed by setting the buffer's allow_user_free attribute
      to 0 when the buffer is allocated or when the user has previously freed
      it instead of waiting for the caller to set it. The problem was that
      when the struct buffer was recycled, allow_user_free was stale and set
      to 1 allowing a free to go through.
      Signed-off-by: NTodd Kjos <tkjos@google.com>
      Acked-by: NArve Hjønnevåg <arve@android.com>
      Cc: stable <stable@vger.kernel.org> # 4.14
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7bada55a
  6. 03 10月, 2018 1 次提交
  7. 14 9月, 2018 4 次提交
    • M
      binder: Add BINDER_GET_NODE_INFO_FOR_REF ioctl. · b7e6a896
      Martijn Coenen 提交于
      This allows the context manager to retrieve information about nodes
      that it holds a reference to, such as the current number of
      references to those nodes.
      
      Such information can for example be used to determine whether the
      servicemanager is the only process holding a reference to a node.
      This information can then be passed on to the process holding the
      node, which can in turn decide whether it wants to shut down to
      reduce resource usage.
      Signed-off-by: NMartijn Coenen <maco@android.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b7e6a896
    • R
    • T
      binder: use standard functions to allocate fds · 44d8047f
      Todd Kjos 提交于
      Binder uses internal fs interfaces to allocate and install fds:
      
      __alloc_fd
      __fd_install
      __close_fd
      get_files_struct
      put_files_struct
      
      These were used to support the passing of fds between processes
      as part of a transaction. The actual allocation and installation
      of the fds in the target process was handled by the sending
      process so the standard functions, alloc_fd() and fd_install()
      which assume task==current couldn't be used.
      
      This patch refactors this mechanism so that the fds are
      allocated and installed by the target process allowing the
      standard functions to be used.
      
      The sender now creates a list of fd fixups that contains the
      struct *file and the address to fixup with the new fd once
      it is allocated. This list is processed by the target process
      when the transaction is dequeued.
      
      A new error case is introduced by this change. If an async
      transaction with file descriptors cannot allocate new
      fds in the target (probably due to out of file descriptors),
      the transaction is discarded with a log message. In the old
      implementation this would have been detected in the sender
      context and failed prior to sending.
      Signed-off-by: NTodd Kjos <tkjos@google.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      44d8047f
    • S
      android: binder: no outgoing transaction when thread todo has transaction · 44b73962
      Sherry Yang 提交于
      When a process dies, failed reply is sent to the sender of any transaction
      queued on a dead thread's todo list. The sender asserts that the
      received failed reply corresponds to the head of the transaction stack.
      This assert can fail if the dead thread is allowed to send outgoing
      transactions when there is already a transaction on its todo list,
      because this new transaction can end up on the transaction stack of the
      original sender. The following steps illustrate how this assertion can
      fail.
      
      1. Thread1 sends txn19 to Thread2
         (T1->transaction_stack=txn19, T2->todo+=txn19)
      2. Without processing todo list, Thread2 sends txn20 to Thread1
         (T1->todo+=txn20, T2->transaction_stack=txn20)
      3. T1 processes txn20 on its todo list
         (T1->transaction_stack=txn20->txn19, T1->todo=<empty>)
      4. T2 dies, T2->todo cleanup attempts to send failed reply for txn19, but
         T1->transaction_stack points to txn20 -- assertion failes
      
      Step 2. is the incorrect behavior. When there is a transaction on a
      thread's todo list, this thread should not be able to send any outgoing
      synchronous transactions. Only the head of the todo list needs to be
      checked because only threads that are waiting for proc work can directly
      receive work from another thread, and no work is allowed to be queued
      on such a thread without waking up the thread. This patch also enforces
      that a thread is not waiting for proc work when a work is directly
      enqueued to its todo list.
      Acked-by: NArve Hjønnevåg <arve@android.com>
      Signed-off-by: NSherry Yang <sherryy@android.com>
      Reviewed-by: NMartijn Coenen <maco@android.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      44b73962
  8. 08 8月, 2018 1 次提交
  9. 24 7月, 2018 1 次提交
  10. 14 5月, 2018 4 次提交
    • S
      android: binder: Change return type to vm_fault_t · e19f70aa
      Souptick Joarder 提交于
      Use new return type vm_fault_t for fault handler in
      struct vm_operations_struct. For now, this is just
      documenting that the function returns a VM_FAULT
      value rather than an errno.  Once all instances are
      converted, vm_fault_t will become a distinct type.
      
      Reference id -> 1c8f4220 ("mm: change return type
      to vm_fault_t")
      Signed-off-by: NSouptick Joarder <jrdr.linux@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e19f70aa
    • M
      ANDROID: binder: change down_write to down_read · 720c2419
      Minchan Kim 提交于
      binder_update_page_range needs down_write of mmap_sem because
      vm_insert_page need to change vma->vm_flags to VM_MIXEDMAP unless
      it is set. However, when I profile binder working, it seems
      every binder buffers should be mapped in advance by binder_mmap.
      It means we could set VM_MIXEDMAP in binder_mmap time which is
      already hold a mmap_sem as down_write so binder_update_page_range
      doesn't need to hold a mmap_sem as down_write.
      Please use proper API down_read. It would help mmap_sem contention
      problem as well as fixing down_write abuse.
      
      Ganesh Mahendran tested app launching and binder throughput test
      and he said he couldn't find any problem and I did binder latency
      test per Greg KH request(Thanks Martijn to teach me how I can do)
      I cannot find any problem, too.
      
      Cc: Ganesh Mahendran <opensource.ganesh@gmail.com>
      Cc: Joe Perches <joe@perches.com>
      Cc: Arve Hjønnevåg <arve@android.com>
      Cc: Todd Kjos <tkjos@google.com>
      Reviewed-by: NMartijn Coenen <maco@android.com>
      Signed-off-by: NMinchan Kim <minchan@kernel.org>
      Reviewed-by: NJoel Fernandes (Google) <joel@joelfernandes.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      720c2419
    • ANDROID: binder: correct the cmd print for BINDER_WORK_RETURN_ERROR · 838d5565
      宋金时 提交于
      When to execute binder_stat_br the e->cmd has been modifying as BR_OK
      instead of the original return error cmd, in fact we want to know the
      original return error, such as BR_DEAD_REPLY or BR_FAILED_REPLY, etc.
      instead of always BR_OK, in order to avoid the value of the e->cmd is
      always BR_OK, so we need assign the value of the e->cmd to cmd before
      e->cmd = BR_OK.
      Signed-off-by: Nsongjinshi <songjinshi@xiaomi.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      838d5565
    • M
      ANDROID: binder: remove 32-bit binder interface. · 1190b4e3
      Martijn Coenen 提交于
      New devices launching with Android P need to use the 64-bit
      binder interface, even on 32-bit SoCs [0].
      
      This change removes the Kconfig option to select the 32-bit
      binder interface. We don't think this will affect existing
      userspace for the following reasons:
      1) The latest Android common tree is 4.14, so we don't
         believe any Android devices are on kernels >4.14.
      2) Android devices launch on an LTS release and stick with
         it, so we wouldn't expect devices running on <= 4.14 now
         to upgrade to 4.17 or later. But even if they did, they'd
         rebuild the world (kernel + userspace) anyway.
      3) Other userspaces like 'anbox' are already using the
         64-bit interface.
      
      Note that this change doesn't remove the 32-bit UAPI
      itself; the reason for that is that Android userspace
      always uses the latest UAPI headers from upstream, and
      userspace retains 32-bit support for devices that are
      upgrading. This will be removed as well in 2-3 years,
      at which point we can remove the code from the UAPI
      as well.
      
      Finally, this change introduces build errors on archs where
      64-bit get_user/put_user is not supported, so make binder
      unavailable on m68k (which wouldn't want it anyway).
      
      [0]: https://android-review.googlesource.com/c/platform/build/+/595193Signed-off-by: NMartijn Coenen <maco@android.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1190b4e3
  11. 23 4月, 2018 2 次提交
  12. 16 2月, 2018 4 次提交
    • M
      ANDROID: binder: synchronize_rcu() when using POLLFREE. · 5eeb2ca0
      Martijn Coenen 提交于
      To prevent races with ep_remove_waitqueue() removing the
      waitqueue at the same time.
      
      Reported-by: syzbot+a2a3c4909716e271487e@syzkaller.appspotmail.com
      Signed-off-by: NMartijn Coenen <maco@android.com>
      Cc: stable <stable@vger.kernel.org> # 4.14+
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      5eeb2ca0
    • T
      binder: replace "%p" with "%pK" · 8ca86f16
      Todd Kjos 提交于
      The format specifier "%p" can leak kernel addresses. Use
      "%pK" instead. There were 4 remaining cases in binder.c.
      Signed-off-by: NTodd Kjos <tkjos@google.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8ca86f16
    • T
      ANDROID: binder: remove WARN() for redundant txn error · e46a3b3b
      Todd Kjos 提交于
      binder_send_failed_reply() is called when a synchronous
      transaction fails. It reports an error to the thread that
      is waiting for the completion. Given that the transaction
      is synchronous, there should never be more than 1 error
      response to that thread -- this was being asserted with
      a WARN().
      
      However, when exercising the driver with syzbot tests, cases
      were observed where multiple "synchronous" requests were
      sent without waiting for responses, so it is possible that
      multiple errors would be reported to the thread. This testing
      was conducted with panic_on_warn set which forced the crash.
      
      This is easily reproduced by sending back-to-back
      "synchronous" transactions without checking for any
      response (eg, set read_size to 0):
      
          bwr.write_buffer = (uintptr_t)&bc1;
          bwr.write_size = sizeof(bc1);
          bwr.read_buffer = (uintptr_t)&br;
          bwr.read_size = 0;
          ioctl(fd, BINDER_WRITE_READ, &bwr);
          sleep(1);
          bwr2.write_buffer = (uintptr_t)&bc2;
          bwr2.write_size = sizeof(bc2);
          bwr2.read_buffer = (uintptr_t)&br;
          bwr2.read_size = 0;
          ioctl(fd, BINDER_WRITE_READ, &bwr2);
          sleep(1);
      
      The first transaction is sent to the servicemanager and the reply
      fails because no VMA is set up by this client. After
      binder_send_failed_reply() is called, the BINDER_WORK_RETURN_ERROR
      is sitting on the thread's todo list since the read_size was 0 and
      the client is not waiting for a response.
      
      The 2nd transaction is sent and the BINDER_WORK_RETURN_ERROR has not
      been consumed, so the thread's reply_error.cmd is still set (normally
      cleared when the BINDER_WORK_RETURN_ERROR is handled). Therefore
      when the servicemanager attempts to reply to the 2nd failed
      transaction, the error is already set and it triggers this warning.
      
      This is a user error since it is not waiting for the synchronous
      transaction to complete. If it ever does check, it will see an
      error.
      
      Changed the WARN() to a pr_warn().
      Signed-off-by: NTodd Kjos <tkjos@android.com>
      Reported-by: Nsyzbot <syzkaller@googlegroups.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e46a3b3b
    • E
      binder: check for binder_thread allocation failure in binder_poll() · f8898267
      Eric Biggers 提交于
      If the kzalloc() in binder_get_thread() fails, binder_poll()
      dereferences the resulting NULL pointer.
      
      Fix it by returning POLLERR if the memory allocation failed.
      
      This bug was found by syzkaller using fault injection.
      Reported-by: Nsyzbot <syzkaller@googlegroups.com>
      Fixes: 457b9a6f ("Staging: android: add binder driver")
      Cc: stable@vger.kernel.org
      Signed-off-by: NEric Biggers <ebiggers@google.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f8898267
  13. 12 2月, 2018 1 次提交
    • L
      vfs: do bulk POLL* -> EPOLL* replacement · a9a08845
      Linus Torvalds 提交于
      This is the mindless scripted replacement of kernel use of POLL*
      variables as described by Al, done by this script:
      
          for V in IN OUT PRI ERR RDNORM RDBAND WRNORM WRBAND HUP RDHUP NVAL MSG; do
              L=`git grep -l -w POLL$V | grep -v '^t' | grep -v /um/ | grep -v '^sa' | grep -v '/poll.h$'|grep -v '^D'`
              for f in $L; do sed -i "-es/^\([^\"]*\)\(\<POLL$V\>\)/\\1E\\2/" $f; done
          done
      
      with de-mangling cleanups yet to come.
      
      NOTE! On almost all architectures, the EPOLL* constants have the same
      values as the POLL* constants do.  But they keyword here is "almost".
      For various bad reasons they aren't the same, and epoll() doesn't
      actually work quite correctly in some cases due to this on Sparc et al.
      
      The next patch from Al will sort out the final differences, and we
      should be all done.
      Scripted-by: NAl Viro <viro@zeniv.linux.org.uk>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      a9a08845
  14. 25 1月, 2018 1 次提交
  15. 10 1月, 2018 4 次提交
  16. 18 12月, 2017 2 次提交
  17. 29 11月, 2017 1 次提交
  18. 28 11月, 2017 2 次提交
    • M
      ANDROID: binder: fix transaction leak. · fb2c4452
      Martijn Coenen 提交于
      If a call to put_user() fails, we failed to
      properly free a transaction and send a failed
      reply (if necessary).
      Signed-off-by: NMartijn Coenen <maco@android.com>
      Cc: stable <stable@vger.kernel.org> # 4.14
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fb2c4452
    • M
      ANDROID: binder: Add thread->process_todo flag. · 148ade2c
      Martijn Coenen 提交于
      This flag determines whether the thread should currently
      process the work in the thread->todo worklist.
      
      The prime usecase for this is improving the performance
      of synchronous transactions: all synchronous transactions
      post a BR_TRANSACTION_COMPLETE to the calling thread,
      but there's no reason to return that command to userspace
      right away - userspace anyway needs to wait for the reply.
      
      Likewise, a synchronous transaction that contains a binder
      object can cause a BC_ACQUIRE/BC_INCREFS to be returned to
      userspace; since the caller must anyway hold a strong/weak
      ref for the duration of the call, postponing these commands
      until the reply comes in is not a problem.
      
      Note that this flag is not used to determine whether a
      thread can handle process work; a thread should never pick
      up process work when thread work is still pending.
      
      Before patch:
      ------------------------------------------------------------------
      Benchmark                           Time           CPU Iterations
      ------------------------------------------------------------------
      BM_sendVec_binderize/4          45959 ns      20288 ns      34351
      BM_sendVec_binderize/8          45603 ns      20080 ns      34909
      BM_sendVec_binderize/16         45528 ns      20113 ns      34863
      BM_sendVec_binderize/32         45551 ns      20122 ns      34881
      BM_sendVec_binderize/64         45701 ns      20183 ns      34864
      BM_sendVec_binderize/128        45824 ns      20250 ns      34576
      BM_sendVec_binderize/256        45695 ns      20171 ns      34759
      BM_sendVec_binderize/512        45743 ns      20211 ns      34489
      BM_sendVec_binderize/1024       46169 ns      20430 ns      34081
      
      After patch:
      ------------------------------------------------------------------
      Benchmark                           Time           CPU Iterations
      ------------------------------------------------------------------
      BM_sendVec_binderize/4          42939 ns      17262 ns      40653
      BM_sendVec_binderize/8          42823 ns      17243 ns      40671
      BM_sendVec_binderize/16         42898 ns      17243 ns      40594
      BM_sendVec_binderize/32         42838 ns      17267 ns      40527
      BM_sendVec_binderize/64         42854 ns      17249 ns      40379
      BM_sendVec_binderize/128        42881 ns      17288 ns      40427
      BM_sendVec_binderize/256        42917 ns      17297 ns      40429
      BM_sendVec_binderize/512        43184 ns      17395 ns      40411
      BM_sendVec_binderize/1024       43119 ns      17357 ns      40432
      Signed-off-by: NMartijn Coenen <maco@android.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      148ade2c
  19. 31 10月, 2017 1 次提交
    • K
      treewide: Fix function prototypes for module_param_call() · e4dca7b7
      Kees Cook 提交于
      Several function prototypes for the set/get functions defined by
      module_param_call() have a slightly wrong argument types. This fixes
      those in an effort to clean up the calls when running under type-enforced
      compiler instrumentation for CFI. This is the result of running the
      following semantic patch:
      
      @match_module_param_call_function@
      declarer name module_param_call;
      identifier _name, _set_func, _get_func;
      expression _arg, _mode;
      @@
      
       module_param_call(_name, _set_func, _get_func, _arg, _mode);
      
      @fix_set_prototype
       depends on match_module_param_call_function@
      identifier match_module_param_call_function._set_func;
      identifier _val, _param;
      type _val_type, _param_type;
      @@
      
       int _set_func(
      -_val_type _val
      +const char * _val
       ,
      -_param_type _param
      +const struct kernel_param * _param
       ) { ... }
      
      @fix_get_prototype
       depends on match_module_param_call_function@
      identifier match_module_param_call_function._get_func;
      identifier _val, _param;
      type _val_type, _param_type;
      @@
      
       int _get_func(
      -_val_type _val
      +char * _val
       ,
      -_param_type _param
      +const struct kernel_param * _param
       ) { ... }
      
      Two additional by-hand changes are included for places where the above
      Coccinelle script didn't notice them:
      
      	drivers/platform/x86/thinkpad_acpi.c
      	fs/lockd/svc.c
      Signed-off-by: NKees Cook <keescook@chromium.org>
      Signed-off-by: NJessica Yu <jeyu@kernel.org>
      e4dca7b7
  20. 20 10月, 2017 2 次提交
  21. 04 10月, 2017 1 次提交
    • T
      binder: fix use-after-free in binder_transaction() · 512cf465
      Todd Kjos 提交于
      User-space normally keeps the node alive when creating a transaction
      since it has a reference to the target. The local strong ref keeps it
      alive if the sending process dies before the target process processes
      the transaction. If the source process is malicious or has a reference
      counting bug, this can fail.
      
      In this case, when we attempt to decrement the node in the failure
      path, the node has already been freed.
      
      This is fixed by taking a tmpref on the node while constructing
      the transaction. To avoid re-acquiring the node lock and inner
      proc lock to increment the proc's tmpref, a helper is used that
      does the ref increments on both the node and proc.
      Signed-off-by: NTodd Kjos <tkjos@google.com>
      Cc: stable <stable@vger.kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      512cf465