1. 16 2月, 2018 3 次提交
    • 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
  2. 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
  3. 25 1月, 2018 1 次提交
  4. 10 1月, 2018 4 次提交
  5. 18 12月, 2017 2 次提交
  6. 29 11月, 2017 1 次提交
  7. 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
  8. 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
  9. 20 10月, 2017 2 次提交
  10. 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
  11. 18 9月, 2017 3 次提交
    • X
      binder: fix memory corruption in binder_transaction binder · d53bebdf
      Xu YiPing 提交于
      commit 7a4408c6 ("binder: make sure accesses to proc/thread are
      safe") made a change to enqueue tcomplete to thread->todo before
      enqueuing the transaction. However, in err_dead_proc_or_thread case,
      the tcomplete is directly freed, without dequeued. It may cause the
      thread->todo list to be corrupted.
      
      So, dequeue it before freeing.
      
      Fixes: 7a4408c6 ("binder: make sure accesses to proc/thread are safe")
      Signed-off-by: NXu YiPing <xuyiping@hisilicon.com>
      Signed-off-by: NTodd Kjos <tkjos@google.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d53bebdf
    • X
      binder: fix an ret value override · 52b81611
      Xu YiPing 提交于
      commit 372e3147 ("binder: guarantee txn complete / errors delivered
      in-order") incorrectly defined a local ret value.  This ret value will
      be invalid when out of the if block
      
      Fixes: 372e3147 ("binder: refactor binder ref inc/dec for thread safety")
      Signed-off-by: NXu YiPing <xuyiping@hislicon.com>
      Signed-off-by: NTodd Kjos <tkjos@google.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      52b81611
    • A
      android: binder: fix type mismatch warning · 1c363eae
      Arnd Bergmann 提交于
      Allowing binder to expose the 64-bit API on 32-bit kernels caused a
      build warning:
      
      drivers/android/binder.c: In function 'binder_transaction_buffer_release':
      drivers/android/binder.c:2220:15: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
          fd_array = (u32 *)(parent_buffer + fda->parent_offset);
                     ^
      drivers/android/binder.c: In function 'binder_translate_fd_array':
      drivers/android/binder.c:2445:13: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
        fd_array = (u32 *)(parent_buffer + fda->parent_offset);
                   ^
      drivers/android/binder.c: In function 'binder_fixup_parent':
      drivers/android/binder.c:2511:18: error: cast to pointer from integer of different size [-Werror=int-to-pointer-cast]
      
      This adds extra type casts to avoid the warning.
      
      However, there is another problem with the Kconfig option: turning
      it on or off creates two incompatible ABI versions, a kernel that
      has this enabled cannot run user space that was built without it
      or vice versa. A better solution might be to leave the option hidden
      until the binder code is fixed to deal with both ABI versions.
      
      Fixes: e8d2ed7d ("Revert "staging: Fix build issues with new binder API"")
      Signed-off-by: NArnd Bergmann <arnd@arndb.de>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1c363eae
  12. 01 9月, 2017 7 次提交
  13. 28 8月, 2017 2 次提交
    • S
      android: binder: Add global lru shrinker to binder · f2517eb7
      Sherry Yang 提交于
      Hold on to the pages allocated and mapped for transaction
      buffers until the system is under memory pressure. When
      that happens, use linux shrinker to free pages. Without
      using shrinker, patch "android: binder: Move buffer out
      of area shared with user space" will cause a significant
      slow down for small transactions that fit into the first
      page because free list buffer header used to be inlined
      with buffer data.
      
      In addition to prevent the performance regression for
      small transactions, this patch improves the performance
      for transactions that take up more than one page.
      
      Modify alloc selftest to work with the shrinker change.
      
      Test: Run memory intensive applications (Chrome and Camera)
      to trigger shrinker callbacks. Binder frees memory as expected.
      Test: Run binderThroughputTest with high memory pressure
      option enabled.
      Signed-off-by: NSherry Yang <sherryy@android.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f2517eb7
    • S
      android: binder: Add allocator selftest · 4175e2b4
      Sherry Yang 提交于
      binder_alloc_selftest tests that alloc_new_buf handles page allocation and
      deallocation properly when allocate and free buffers. The test allocates 5
      buffers of various sizes to cover all possible page alignment cases, and
      frees the buffers using a list of exhaustive freeing order.
      
      Test: boot the device with ANDROID_BINDER_IPC_SELFTEST config option
      enabled. Allocator selftest passes.
      Signed-off-by: NSherry Yang <sherryy@android.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4175e2b4
  14. 23 8月, 2017 3 次提交
  15. 17 7月, 2017 7 次提交