Re: [selftest/bpf] b83590ee1a: BUG:KASAN:slab-out-of-bounds_in_l

2020-11-11 Thread Daniel Xu
Hi Daniel,

On Mon Nov 9, 2020 at 8:54 AM PST, Daniel Borkmann wrote:
> Hi Daniel,
>
> On 11/9/20 3:54 PM, kernel test robot wrote:
> > Greeting,
> > 
> > FYI, we noticed the following commit (built with gcc-9):
> > 
> > commit: b83590ee1add052518603bae607b0524632b7793 ("[PATCH bpf v3 2/2] 
> > selftest/bpf: Test bpf_probe_read_user_str() strips trailing bytes after 
> > NUL")
> > url: 
> > https://github.com/0day-ci/linux/commits/Daniel-Xu/Fix-bpf_probe_read_user_str-overcopying/20201106-033210
> > base: https://git.kernel.org/cgit/linux/kernel/git/bpf/bpf.git master
>
> I've tossed them from the tree for now as it looks like these are adding
> regressions
> for regular strncpy_from_user() calls, please take a look.
>
> Thanks!

Sorry about the KASAN issue.

I spent a day reproing. The kasan warnings seem a bit misleading but I
think I have a fix. I'll put a v5 shortly. I'll see if any of the bots
find errors on it.

Thanks,
Daniel


Re: [selftest/bpf] b83590ee1a: BUG:KASAN:slab-out-of-bounds_in_l

2020-11-09 Thread Daniel Borkmann

Hi Daniel,

On 11/9/20 3:54 PM, kernel test robot wrote:

Greeting,

FYI, we noticed the following commit (built with gcc-9):

commit: b83590ee1add052518603bae607b0524632b7793 ("[PATCH bpf v3 2/2] selftest/bpf: 
Test bpf_probe_read_user_str() strips trailing bytes after NUL")
url: 
https://github.com/0day-ci/linux/commits/Daniel-Xu/Fix-bpf_probe_read_user_str-overcopying/20201106-033210
base: https://git.kernel.org/cgit/linux/kernel/git/bpf/bpf.git master


I've tossed them from the tree for now as it looks like these are adding 
regressions
for regular strncpy_from_user() calls, please take a look.

Thanks!


in testcase: trinity
version: trinity-x86_64-af355e9-1_2019-12-03
with following parameters:

runtime: 300s

test-description: Trinity is a linux system call fuzz tester.
test-url: http://codemonkey.org.uk/projects/trinity/


on test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 8G

caused below changes (please refer to attached dmesg/kmsg for entire 
log/backtrace):


++++
|| 
e65411d04b | b83590ee1a |
++++
| BUG:KASAN:slab-out-of-bounds_in_l  | 
0  | 4  |
++++


If you fix the issue, kindly add following tag
Reported-by: kernel test robot 


[   54.933739] BUG: KASAN: slab-out-of-bounds in link_path_walk+0x8f5/0xa80
[   54.935295] Read of size 1 at addr 88815f726951 by task modprobe/114
[   54.936720]
[   54.937199] CPU: 1 PID: 114 Comm: modprobe Not tainted 
5.9.0-13439-gb83590ee1add #1
[   54.938907] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
1.12.0-1 04/01/2014
[   54.940683] Call Trace:
[   54.941008]  dump_stack+0x84/0xad
[   54.941008]  print_address_description+0x2f/0x220
[   54.941008]  ? pm_suspend.cold+0x70e/0x70e
[   54.941008]  ? _raw_write_lock_irqsave+0x150/0x150
[   54.941008]  ? link_path_walk+0x8f5/0xa80
[   54.941008]  kasan_report.cold+0x37/0x7c
[   54.941008]  ? link_path_walk+0x8f5/0xa80
[   54.941008]  __asan_report_load1_noabort+0x14/0x20
[   54.941008]  link_path_walk+0x8f5/0xa80
[   54.941008]  ? walk_component+0x670/0x670
[   54.941008]  ? deactivate_slab+0x3d9/0x690
[   54.941008]  link_path_walk+0x91/0xb0
[   54.941008]  path_lookupat+0x12f/0x430
[   54.941008]  filename_lookup+0x19a/0x2d0
[   54.941008]  ? may_linkat+0x180/0x180
[   54.941008]  ? __check_object_size+0x2bf/0x390
[   54.941008]  ? strncpy_from_user+0x24b/0x490
[   54.941008]  ? getname_flags+0x13a/0x4a0
[   54.941008]  user_path_at_empty+0x3f/0x50
[   54.941008]  do_faccessat+0xc1/0x5d0
[   54.941008]  ? stream_open+0x60/0x60
[   54.941008]  ? exit_to_user_mode_prepare+0xb9/0x190
[   54.941008]  __x64_sys_access+0x56/0x80
[   54.941008]  do_syscall_64+0x5d/0x70
[   54.941008]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[   54.941008] RIP: 0033:0x7f3cc3f345f7
[   54.941008] Code: c8 ff c3 b8 01 00 00 00 0f 05 48 3d 01 f0 ff ff 73 01 c3 48 8d 
0d 19 9b 20 00 f7 d8 89 01 48 83 c8 ff c3 b8 15 00 00 00 0f 05 <48> 3d 01 f0 ff 
ff 73 01 c3 48 8d 0d f9 9a 20 00 f7 d8 89 01 48 83
[   54.941008] RSP: 002b:7ffde47f0b68 EFLAGS: 0246 ORIG_RAX: 
0015
[   54.941008] RAX: ffda RBX:  RCX: 7f3cc3f345f7
[   54.941008] RDX: 0006 RSI: 0004 RDI: 7f3cc3f39bd0
[   54.941008] RBP: 7ffde47f1c70 R08:  R09: 
[   54.941008] R10: 0022 R11: 0246 R12: 
[   54.941008] R13: 7ffde47f9330 R14: 000f R15: 7f3cc413e150
[   54.941008]
[   54.941008] Allocated by task 114:
[   54.941008]  kasan_save_stack+0x23/0x50
[   54.941008]  __kasan_kmalloc+0xe1/0xf0
[   54.941008]  kasan_slab_alloc+0xe/0x10
[   54.941008]  kmem_cache_alloc+0x166/0x360
[   54.941008]  getname_flags+0x4e/0x4a0
[   54.941008]  user_path_at_empty+0x2b/0x50
[   54.941008]  do_faccessat+0xc1/0x5d0
[   54.941008]  __x64_sys_access+0x56/0x80
[   54.941008]  do_syscall_64+0x5d/0x70
[   54.941008]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
[   54.941008]
[   54.941008] The buggy address belongs to the object at 88815f725900
[   54.941008]  which belongs to the cache names_cache of size 4096
[   54.941008] The buggy address is located 81 bytes to the right of
[   54.941008]  4096-byte region [88815f725900, 88815f726900)
[   54.941008] The buggy address belongs to the page:
[   54.941008] page:(ptrval) refcount:1 mapcount:0 
mapping: index:0x0 pfn:0x15f720
[   54.941008] head:(ptrval) order:3 compound_mapcount:0 
compound_pincount:0
[   54.941008] flags: 0x80010200(slab|head)
[