1. 29 7月, 2020 1 次提交
    • J
      binder: Prevent context manager from incrementing ref 0 · 4b836a14
      Jann Horn 提交于
      Binder is designed such that a binder_proc never has references to
      itself. If this rule is violated, memory corruption can occur when a
      process sends a transaction to itself; see e.g.
      <https://syzkaller.appspot.com/bug?extid=09e05aba06723a94d43d>.
      
      There is a remaining edgecase through which such a transaction-to-self
      can still occur from the context of a task with BINDER_SET_CONTEXT_MGR
      access:
      
       - task A opens /dev/binder twice, creating binder_proc instances P1
         and P2
       - P1 becomes context manager
       - P2 calls ACQUIRE on the magic handle 0, allocating index 0 in its
         handle table
       - P1 dies (by closing the /dev/binder fd and waiting a bit)
       - P2 becomes context manager
       - P2 calls ACQUIRE on the magic handle 0, allocating index 1 in its
         handle table
         [this triggers a warning: "binder: 1974:1974 tried to acquire
         reference to desc 0, got 1 instead"]
       - task B opens /dev/binder once, creating binder_proc instance P3
       - P3 calls P2 (via magic handle 0) with (void*)1 as argument (two-way
         transaction)
       - P2 receives the handle and uses it to call P3 (two-way transaction)
       - P3 calls P2 (via magic handle 0) (two-way transaction)
       - P2 calls P2 (via handle 1) (two-way transaction)
      
      And then, if P2 does *NOT* accept the incoming transaction work, but
      instead closes the binder fd, we get a crash.
      
      Solve it by preventing the context manager from using ACQUIRE on ref 0.
      There shouldn't be any legitimate reason for the context manager to do
      that.
      
      Additionally, print a warning if someone manages to find another way to
      trigger a transaction-to-self bug in the future.
      
      Cc: stable@vger.kernel.org
      Fixes: 457b9a6f ("Staging: android: add binder driver")
      Acked-by: NTodd Kjos <tkjos@google.com>
      Signed-off-by: NJann Horn <jannh@google.com>
      Reviewed-by: NMartijn Coenen <maco@android.com>
      Link: https://lore.kernel.org/r/20200727120424.1627555-1-jannh@google.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      4b836a14
  2. 23 7月, 2020 1 次提交
  3. 23 6月, 2020 1 次提交
    • T
      binder: fix null deref of proc->context · d35d3660
      Todd Kjos 提交于
      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 f0fe2c0f ("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: f0fe2c0f ("binder: prevent UAF for binderfs devices II")
      Acked-by: NChristian Brauner <christian.brauner@ubuntu.com>
      Signed-off-by: NTodd Kjos <tkjos@google.com>
      Cc: stable <stable@vger.kernel.org>
      Link: https://lore.kernel.org/r/20200622200715.114382-1-tkjos@google.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d35d3660
  4. 14 6月, 2020 1 次提交
    • M
      treewide: replace '---help---' in Kconfig files with 'help' · a7f7f624
      Masahiro Yamada 提交于
      Since commit 84af7a61 ("checkpatch: kconfig: prefer 'help' over
      '---help---'"), the number of '---help---' has been gradually
      decreasing, but there are still more than 2400 instances.
      
      This commit finishes the conversion. While I touched the lines,
      I also fixed the indentation.
      
      There are a variety of indentation styles found.
      
        a) 4 spaces + '---help---'
        b) 7 spaces + '---help---'
        c) 8 spaces + '---help---'
        d) 1 space + 1 tab + '---help---'
        e) 1 tab + '---help---'    (correct indentation)
        f) 1 tab + 1 space + '---help---'
        g) 1 tab + 2 spaces + '---help---'
      
      In order to convert all of them to 1 tab + 'help', I ran the
      following commend:
      
        $ find . -name 'Kconfig*' | xargs sed -i 's/^[[:space:]]*---help---/\thelp/'
      Signed-off-by: NMasahiro Yamada <masahiroy@kernel.org>
      a7f7f624
  5. 10 6月, 2020 2 次提交
  6. 23 4月, 2020 2 次提交
  7. 19 3月, 2020 1 次提交
    • C
      binderfs: port to new mount api · 095cf502
      Christian Brauner 提交于
      When I first wrote binderfs the new mount api had not yet landed. Now
      that it has been around for a little while and a bunch of filesystems
      have already been ported we should do so too. When Al sent his
      mount-api-conversion pr he requested that binderfs (and a few others) be
      ported separately. It's time we port binderfs. We can make use of the
      new option parser, get nicer infrastructure and it will be easier if we
      ever add any new mount options.
      
      This survives testing with the binderfs selftests:
      
      for i in `seq 1 1000`; do ./binderfs_test; done
      
      including the new stress tests I sent out for review today:
      
       TAP version 13
       1..1
       # selftests: filesystems/binderfs: binderfs_test
       # [==========] Running 3 tests from 1 test cases.
       # [ RUN      ] global.binderfs_stress
       # [  XFAIL!  ] Tests are not run as root. Skipping privileged tests
       # [==========] Running 3 tests from 1 test cases.
       # [ RUN      ] global.binderfs_stress
       # [       OK ] global.binderfs_stress
       # [ RUN      ] global.binderfs_test_privileged
       # [       OK ] global.binderfs_test_privileged
       # [ RUN      ] global.binderfs_test_unprivileged
       # # Allocated new binder device with major 243, minor 4, and name my-binder
       # # Detected binder version: 8
       # [==========] Running 3 tests from 1 test cases.
       # [ RUN      ] global.binderfs_stress
       # [       OK ] global.binderfs_stress
       # [ RUN      ] global.binderfs_test_privileged
       # [       OK ] global.binderfs_test_privileged
       # [ RUN      ] global.binderfs_test_unprivileged
       # [       OK ] global.binderfs_test_unprivileged
       # [==========] 3 / 3 tests passed.
       # [  PASSED  ]
       ok 1 selftests: filesystems/binderfs: binderfs_test
      
      Cc: Todd Kjos <tkjos@google.com>
      Signed-off-by: NChristian Brauner <christian.brauner@ubuntu.com>
      Reviewed-by: NKees Cook <keescook@chromium.org>
      Link: https://lore.kernel.org/r/20200313153427.141789-1-christian.brauner@ubuntu.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      095cf502
  8. 12 3月, 2020 1 次提交
  9. 04 3月, 2020 1 次提交
    • C
      binder: prevent UAF for binderfs devices II · f0fe2c0f
      Christian Brauner 提交于
      This is a necessary follow up to the first fix I proposed and we merged
      in 2669b8b0 ("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 51d8a7ec ("binder: prevent UAF read in
      print_binder_transaction_log_entry()").
      
      Fixes: 3ad20fe3 ("binder: implement binderfs")
      Fixes: 2669b8b0 ("binder: prevent UAF for binderfs devices")
      Fixes: 03e2e07e ("binder: Make transaction_log available in binderfs")
      Related : 51d8a7ec ("binder: prevent UAF read in print_binder_transaction_log_entry()")
      Cc: stable@vger.kernel.org
      Signed-off-by: NChristian Brauner <christian.brauner@ubuntu.com>
      Acked-by: NTodd Kjos <tkjos@google.com>
      Link: https://lore.kernel.org/r/20200303164340.670054-1-christian.brauner@ubuntu.comSigned-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f0fe2c0f
  10. 03 3月, 2020 1 次提交
    • C
      binder: prevent UAF for binderfs devices · 2669b8b0
      Christian Brauner 提交于
      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 51d8a7ec ("binder: prevent UAF read in
      print_binder_transaction_log_entry()").
      
      Fixes: 3ad20fe3 ("binder: implement binderfs")
      Fixes: 03e2e07e ("binder: Make transaction_log available in binderfs")
      Related : 51d8a7ec ("binder: prevent UAF read in print_binder_transaction_log_entry()")
      Cc: stable@vger.kernel.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>
      2669b8b0
  11. 22 1月, 2020 1 次提交
  12. 21 1月, 2020 1 次提交
  13. 14 12月, 2019 1 次提交
  14. 14 11月, 2019 3 次提交
  15. 23 10月, 2019 1 次提交
  16. 22 10月, 2019 1 次提交
  17. 17 10月, 2019 2 次提交
  18. 10 10月, 2019 2 次提交
  19. 04 9月, 2019 6 次提交
  20. 24 7月, 2019 2 次提交
  21. 01 7月, 2019 1 次提交
  22. 22 6月, 2019 1 次提交
  23. 13 6月, 2019 1 次提交
  24. 05 6月, 2019 1 次提交
  25. 21 5月, 2019 1 次提交
  26. 26 4月, 2019 1 次提交
  27. 25 4月, 2019 1 次提交
  28. 21 3月, 2019 1 次提交