1. 18 1月, 2023 2 次提交
    • C
      binder: fix UAF of alloc->vma in race with munmap() · b84980c2
      Carlos Llamas 提交于
      stable inclusion
      from stable-v5.10.154
      commit 015ac18be7de25d17d6e5f1643cb3b60bfbe859e
      category: bugfix
      bugzilla: https://gitee.com/src-openeuler/kernel/issues/I68WW5
      CVE: CVE-2023-20928
      
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=015ac18be7de25d17d6e5f1643cb3b60bfbe859e
      
      --------------------------------
      
      In commit 720c2419 ("ANDROID: binder: change down_write to
      down_read") binder assumed the mmap read lock is sufficient to protect
      alloc->vma inside binder_update_page_range(). This used to be accurate
      until commit dd2283f2 ("mm: mmap: zap pages with read mmap_sem in
      munmap"), which now downgrades the mmap_lock after detaching the vma
      from the rbtree in munmap(). Then it proceeds to teardown and free the
      vma with only the read lock held.
      
      This means that accesses to alloc->vma in binder_update_page_range() now
      will race with vm_area_free() in munmap() and can cause a UAF as shown
      in the following KASAN trace:
      
        ==================================================================
        BUG: KASAN: use-after-free in vm_insert_page+0x7c/0x1f0
        Read of size 8 at addr ffff16204ad00600 by task server/558
      
        CPU: 3 PID: 558 Comm: server Not tainted 5.10.150-00001-gdc8dcf942daa #1
        Hardware name: linux,dummy-virt (DT)
        Call trace:
         dump_backtrace+0x0/0x2a0
         show_stack+0x18/0x2c
         dump_stack+0xf8/0x164
         print_address_description.constprop.0+0x9c/0x538
         kasan_report+0x120/0x200
         __asan_load8+0xa0/0xc4
         vm_insert_page+0x7c/0x1f0
         binder_update_page_range+0x278/0x50c
         binder_alloc_new_buf+0x3f0/0xba0
         binder_transaction+0x64c/0x3040
         binder_thread_write+0x924/0x2020
         binder_ioctl+0x1610/0x2e5c
         __arm64_sys_ioctl+0xd4/0x120
         el0_svc_common.constprop.0+0xac/0x270
         do_el0_svc+0x38/0xa0
         el0_svc+0x1c/0x2c
         el0_sync_handler+0xe8/0x114
         el0_sync+0x180/0x1c0
      
        Allocated by task 559:
         kasan_save_stack+0x38/0x6c
         __kasan_kmalloc.constprop.0+0xe4/0xf0
         kasan_slab_alloc+0x18/0x2c
         kmem_cache_alloc+0x1b0/0x2d0
         vm_area_alloc+0x28/0x94
         mmap_region+0x378/0x920
         do_mmap+0x3f0/0x600
         vm_mmap_pgoff+0x150/0x17c
         ksys_mmap_pgoff+0x284/0x2dc
         __arm64_sys_mmap+0x84/0xa4
         el0_svc_common.constprop.0+0xac/0x270
         do_el0_svc+0x38/0xa0
         el0_svc+0x1c/0x2c
         el0_sync_handler+0xe8/0x114
         el0_sync+0x180/0x1c0
      
        Freed by task 560:
         kasan_save_stack+0x38/0x6c
         kasan_set_track+0x28/0x40
         kasan_set_free_info+0x24/0x4c
         __kasan_slab_free+0x100/0x164
         kasan_slab_free+0x14/0x20
         kmem_cache_free+0xc4/0x34c
         vm_area_free+0x1c/0x2c
         remove_vma+0x7c/0x94
         __do_munmap+0x358/0x710
         __vm_munmap+0xbc/0x130
         __arm64_sys_munmap+0x4c/0x64
         el0_svc_common.constprop.0+0xac/0x270
         do_el0_svc+0x38/0xa0
         el0_svc+0x1c/0x2c
         el0_sync_handler+0xe8/0x114
         el0_sync+0x180/0x1c0
      
        [...]
        ==================================================================
      
      To prevent the race above, revert back to taking the mmap write lock
      inside binder_update_page_range(). One might expect an increase of mmap
      lock contention. However, binder already serializes these calls via top
      level alloc->mutex. Also, there was no performance impact shown when
      running the binder benchmark tests.
      
      Note this patch is specific to stable branches 5.4 and 5.10. Since in
      newer kernel releases binder no longer caches a pointer to the vma.
      Instead, it has been refactored to use vma_lookup() which avoids the
      issue described here. This switch was introduced in commit a43cfc87
      ("android: binder: stop saving a pointer to the VMA").
      
      Fixes: dd2283f2 ("mm: mmap: zap pages with read mmap_sem in munmap")
      Reported-by: NJann Horn <jannh@google.com>
      Cc: <stable@vger.kernel.org> # 5.10.x
      Cc: Minchan Kim <minchan@kernel.org>
      Cc: Yang Shi <yang.shi@linux.alibaba.com>
      Cc: Liam Howlett <liam.howlett@oracle.com>
      Signed-off-by: NCarlos Llamas <cmllamas@google.com>
      Acked-by: NTodd Kjos <tkjos@google.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      Signed-off-by: NChen Jiahao <chenjiahao16@huawei.com>
      Reviewed-by: NLiao Chang <liaochang1@huawei.com>
      Reviewed-by: NZhang Jianhua <chris.zjh@huawei.com>
      Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
      b84980c2
    • P
      io_uring: disable polling pollfree files · b3851214
      Pavel Begunkov 提交于
      stable inclusion
      from stable-v5.10.141
      commit 28d8d2737e82fc29ff9e788597661abecc7f7994
      category: bugfix
      bugzilla: https://gitee.com/openeuler/kernel/issues/I685FC
      CEV: NA
      
      Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.10.162&id=28d8d2737e82fc29ff9e788597661abecc7f7994
      
      --------------------------------
      
      Older kernels lack io_uring POLLFREE handling. As only affected files
      are signalfd and android binder the safest option would be to disable
      polling those files via io_uring and hope there are no users.
      
      Fixes: 221c5eb2 ("io_uring: add support for IORING_OP_POLL")
      Signed-off-by: NPavel Begunkov <asml.silence@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      
      conflicts:
        include/linux/fs.h
      Signed-off-by: NLi Lingfeng <lilingfeng3@huawei.com>
      Reviewed-by: NZhang Yi <yi.zhang@huawei.com>
      Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
      b3851214
  2. 27 10月, 2022 1 次提交
  3. 19 10月, 2022 1 次提交
  4. 27 4月, 2022 1 次提交
  5. 28 1月, 2022 1 次提交
  6. 22 1月, 2022 2 次提交
    • J
      vendor_hooks: make android vendor hooks feature generic. · fe56c942
      Jialin Zhang 提交于
      hulk inclusion
      category: feature
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4RCS8
      CVE: NA
      
      Reference: https://android.googlesource.com/kernel/common/
      
      ---------------------------
      
      Make android vendor hooks feature generic.
      Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
      Reviewed-by: NWei Li <liwei391@huawei.com>
      Reviewed-by: NXie XiuQi <xiexiuqi@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      fe56c942
    • T
      ANDROID: add support for vendor hooks · 122b83d2
      Todd Kjos 提交于
      aosp inclusion
      category: feature
      bugzilla: https://gitee.com/openeuler/kernel/issues/I4RCS8
      CVE: NA
      
      Reference: https://android.googlesource.com/kernel/common/+/7f62740112ef
      
      ---------------------------
      
      Add support for vendor hooks. Adds include/trace/hooks
      directory for trace definition headers where hooks
      can be defined and vendor_hook.c for instantiating
      and exporting them for vendor modules.
      
      There are two variants of vendor hooks, both based
      on tracepoints:
      
      Normal: this uses the DECLARE_HOOK macro
      to create a tracepoint function with the name trace_<name>
      where <name> is the unique identifier for the trace.
      
      Restricted: restricted hooks are needed for cases like
      scheduler hooks where the attached function must be
      called even if the cpu is offline or requires a
      non-atomic context. Restricted vendor hooks cannot
      be detached, so modules that attach to a restricted
      hook can never unload. Also, only 1 attachment is
      allowed (any other attempts to attach will fail with
      -EBUSY).
      
      For either case, modules attach to the hook by using
      register_trace_<name>(func_ptr, NULL).
      
      New hooks should be defined in headers in the
      include/trace/hooks/ directory using the
      DECLARE_HOOK() or DECLARE_RESTRICTED_HOOK()
      macros.
      
      New files added to include/trace/hooks should
      be #include'd from drivers/android/vendor_hooks.c.
      The EXPORT_TRACEPOINT_SYMBOL_GPL() should be
      also added to drivers/android/vendor_hooks.c.
      
      For example, if a new hook, 'android_vh_foo(int &ret)'
      is added in do_exit() in exit.c, these changes are
      needed:
      
      1. create a new header file include/trace/hooks/foo.h
      which contains:
      	#include <trace/hooks/vendor_hooks.h>
      	...
       	DECLARE_HOOK(android_vh_foo,
      		     TP_PROTO(int *retp),
      		     TP_ARGS(retp);
      
      2. in exit.c, add
      	#include <trace/hooks/foo.h>
      	...
        	int ret = 0;
      	...
        	android_vh_foo(&ret);
        	if (ret)
          		return ret;
      	...
      
      3. in drivers/android/vendor_hooks.c, add
      	#include <trace/hooks/foo.h>
      	...
      	EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_foo);
      
      The hook can then be attached by adding the registration code
      to the module:
      
      	#include <trace/hooks/sched.h>
      	...
      	static void my_foo(int *retp)
      	{
      		*retp = 0;
      	}
      	...
      	rc = register_trace_android_vh_sched_exit(my_foo, NULL);
      
      Bug: 156285741
      Signed-off-by: NTodd Kjos <tkjos@google.com>
      Change-Id: I6a7d1c8919dae91c965e2a0450df50eac2d282db
      Signed-off-by: NJialin Zhang <zhangjialin11@huawei.com>
      Reviewed-by: NWei Li <liwei391@huawei.com>
      Reviewed-by: NXie XiuQi <xiexiuqi@huawei.com>
      Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
      122b83d2
  7. 14 1月, 2022 2 次提交
  8. 06 12月, 2021 3 次提交
  9. 30 11月, 2021 1 次提交
  10. 15 11月, 2021 1 次提交
  11. 12 1月, 2021 1 次提交
  12. 18 10月, 2020 1 次提交
    • J
      task_work: cleanup notification modes · 91989c70
      Jens Axboe 提交于
      A previous commit changed the notification mode from true/false to an
      int, allowing notify-no, notify-yes, or signal-notify. This was
      backwards compatible in the sense that any existing true/false user
      would translate to either 0 (on notification sent) or 1, the latter
      which mapped to TWA_RESUME. TWA_SIGNAL was assigned a value of 2.
      
      Clean this up properly, and define a proper enum for the notification
      mode. Now we have:
      
      - TWA_NONE. This is 0, same as before the original change, meaning no
        notification requested.
      - TWA_RESUME. This is 1, same as before the original change, meaning
        that we use TIF_NOTIFY_RESUME.
      - TWA_SIGNAL. This uses TIF_SIGPENDING/JOBCTL_TASK_WORK for the
        notification.
      
      Clean up all the callers, switching their 0/1/false/true to using the
      appropriate TWA_* mode for notifications.
      
      Fixes: e91b4816 ("task_work: teach task_work_add() to do signal_wake_up()")
      Reviewed-by: NThomas Gleixner <tglx@linutronix.de>
      Signed-off-by: NJens Axboe <axboe@kernel.dk>
      91989c70
  13. 10 10月, 2020 1 次提交
    • T
      binder: fix UAF when releasing todo list · f3277cbf
      Todd Kjos 提交于
      When releasing a thread todo list when tearing down
      a binder_proc, the following race was possible which
      could result in a use-after-free:
      
      1.  Thread 1: enter binder_release_work from binder_thread_release
      2.  Thread 2: binder_update_ref_for_handle() -> binder_dec_node_ilocked()
      3.  Thread 2: dec nodeA --> 0 (will free node)
      4.  Thread 1: ACQ inner_proc_lock
      5.  Thread 2: block on inner_proc_lock
      6.  Thread 1: dequeue work (BINDER_WORK_NODE, part of nodeA)
      7.  Thread 1: REL inner_proc_lock
      8.  Thread 2: ACQ inner_proc_lock
      9.  Thread 2: todo list cleanup, but work was already dequeued
      10. Thread 2: free node
      11. Thread 2: REL inner_proc_lock
      12. Thread 1: deref w->type (UAF)
      
      The problem was that for a BINDER_WORK_NODE, the binder_work element
      must not be accessed after releasing the inner_proc_lock while
      processing the todo list elements since another thread might be
      handling a deref on the node containing the binder_work element
      leading to the node being freed.
      Signed-off-by: NTodd Kjos <tkjos@google.com>
      Link: https://lore.kernel.org/r/20201009232455.4054810-1-tkjos@google.com
      Cc: <stable@vger.kernel.org> # 4.14, 4.19, 5.4, 5.8
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f3277cbf
  14. 05 10月, 2020 1 次提交
  15. 16 9月, 2020 1 次提交
  16. 04 9月, 2020 4 次提交
  17. 29 7月, 2020 6 次提交
  18. 23 7月, 2020 1 次提交
  19. 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
  20. 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
  21. 10 6月, 2020 2 次提交
  22. 23 4月, 2020 2 次提交
  23. 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
  24. 12 3月, 2020 1 次提交
  25. 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