<feed xmlns='http://www.w3.org/2005/Atom'>
<title>user/sven/linux.git/drivers/android/binder_alloc.c, branch v4.14.117</title>
<subtitle>Linux Kernel
</subtitle>
<id>https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v4.14.117</id>
<link rel='self' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/atom?h=v4.14.117'/>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/'/>
<updated>2019-05-02T07:40:31Z</updated>
<entry>
<title>binder: fix handling of misaligned binder object</title>
<updated>2019-05-02T07:40:31Z</updated>
<author>
<name>Todd Kjos</name>
<email>tkjos@android.com</email>
</author>
<published>2019-02-14T23:22:57Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=33c6b9ca70a8b066a613e2a3d0331ae8f82aa31a'/>
<id>urn:sha1:33c6b9ca70a8b066a613e2a3d0331ae8f82aa31a</id>
<content type='text'>
commit 26528be6720bb40bc8844e97ee73a37e530e9c5e upstream.

Fixes crash found by syzbot:
kernel BUG at drivers/android/binder_alloc.c:LINE! (2)

Reported-and-tested-by: syzbot+55de1eb4975dec156d8f@syzkaller.appspotmail.com
Signed-off-by: Todd Kjos &lt;tkjos@google.com&gt;
Reviewed-by: Joel Fernandes (Google) &lt;joel@joelfernandes.org&gt;
Cc: stable &lt;stable@vger.kernel.org&gt; # 5.0, 4.19, 4.14
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>binder: fix race that allows malicious free of live buffer</title>
<updated>2018-12-05T18:41:26Z</updated>
<author>
<name>Todd Kjos</name>
<email>tkjos@android.com</email>
</author>
<published>2018-11-06T23:55:32Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=fd6cc33d0775b0d902906d88dd05cc1a2a059f8d'/>
<id>urn:sha1:fd6cc33d0775b0d902906d88dd05cc1a2a059f8d</id>
<content type='text'>
commit 7bada55ab50697861eee6bb7d60b41e68a961a9c upstream.

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: Todd Kjos &lt;tkjos@google.com&gt;
Acked-by: Arve Hjønnevåg &lt;arve@android.com&gt;
Cc: stable &lt;stable@vger.kernel.org&gt; # 4.14
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;


</content>
</entry>
<entry>
<title>android: binder: fix the race mmap and alloc_new_buf_locked</title>
<updated>2018-09-19T20:43:35Z</updated>
<author>
<name>Minchan Kim</name>
<email>minchan@kernel.org</email>
</author>
<published>2018-08-23T05:29:56Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=492519107c9d5ecfe3298586e3f5a33ac968b62c'/>
<id>urn:sha1:492519107c9d5ecfe3298586e3f5a33ac968b62c</id>
<content type='text'>
commit da1b9564e85b1d7baf66cbfabcab27e183a1db63 upstream.

There is RaceFuzzer report like below because we have no lock to close
below the race between binder_mmap and binder_alloc_new_buf_locked.
To close the race, let's use memory barrier so that if someone see
alloc-&gt;vma is not NULL, alloc-&gt;vma_vm_mm should be never NULL.

(I didn't add stable mark intentionallybecause standard android
userspace libraries that interact with binder (libbinder &amp; libhwbinder)
prevent the mmap/ioctl race. - from Todd)

"
Thread interleaving:
CPU0 (binder_alloc_mmap_handler)              CPU1 (binder_alloc_new_buf_locked)
=====                                         =====
// drivers/android/binder_alloc.c
// #L718 (v4.18-rc3)
alloc-&gt;vma = vma;
                                              // drivers/android/binder_alloc.c
                                              // #L346 (v4.18-rc3)
                                              if (alloc-&gt;vma == NULL) {
                                                  ...
                                                  // alloc-&gt;vma is not NULL at this point
                                                  return ERR_PTR(-ESRCH);
                                              }
                                              ...
                                              // #L438
                                              binder_update_page_range(alloc, 0,
                                                      (void *)PAGE_ALIGN((uintptr_t)buffer-&gt;data),
                                                      end_page_addr);

                                              // In binder_update_page_range() #L218
                                              // But still alloc-&gt;vma_vm_mm is NULL here
                                              if (need_mm &amp;&amp; mmget_not_zero(alloc-&gt;vma_vm_mm))
alloc-&gt;vma_vm_mm = vma-&gt;vm_mm;

Crash Log:
==================================================================
BUG: KASAN: null-ptr-deref in __atomic_add_unless include/asm-generic/atomic-instrumented.h:89 [inline]
BUG: KASAN: null-ptr-deref in atomic_add_unless include/linux/atomic.h:533 [inline]
BUG: KASAN: null-ptr-deref in mmget_not_zero include/linux/sched/mm.h:75 [inline]
BUG: KASAN: null-ptr-deref in binder_update_page_range+0xece/0x18e0 drivers/android/binder_alloc.c:218
Write of size 4 at addr 0000000000000058 by task syz-executor0/11184

CPU: 1 PID: 11184 Comm: syz-executor0 Not tainted 4.18.0-rc3 #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.8.2-0-g33fbe13 by qemu-project.org 04/01/2014
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x16e/0x22c lib/dump_stack.c:113
 kasan_report_error mm/kasan/report.c:352 [inline]
 kasan_report+0x163/0x380 mm/kasan/report.c:412
 check_memory_region_inline mm/kasan/kasan.c:260 [inline]
 check_memory_region+0x140/0x1a0 mm/kasan/kasan.c:267
 kasan_check_write+0x14/0x20 mm/kasan/kasan.c:278
 __atomic_add_unless include/asm-generic/atomic-instrumented.h:89 [inline]
 atomic_add_unless include/linux/atomic.h:533 [inline]
 mmget_not_zero include/linux/sched/mm.h:75 [inline]
 binder_update_page_range+0xece/0x18e0 drivers/android/binder_alloc.c:218
 binder_alloc_new_buf_locked drivers/android/binder_alloc.c:443 [inline]
 binder_alloc_new_buf+0x467/0xc30 drivers/android/binder_alloc.c:513
 binder_transaction+0x125b/0x4fb0 drivers/android/binder.c:2957
 binder_thread_write+0xc08/0x2770 drivers/android/binder.c:3528
 binder_ioctl_write_read.isra.39+0x24f/0x8e0 drivers/android/binder.c:4456
 binder_ioctl+0xa86/0xf34 drivers/android/binder.c:4596
 vfs_ioctl fs/ioctl.c:46 [inline]
 do_vfs_ioctl+0x154/0xd40 fs/ioctl.c:686
 ksys_ioctl+0x94/0xb0 fs/ioctl.c:701
 __do_sys_ioctl fs/ioctl.c:708 [inline]
 __se_sys_ioctl fs/ioctl.c:706 [inline]
 __x64_sys_ioctl+0x43/0x50 fs/ioctl.c:706
 do_syscall_64+0x167/0x4b0 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
"

Signed-off-by: Todd Kjos &lt;tkjos@google.com&gt;
Signed-off-by: Minchan Kim &lt;minchan@kernel.org&gt;
Reviewed-by: Martijn Coenen &lt;maco@android.com&gt;
Cc: stable &lt;stable@vger.kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>android: binder: use VM_ALLOC to get vm area</title>
<updated>2018-02-03T16:39:22Z</updated>
<author>
<name>Ganesh Mahendran</name>
<email>opensource.ganesh@gmail.com</email>
</author>
<published>2018-01-10T02:49:05Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=86eda3864a704a98d5444ae60654b898731bfea5'/>
<id>urn:sha1:86eda3864a704a98d5444ae60654b898731bfea5</id>
<content type='text'>
commit aac6830ec1cb681544212838911cdc57f2638216 upstream.

VM_IOREMAP is used to access hardware through a mechanism called
I/O mapped memory. Android binder is a IPC machanism which will
not access I/O memory.

And VM_IOREMAP has alignment requiement which may not needed in
binder.
    __get_vm_area_node()
    {
    ...
        if (flags &amp; VM_IOREMAP)
            align = 1ul &lt;&lt; clamp_t(int, fls_long(size),
               PAGE_SHIFT, IOREMAP_MAX_ORDER);
    ...
    }

This patch will save some kernel vm area, especially for 32bit os.

In 32bit OS, kernel vm area is only 240MB. We may got below
error when launching a app:

&lt;3&gt;[ 4482.440053] binder_alloc: binder_alloc_mmap_handler: 15728 8ce67000-8cf65000 get_vm_area failed -12
&lt;3&gt;[ 4483.218817] binder_alloc: binder_alloc_mmap_handler: 15745 8ce67000-8cf65000 get_vm_area failed -12

Signed-off-by: Ganesh Mahendran &lt;opensource.ganesh@gmail.com&gt;
Acked-by: Martijn Coenen &lt;maco@android.com&gt;
Acked-by: Todd Kjos &lt;tkjos@google.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
</entry>
<entry>
<title>android: binder: Fix null ptr dereference in debug msg</title>
<updated>2017-10-21T08:14:20Z</updated>
<author>
<name>Sherry Yang</name>
<email>sherryy@android.com</email>
</author>
<published>2017-10-21T00:58:59Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=ae65c8510f3319dfb2114cc48d476b81232e27b3'/>
<id>urn:sha1:ae65c8510f3319dfb2114cc48d476b81232e27b3</id>
<content type='text'>
Don't access next-&gt;data in kernel debug message when the
next buffer is null.

Acked-by: Arve Hjønnevåg &lt;arve@android.com&gt;
Signed-off-by: Sherry Yang &lt;sherryy@android.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>android: binder: Don't get mm from task</title>
<updated>2017-10-21T08:14:20Z</updated>
<author>
<name>Sherry Yang</name>
<email>sherryy@android.com</email>
</author>
<published>2017-10-21T00:58:58Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=a0c2baaf81bd53dc76fccdddc721ba7dbb62be21'/>
<id>urn:sha1:a0c2baaf81bd53dc76fccdddc721ba7dbb62be21</id>
<content type='text'>
Use binder_alloc struct's mm_struct rather than getting
a reference to the mm struct through get_task_mm to
avoid a potential deadlock between lru lock, task lock and
dentry lock, since a thread can be holding the task lock
and the dentry lock while trying to acquire the lru lock.

Acked-by: Arve Hjønnevåg &lt;arve@android.com&gt;
Signed-off-by: Sherry Yang &lt;sherryy@android.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>android: binder: drop lru lock in isolate callback</title>
<updated>2017-10-04T00:54:24Z</updated>
<author>
<name>Sherry Yang</name>
<email>sherryy@android.com</email>
</author>
<published>2017-10-03T23:15:00Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=a1b2289cef92ef0e9a92afcd2e1ea71d5bcaaf64'/>
<id>urn:sha1:a1b2289cef92ef0e9a92afcd2e1ea71d5bcaaf64</id>
<content type='text'>
Drop the global lru lock in isolate callback before calling
zap_page_range which calls cond_resched, and re-acquire the global lru
lock before returning.  Also change return code to LRU_REMOVED_RETRY.

Use mmput_async when fail to acquire mmap sem in an atomic context.

Fix "BUG: sleeping function called from invalid context"
errors when CONFIG_DEBUG_ATOMIC_SLEEP is enabled.

Also restore mmput_async, which was initially introduced in commit
ec8d7c14ea14 ("mm, oom_reaper: do not mmput synchronously from the oom
reaper context"), and was removed in commit 212925802454 ("mm: oom: let
oom_reap_task and exit_mmap run concurrently").

Link: http://lkml.kernel.org/r/20170914182231.90908-1-sherryy@android.com
Fixes: f2517eb76f1f2 ("android: binder: Add global lru shrinker to binder")
Signed-off-by: Sherry Yang &lt;sherryy@android.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Reported-by: Kyle Yan &lt;kyan@codeaurora.org&gt;
Acked-by: Arve Hjønnevåg &lt;arve@android.com&gt;
Acked-by: Michal Hocko &lt;mhocko@suse.com&gt;
Cc: Martijn Coenen &lt;maco@google.com&gt;
Cc: Todd Kjos &lt;tkjos@google.com&gt;
Cc: Riley Andrews &lt;riandrews@android.com&gt;
Cc: Ingo Molnar &lt;mingo@kernel.org&gt;
Cc: Vlastimil Babka &lt;vbabka@suse.cz&gt;
Cc: Hillf Danton &lt;hdanton@sina.com&gt;
Cc: Peter Zijlstra &lt;peterz@infradead.org&gt;
Cc: Andrea Arcangeli &lt;aarcange@redhat.com&gt;
Cc: Thomas Gleixner &lt;tglx@linutronix.de&gt;
Cc: Andy Lutomirski &lt;luto@kernel.org&gt;
Cc: Oleg Nesterov &lt;oleg@redhat.com&gt;
Cc: Hoeun Ryu &lt;hoeun.ryu@gmail.com&gt;
Cc: Christopher Lameter &lt;cl@linux.com&gt;
Cc: Vegard Nossum &lt;vegard.nossum@oracle.com&gt;
Cc: Frederic Weisbecker &lt;fweisbec@gmail.com&gt;
Signed-off-by: Andrew Morton &lt;akpm@linux-foundation.org&gt;
Signed-off-by: Linus Torvalds &lt;torvalds@linux-foundation.org&gt;
</content>
</entry>
<entry>
<title>android: binder: Add page usage in binder stats</title>
<updated>2017-09-01T06:53:32Z</updated>
<author>
<name>Sherry Yang</name>
<email>sherryy@android.com</email>
</author>
<published>2017-08-31T18:56:36Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=8ef4665aa129a14f3733efc651c53a3c6c47b500'/>
<id>urn:sha1:8ef4665aa129a14f3733efc651c53a3c6c47b500</id>
<content type='text'>
Add the number of active, lru, and free pages for
each binder process in binder stats

Signed-off-by: Sherry Yang &lt;sherryy@android.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>android: binder: fixup crash introduced by moving buffer hdr</title>
<updated>2017-09-01T06:53:32Z</updated>
<author>
<name>Sherry Yang</name>
<email>sherryy@android.com</email>
</author>
<published>2017-08-31T17:26:06Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=957ccc2bc8f9ebfe8b19112cdc6c2bb20fd7bcf8'/>
<id>urn:sha1:957ccc2bc8f9ebfe8b19112cdc6c2bb20fd7bcf8</id>
<content type='text'>
Fix crash introduced by 74310e06be4d74dcf67cd108366710dee5c576d5
(android: binder: Move buffer out of area shared with user space)
when close is called after open without mmap in between.

Reported-by: kernel test robot &lt;fengguang.wu@intel.com&gt;
Fixes: 74310e06be4d ("android: binder: Move buffer out of area shared with user space")
Signed-off-by: Sherry Yang &lt;sherryy@android.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>android: binder: Add shrinker tracepoints</title>
<updated>2017-08-28T14:47:17Z</updated>
<author>
<name>Sherry Yang</name>
<email>sherryy@android.com</email>
</author>
<published>2017-08-23T15:46:43Z</published>
<link rel='alternate' type='text/html' href='https://git.stealer.net/cgit.cgi/user/sven/linux.git/commit/?id=e41e164c3cdff632f7e4372d1d5a0df35338c370'/>
<id>urn:sha1:e41e164c3cdff632f7e4372d1d5a0df35338c370</id>
<content type='text'>
Add tracepoints in binder transaction allocator to
record lru hits and alloc/free page.

Signed-off-by: Sherry Yang &lt;sherryy@android.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
</feed>
