1. 01 9月, 2022 1 次提交
    • C
      binder: fix alloc->vma_vm_mm null-ptr dereference · 1da52815
      Carlos Llamas 提交于
      Syzbot reported a couple issues introduced by commit 44e602b4
      ("binder_alloc: add missing mmap_lock calls when using the VMA"), in
      which we attempt to acquire the mmap_lock when alloc->vma_vm_mm has not
      been initialized yet.
      
      This can happen if a binder_proc receives a transaction without having
      previously called mmap() to setup the binder_proc->alloc space in [1].
      Also, a similar issue occurs via binder_alloc_print_pages() when we try
      to dump the debugfs binder stats file in [2].
      
      Sample of syzbot's crash report:
        ==================================================================
        KASAN: null-ptr-deref in range [0x0000000000000128-0x000000000000012f]
        CPU: 0 PID: 3755 Comm: syz-executor229 Not tainted 6.0.0-rc1-next-20220819-syzkaller #0
        syz-executor229[3755] cmdline: ./syz-executor2294415195
        Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/22/2022
        RIP: 0010:__lock_acquire+0xd83/0x56d0 kernel/locking/lockdep.c:4923
        [...]
        Call Trace:
         <TASK>
         lock_acquire kernel/locking/lockdep.c:5666 [inline]
         lock_acquire+0x1ab/0x570 kernel/locking/lockdep.c:5631
         down_read+0x98/0x450 kernel/locking/rwsem.c:1499
         mmap_read_lock include/linux/mmap_lock.h:117 [inline]
         binder_alloc_new_buf_locked drivers/android/binder_alloc.c:405 [inline]
         binder_alloc_new_buf+0xa5/0x19e0 drivers/android/binder_alloc.c:593
         binder_transaction+0x242e/0x9a80 drivers/android/binder.c:3199
         binder_thread_write+0x664/0x3220 drivers/android/binder.c:3986
         binder_ioctl_write_read drivers/android/binder.c:5036 [inline]
         binder_ioctl+0x3470/0x6d00 drivers/android/binder.c:5323
         vfs_ioctl fs/ioctl.c:51 [inline]
         __do_sys_ioctl fs/ioctl.c:870 [inline]
         __se_sys_ioctl fs/ioctl.c:856 [inline]
         __x64_sys_ioctl+0x193/0x200 fs/ioctl.c:856
         do_syscall_x64 arch/x86/entry/common.c:50 [inline]
         do_syscall_64+0x35/0xb0 arch/x86/entry/common.c:80
         entry_SYSCALL_64_after_hwframe+0x63/0xcd
         [...]
        ==================================================================
      
      Fix these issues by setting up alloc->vma_vm_mm pointer during open()
      and caching directly from current->mm. This guarantees we have a valid
      reference to take the mmap_lock during scenarios described above.
      
      [1] https://syzkaller.appspot.com/bug?extid=f7dc54e5be28950ac459
      [2] https://syzkaller.appspot.com/bug?extid=a75ebe0452711c9e56d9
      
      Fixes: 44e602b4 ("binder_alloc: add missing mmap_lock calls when using the VMA")
      Cc: <stable@vger.kernel.org> # v5.15+
      Cc: Liam R. Howlett <Liam.Howlett@oracle.com>
      Reported-by: syzbot+f7dc54e5be28950ac459@syzkaller.appspotmail.com
      Reported-by: syzbot+a75ebe0452711c9e56d9@syzkaller.appspotmail.com
      Reviewed-by: NLiam R. Howlett <Liam.Howlett@oracle.com>
      Acked-by: NTodd Kjos <tkjos@google.com>
      Signed-off-by: NCarlos Llamas <cmllamas@google.com>
      Link: https://lore.kernel.org/r/20220829201254.1814484-2-cmllamas@google.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1da52815
  2. 29 8月, 2022 1 次提交
  3. 19 8月, 2022 1 次提交
  4. 18 8月, 2022 2 次提交
  5. 30 7月, 2022 2 次提交
    • L
      android: binder: fix lockdep check on clearing vma · b0cab80e
      Liam Howlett 提交于
      When munmapping a vma, the mmap_lock can be degraded to a write before
      calling close() on the file handle.  The binder close() function calls
      binder_alloc_set_vma() to clear the vma address, which now has a lock dep
      check for writing on the mmap_lock.  Change the lockdep check to ensure
      the reading lock is held while clearing and keep the write check while
      writing.
      
      Link: https://lkml.kernel.org/r/20220627151857.2316964-1-Liam.Howlett@oracle.com
      Fixes: 472a68df605b ("android: binder: stop saving a pointer to the VMA")
      Signed-off-by: NLiam R. Howlett <Liam.Howlett@oracle.com>
      Reported-by: syzbot+da54fa8d793ca89c741f@syzkaller.appspotmail.com
      Acked-by: NTodd Kjos <tkjos@google.com>
      Cc: "Arve Hjønnevåg" <arve@android.com>
      Cc: Christian Brauner (Microsoft) <brauner@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Hridya Valsaraju <hridya@google.com>
      Cc: Joel Fernandes <joel@joelfernandes.org>
      Cc: Martijn Coenen <maco@android.com>
      Cc: Suren Baghdasaryan <surenb@google.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      b0cab80e
    • L
      android: binder: stop saving a pointer to the VMA · a43cfc87
      Liam R. Howlett 提交于
      Do not record a pointer to a VMA outside of the mmap_lock for later use. 
      This is unsafe and there are a number of failure paths *after* the
      recorded VMA pointer may be freed during setup.  There is no callback to
      the driver to clear the saved pointer from generic mm code.  Furthermore,
      the VMA pointer may become stale if any number of VMA operations end up
      freeing the VMA so saving it was fragile to being with.
      
      Instead, change the binder_alloc struct to record the start address of the
      VMA and use vma_lookup() to get the vma when needed.  Add lockdep
      mmap_lock checks on updates to the vma pointer to ensure the lock is held
      and depend on that lock for synchronization of readers and writers - which
      was already the case anyways, so the smp_wmb()/smp_rmb() was not
      necessary.
      
      [akpm@linux-foundation.org: fix drivers/android/binder_alloc_selftest.c]
      Link: https://lkml.kernel.org/r/20220621140212.vpkio64idahetbyf@revolver
      Fixes: da1b9564 ("android: binder: fix the race mmap and alloc_new_buf_locked")
      Reported-by: syzbot+58b51ac2b04e388ab7b0@syzkaller.appspotmail.com
      Signed-off-by: NLiam R. Howlett <Liam.Howlett@oracle.com>
      Cc: Minchan Kim <minchan@kernel.org>
      Cc: Christian Brauner (Microsoft) <brauner@kernel.org>
      Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
      Cc: Hridya Valsaraju <hridya@google.com>
      Cc: Joel Fernandes <joel@joelfernandes.org>
      Cc: Martijn Coenen <maco@android.com>
      Cc: Suren Baghdasaryan <surenb@google.com>
      Cc: Todd Kjos <tkjos@android.com>
      Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      a43cfc87
  6. 08 7月, 2022 1 次提交
    • C
      binder: fix redefinition of seq_file attributes · b7e241bb
      Carlos Llamas 提交于
      The patchset in [1] exported some definitions to binder_internal.h in
      order to make the debugfs entries such as 'stats' and 'transaction_log'
      available in a binderfs instance. However, the DEFINE_SHOW_ATTRIBUTE
      macro expands into a static function/variable pair, which in turn get
      redefined each time a source file includes this internal header.
      
      This problem was made evident after a report from the kernel test robot
      <lkp@intel.com> where several W=1 build warnings are seen in downstream
      kernels. See the following example:
      
        include/../drivers/android/binder_internal.h:111:23: warning: 'binder_stats_fops' defined but not used [-Wunused-const-variable=]
           111 | DEFINE_SHOW_ATTRIBUTE(binder_stats);
               |                       ^~~~~~~~~~~~
        include/linux/seq_file.h:174:37: note: in definition of macro 'DEFINE_SHOW_ATTRIBUTE'
           174 | static const struct file_operations __name ## _fops = {                 \
               |                                     ^~~~~~
      
      This patch fixes the above issues by moving back the definitions into
      binder.c and instead creates an array of the debugfs entries which is
      more convenient to share with binderfs and iterate through.
      
        [1] https://lore.kernel.org/all/20190903161655.107408-1-hridya@google.com/
      
      Fixes: 0e13e452 ("binder: Add stats, state and transactions files")
      Fixes: 03e2e07e ("binder: Make transaction_log available in binderfs")
      Reported-by: Nkernel test robot <lkp@intel.com>
      Signed-off-by: NCarlos Llamas <cmllamas@google.com>
      Link: https://lore.kernel.org/r/20220701182041.2134313-1-cmllamas@google.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b7e241bb
  7. 04 7月, 2022 1 次提交
    • R
      mm: shrinkers: provide shrinkers with names · e33c267a
      Roman Gushchin 提交于
      Currently shrinkers are anonymous objects.  For debugging purposes they
      can be identified by count/scan function names, but it's not always
      useful: e.g.  for superblock's shrinkers it's nice to have at least an
      idea of to which superblock the shrinker belongs.
      
      This commit adds names to shrinkers.  register_shrinker() and
      prealloc_shrinker() functions are extended to take a format and arguments
      to master a name.
      
      In some cases it's not possible to determine a good name at the time when
      a shrinker is allocated.  For such cases shrinker_debugfs_rename() is
      provided.
      
      The expected format is:
          <subsystem>-<shrinker_type>[:<instance>]-<id>
      For some shrinkers an instance can be encoded as (MAJOR:MINOR) pair.
      
      After this change the shrinker debugfs directory looks like:
        $ cd /sys/kernel/debug/shrinker/
        $ ls
          dquota-cache-16     sb-devpts-28     sb-proc-47       sb-tmpfs-42
          mm-shadow-18        sb-devtmpfs-5    sb-proc-48       sb-tmpfs-43
          mm-zspool:zram0-34  sb-hugetlbfs-17  sb-pstore-31     sb-tmpfs-44
          rcu-kfree-0         sb-hugetlbfs-33  sb-rootfs-2      sb-tmpfs-49
          sb-aio-20           sb-iomem-12      sb-securityfs-6  sb-tracefs-13
          sb-anon_inodefs-15  sb-mqueue-21     sb-selinuxfs-22  sb-xfs:vda1-36
          sb-bdev-3           sb-nsfs-4        sb-sockfs-8      sb-zsmalloc-19
          sb-bpf-32           sb-pipefs-14     sb-sysfs-26      thp-deferred_split-10
          sb-btrfs:vda2-24    sb-proc-25       sb-tmpfs-1       thp-zero-9
          sb-cgroup2-30       sb-proc-39       sb-tmpfs-27      xfs-buf:vda1-37
          sb-configfs-23      sb-proc-41       sb-tmpfs-29      xfs-inodegc:vda1-38
          sb-dax-11           sb-proc-45       sb-tmpfs-35
          sb-debugfs-7        sb-proc-46       sb-tmpfs-40
      
      [roman.gushchin@linux.dev: fix build warnings]
        Link: https://lkml.kernel.org/r/Yr+ZTnLb9lJk6fJO@castleReported-by: Nkernel test robot <lkp@intel.com>
      Link: https://lkml.kernel.org/r/20220601032227.4076670-4-roman.gushchin@linux.devSigned-off-by: NRoman Gushchin <roman.gushchin@linux.dev>
      Cc: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
      Cc: Dave Chinner <dchinner@redhat.com>
      Cc: Hillf Danton <hdanton@sina.com>
      Cc: Kent Overstreet <kent.overstreet@gmail.com>
      Cc: Muchun Song <songmuchun@bytedance.com>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      e33c267a
  8. 01 7月, 2022 1 次提交
  9. 27 6月, 2022 1 次提交
    • L
      Binder: add TF_UPDATE_TXN to replace outdated txn · 9864bb48
      Li Li 提交于
      When the target process is busy, incoming oneway transactions are
      queued in the async_todo list. If the clients continue sending extra
      oneway transactions while the target process is frozen, this queue can
      become too large to accommodate new transactions. That's why binder
      driver introduced ONEWAY_SPAM_DETECTION to detect this situation. It's
      helpful to debug the async binder buffer exhausting issue, but the
      issue itself isn't solved directly.
      
      In real cases applications are designed to send oneway transactions
      repeatedly, delivering updated inforamtion to the target process.
      Typical examples are Wi-Fi signal strength and some real time sensor
      data. Even if the apps might only care about the lastet information,
      all outdated oneway transactions are still accumulated there until the
      frozen process is thawed later. For this kind of situations, there's
      no existing method to skip those outdated transactions and deliver the
      latest one only.
      
      This patch introduces a new transaction flag TF_UPDATE_TXN. To use it,
      use apps can set this new flag along with TF_ONE_WAY. When such an
      oneway transaction is to be queued into the async_todo list of a frozen
      process, binder driver will check if any previous pending transactions
      can be superseded by comparing their code, flags and target node. If
      such an outdated pending transaction is found, the latest transaction
      will supersede that outdated one. This effectively prevents the async
      binder buffer running out and saves unnecessary binder read workloads.
      Acked-by: NTodd Kjos <tkjos@google.com>
      Signed-off-by: NLi Li <dualli@google.com>
      Link: https://lore.kernel.org/r/20220526220018.3334775-2-dualli@chromium.orgSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      9864bb48
  10. 06 6月, 2022 1 次提交
  11. 20 5月, 2022 3 次提交
  12. 15 5月, 2022 1 次提交
    • A
      Unify the primitives for file descriptor closing · 6319194e
      Al Viro 提交于
      Currently we have 3 primitives for removing an opened file from descriptor
      table - pick_file(), __close_fd_get_file() and close_fd_get_file().  Their
      calling conventions are rather odd and there's a code duplication for no
      good reason.  They can be unified -
      
      1) have __range_close() cap max_fd in the very beginning; that way
      we don't need separate way for pick_file() to report being past the end
      of descriptor table.
      
      2) make {__,}close_fd_get_file() return file (or NULL) directly, rather
      than returning it via struct file ** argument.  Don't bother with
      (bogus) return value - nobody wants that -ENOENT.
      
      3) make pick_file() return NULL on unopened descriptor - the only caller
      that used to care about the distinction between descriptor past the end
      of descriptor table and finding NULL in descriptor table doesn't give
      a damn after (1).
      
      4) lift ->files_lock out of pick_file()
      
      That actually simplifies the callers, as well as the primitives themselves.
      Code duplication is also gone...
      Reviewed-by: NChristian Brauner (Microsoft) <brauner@kernel.org>
      Signed-off-by: NAl Viro <viro@zeniv.linux.org.uk>
      6319194e
  13. 09 5月, 2022 5 次提交
  14. 26 4月, 2022 3 次提交
  15. 22 4月, 2022 3 次提交
  16. 04 2月, 2022 1 次提交
  17. 21 12月, 2021 2 次提交
  18. 10 12月, 2021 1 次提交
  19. 09 12月, 2021 1 次提交
  20. 03 12月, 2021 5 次提交
  21. 17 11月, 2021 1 次提交
  22. 19 10月, 2021 1 次提交
  23. 15 10月, 2021 1 次提交