All of lore.kernel.org
 help / color / mirror / Atom feed
* [syzbot] [kernel?] linux-next test error: UBSAN: array-index-out-of-bounds in alloc_pid
@ 2023-05-17  7:40 syzbot
  2023-05-17  8:25 ` Christian Brauner
  0 siblings, 1 reply; 3+ messages in thread
From: syzbot @ 2023-05-17  7:40 UTC (permalink / raw)
  To: brauner, linux-kernel, linux-next, sfr, syzkaller-bugs

Hello,

syzbot found the following issue on:

HEAD commit:    065efa589871 Add linux-next specific files for 20230517
git tree:       linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=17f27bb2280000
kernel config:  https://syzkaller.appspot.com/x/.config?x=821eeb02ef201bcc
dashboard link: https://syzkaller.appspot.com/bug?extid=ac3b41786a2d0565b6d5
compiler:       gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2

Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/dbbd691e9e5a/disk-065efa58.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/e5b9541c3979/vmlinux-065efa58.xz
kernel image: https://storage.googleapis.com/syzbot-assets/44cf3f3aaabb/bzImage-065efa58.xz

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+ac3b41786a2d0565b6d5@syzkaller.appspotmail.com

================================================================================
UBSAN: array-index-out-of-bounds in kernel/pid.c:244:15
index 1 is out of range for type 'upid [1]'
CPU: 1 PID: 5002 Comm: syz-executor.0 Not tainted 6.4.0-rc2-next-20230517-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/28/2023
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x136/0x150 lib/dump_stack.c:106
 ubsan_epilogue lib/ubsan.c:217 [inline]
 __ubsan_handle_out_of_bounds+0xd5/0x140 lib/ubsan.c:348
 alloc_pid+0xbe5/0xdd0 kernel/pid.c:244
 copy_process+0x45da/0x7660 kernel/fork.c:2522
 kernel_clone+0xeb/0x890 kernel/fork.c:2914
 __do_sys_clone+0xba/0x100 kernel/fork.c:3057
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x39/0xb0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x63/0xcd
RIP: 0033:0x7f23be089e9b
Code: ed 0f 85 60 01 00 00 64 4c 8b 0c 25 10 00 00 00 45 31 c0 4d 8d 91 d0 02 00 00 31 d2 31 f6 bf 11 00 20 01 b8 38 00 00 00 0f 05 <48> 3d 00 f0 ff ff 0f 87 89 00 00 00 41 89 c5 85 c0 0f 85 90 00 00
RSP: 002b:00007ffe5c64b680 EFLAGS: 00000246 ORIG_RAX: 0000000000000038
RAX: ffffffffffffffda RBX: 00007ffe5c64bcd8 RCX: 00007f23be089e9b
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000001200011
RBP: 0000000000000000 R08: 0000000000000000 R09: 0000555557393400
R10: 00005555573936d0 R11: 0000000000000246 R12: 0000000000000000
R13: 00007ffe5c64b770 R14: 00007f23be1ac9d8 R15: 000000000000000c
 </TASK>
================================================================================


---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.

syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.

If the bug is already fixed, let syzbot know by replying with:
#syz fix: exact-commit-title

If you want to change bug's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)

If the bug is a duplicate of another bug, reply with:
#syz dup: exact-subject-of-another-report

If you want to undo deduplication, reply with:
#syz undup

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [syzbot] [kernel?] linux-next test error: UBSAN: array-index-out-of-bounds in alloc_pid
  2023-05-17  7:40 [syzbot] [kernel?] linux-next test error: UBSAN: array-index-out-of-bounds in alloc_pid syzbot
@ 2023-05-17  8:25 ` Christian Brauner
  2023-05-17 15:38   ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Brauner @ 2023-05-17  8:25 UTC (permalink / raw)
  To: syzbot, Kees Cook; +Cc: linux-kernel, linux-next, sfr, syzkaller-bugs

On Wed, May 17, 2023 at 12:40:03AM -0700, syzbot wrote:
> Hello,
> 
> syzbot found the following issue on:
> 
> HEAD commit:    065efa589871 Add linux-next specific files for 20230517
> git tree:       linux-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=17f27bb2280000
> kernel config:  https://syzkaller.appspot.com/x/.config?x=821eeb02ef201bcc
> dashboard link: https://syzkaller.appspot.com/bug?extid=ac3b41786a2d0565b6d5
> compiler:       gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
> 
> Downloadable assets:
> disk image: https://storage.googleapis.com/syzbot-assets/dbbd691e9e5a/disk-065efa58.raw.xz
> vmlinux: https://storage.googleapis.com/syzbot-assets/e5b9541c3979/vmlinux-065efa58.xz
> kernel image: https://storage.googleapis.com/syzbot-assets/44cf3f3aaabb/bzImage-065efa58.xz
> 
> IMPORTANT: if you fix the issue, please add the following tag to the commit:
> Reported-by: syzbot+ac3b41786a2d0565b6d5@syzkaller.appspotmail.com
> 
> ================================================================================
> UBSAN: array-index-out-of-bounds in kernel/pid.c:244:15

Only way I see this happening is if the logic in
kernel/pid_namespace.c:create_pid_cachep() which sets the object size
for the struct pid allocation of this pid namespace based on
parent_pid_namespace->level + 1 is broken. The way this works is:

    struct pid
    {
            [snip]
            struct upid numbers[1];
    };

    create_pid_namespace()
    {
            unsigned int level = parent_pid_ns->level + 1;
            ns->pid_cachep = create_pid_cachep(level);
    }

and then during fork:

    alloc_pid()
    {
            pid = kmem_cache_alloc(ns->pid_cachep, GFP_KERNEL);
    }

So effectively, the wrong level must've been set in
create_pid_namespace() so that the flexible array allocation is too
small.

I don't have time to debug this tbh. Ccing Kees maybe there's some
flexible array stuff going on I'm unaware of.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [syzbot] [kernel?] linux-next test error: UBSAN: array-index-out-of-bounds in alloc_pid
  2023-05-17  8:25 ` Christian Brauner
@ 2023-05-17 15:38   ` Kees Cook
  0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2023-05-17 15:38 UTC (permalink / raw)
  To: Christian Brauner, syzbot, Kees Cook
  Cc: linux-kernel, linux-next, sfr, syzkaller-bugs, linux-hardening

On May 17, 2023 1:25:08 AM PDT, Christian Brauner <brauner@kernel.org> wrote:
>On Wed, May 17, 2023 at 12:40:03AM -0700, syzbot wrote:
>> Hello,
>> 
>> syzbot found the following issue on:
>> 
>> HEAD commit:    065efa589871 Add linux-next specific files for 20230517
>> git tree:       linux-next
>> console output: https://syzkaller.appspot.com/x/log.txt?x=17f27bb2280000
>> kernel config:  https://syzkaller.appspot.com/x/.config?x=821eeb02ef201bcc
>> dashboard link: https://syzkaller.appspot.com/bug?extid=ac3b41786a2d0565b6d5
>> compiler:       gcc (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2
>> 
>> Downloadable assets:
>> disk image: https://storage.googleapis.com/syzbot-assets/dbbd691e9e5a/disk-065efa58.raw.xz
>> vmlinux: https://storage.googleapis.com/syzbot-assets/e5b9541c3979/vmlinux-065efa58.xz
>> kernel image: https://storage.googleapis.com/syzbot-assets/44cf3f3aaabb/bzImage-065efa58.xz
>> 
>> IMPORTANT: if you fix the issue, please add the following tag to the commit:
>> Reported-by: syzbot+ac3b41786a2d0565b6d5@syzkaller.appspotmail.com
>> 
>> ================================================================================
>> UBSAN: array-index-out-of-bounds in kernel/pid.c:244:15
>
>Only way I see this happening is if the logic in
>kernel/pid_namespace.c:create_pid_cachep() which sets the object size
>for the struct pid allocation of this pid namespace based on
>parent_pid_namespace->level + 1 is broken. The way this works is:
>
>    struct pid
>    {
>            [snip]
>            struct upid numbers[1];

I was *just* looking at this fake flex array during LSS last week. It was one of two core structs still using the ancient 1-element style.

>    };
>
>    create_pid_namespace()
>    {
>            unsigned int level = parent_pid_ns->level + 1;
>            ns->pid_cachep = create_pid_cachep(level);
>    }
>
>and then during fork:
>
>    alloc_pid()
>    {
>            pid = kmem_cache_alloc(ns->pid_cachep, GFP_KERNEL);
>    }
>
>So effectively, the wrong level must've been set in
>create_pid_namespace() so that the flexible array allocation is too
>small.
>
>I don't have time to debug this tbh. Ccing Kees maybe there's some
>flexible array stuff going on I'm unaware of.

Yes, I think it's due to:
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=for-next/hardening&id=2d47c6956ab3c8b580a59d7704aab3e2a4882b6c

This makes the sanitizer treat only [0]-arrays as flex arrays.

Though I wonder why Clang hasn't warned about this yet.

Regardless, we'll need to fix struct pid. Since it uses a static initializer for "numbers[0]", this will need a bit of a tweak, but I've got patches for this. I hadn't sent them yet because I was still studying the use of the "levels" member which is off by one for the count of "numbers" elements, which some code already has to work around (using "<=" when iterating and "+ 1" for some outputs)...



-- 
Kees Cook

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-05-17 15:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-17  7:40 [syzbot] [kernel?] linux-next test error: UBSAN: array-index-out-of-bounds in alloc_pid syzbot
2023-05-17  8:25 ` Christian Brauner
2023-05-17 15:38   ` Kees Cook

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.