general protection fault in tomoyo_gc_thread
Subsystems (2)
syzbot
syzbotHello,
syzbot found the following issue on:
HEAD commit: f92f4749861b Merge tag 'clk-fixes-for-linus' of git://git... git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=12fa2cdf980000 kernel config: https://syzkaller.appspot.com/x/.config?x=99a5586995ec03b2 dashboard link: https://syzkaller.appspot.com/bug?extid=bf6351831bc4f9148d98 compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40 syz repro: https://syzkaller.appspot.com/x/repro.syz?x=12fc78f8580000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/b85403132ddc/disk-f92f4749.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/20613d034287/vmlinux-f92f4749.xz
kernel image: https://storage.googleapis.com/syzbot-assets/d1ea80bf7e4e/bzImage-f92f4749.xz
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Oops: general protection fault, probably for non-canonical address 0xdffffc0000000000: 0000 [#1] PREEMPT SMP KASAN PTI KASAN: null-ptr-deref in range [0x0000000000000000-0x0000000000000007] CPU: 0 UID: 0 PID: 6044 Comm: GC for TOMOYO Not tainted 6.13.0-rc2-syzkaller-00031-gf92f4749861b #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 09/13/2024 RIP: 0010:tomoyo_collect_acl security/tomoyo/gc.c:511 [inline] RIP: 0010:tomoyo_collect_entry security/tomoyo/gc.c:537 [inline] RIP: 0010:tomoyo_gc_thread security/tomoyo/gc.c:619 [inline] RIP: 0010:tomoyo_gc_thread+0x1ab/0x1390 security/tomoyo/gc.c:612 Code: 3b 5c 47 fd c6 45 18 ff 4c 89 ee bf 09 00 00 00 e8 8a f1 ff ff e8 25 5c 47 fd 48 89 d8 48 89 de 49 89 dd 48 c1 e8 03 83 e6 07 <42> 0f b6 0c 20 48 8d 43 07 48 89 c2 48 c1 ea 03 42 0f b6 14 22 40 RSP: 0018:ffffc90003367e78 EFLAGS: 00010246 RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff8451e1ab RDX: ffff888074e85a00 RSI: 0000000000000000 RDI: 0000000000000001 RBP: ffff888143b02f00 R08: 0000000000000001 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000b8f R12: dffffc0000000000 R13: 0000000000000000 R14: 0000000000000000 R15: ffff888025b49b00 FS: 0000000000000000(0000) GS:ffff8880b8600000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000008 CR3: 0000000028642000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> kthread+0x2c1/0x3a0 kernel/kthread.c:389 ret_from_fork+0x45/0x80 arch/x86/kernel/process.c:147 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:244 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:tomoyo_collect_acl security/tomoyo/gc.c:511 [inline] RIP: 0010:tomoyo_collect_entry security/tomoyo/gc.c:537 [inline] RIP: 0010:tomoyo_gc_thread security/tomoyo/gc.c:619 [inline] RIP: 0010:tomoyo_gc_thread+0x1ab/0x1390 security/tomoyo/gc.c:612 Code: 3b 5c 47 fd c6 45 18 ff 4c 89 ee bf 09 00 00 00 e8 8a f1 ff ff e8 25 5c 47 fd 48 89 d8 48 89 de 49 89 dd 48 c1 e8 03 83 e6 07 <42> 0f b6 0c 20 48 8d 43 07 48 89 c2 48 c1 ea 03 42 0f b6 14 22 40 RSP: 0018:ffffc90003367e78 EFLAGS: 00010246 RAX: 0000000000000000 RBX: 0000000000000000 RCX: ffffffff8451e1ab RDX: ffff888074e85a00 RSI: 0000000000000000 RDI: 0000000000000001 RBP: ffff888143b02f00 R08: 0000000000000001 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000b8f R12: dffffc0000000000 R13: 0000000000000000 R14: 0000000000000000 R15: ffff888025b49b00 FS: 0000000000000000(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055b9c4865950 CR3: 0000000029aee000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 ---------------- Code disassembly (best guess): 0: 3b 5c 47 fd cmp -0x3(%rdi,%rax,2),%ebx 4: c6 45 18 ff movb $0xff,0x18(%rbp) 8: 4c 89 ee mov %r13,%rsi b: bf 09 00 00 00 mov $0x9,%edi 10: e8 8a f1 ff ff call 0xfffff19f 15: e8 25 5c 47 fd call 0xfd475c3f 1a: 48 89 d8 mov %rbx,%rax 1d: 48 89 de mov %rbx,%rsi 20: 49 89 dd mov %rbx,%r13 23: 48 c1 e8 03 shr $0x3,%rax 27: 83 e6 07 and $0x7,%esi * 2a: 42 0f b6 0c 20 movzbl (%rax,%r12,1),%ecx <-- trapping instruction 2f: 48 8d 43 07 lea 0x7(%rbx),%rax 33: 48 89 c2 mov %rax,%rdx 36: 48 c1 ea 03 shr $0x3,%rdx 3a: 42 0f b6 14 22 movzbl (%rdx,%r12,1),%edx 3f: 40 rex
---
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 [email protected].
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
Tetsuo Handa
maintainertomoyo_try_to_gc() is called only when the ->is_deleted flag is set. The ->is_deleted flag is set when a line in
delete $a_line_to_delete
format is written via the /sys/kernel/security/tomoyo/ interface. But since I can't find the "delete " string within the syz reproducer, tomoyo_try_to_gc() should not be called in the first place.
The syz reproducer is repeatedly opening /sys/kernel/security/tomoyo/manager which in turn repeatedly triggers the gc thread. But unless the ->is_deleted flag is set, gc has nothing to remove from the lists, and list corruption cannot happen because list manipulation is serialized by tomoyo_policy_lock mutex.
Therefore, currently I can't imagine that this report and "general protection fault in tomoyo_check_acl (4)" and "BUG: corrupted list in tomoyo_try_to_gc" are TOMOYO's bug; these look like a collateral victim caused by memory corruption in somewhere else.
Anyway, let's try with lockdep annotation added.
#syz test
security/tomoyo/common.c +1 -0
@@ -348,6 +348,7 @@ void tomoyo_init_policy_namespace(struct tomoyo_policy_namespace *ns)INIT_LIST_HEAD (&ns->policy_list[idx]); ns->profile_version =20150505 ; tomoyo_namespace_enabled = !list_empty (&tomoyo_namespace_list); +lockdep_assert_held (&tomoyo_policy_lock);list_add_tail_rcu (&ns->namespace_list, &tomoyo_namespace_list); }
security/tomoyo/condition.c +1 -0
@@ -427,6 +427,7 @@ static struct tomoyo_condition *tomoyo_commit_conditionif (!found) {if (tomoyo_memory_ok (entry)) {atomic_set (&entry->head.users,1 ); +lockdep_assert_held (&tomoyo_policy_lock);list_add (&entry->head.list, &tomoyo_condition_list); }else { found = true;
security/tomoyo/domain.c +3 -0
@@ -54,6 +54,7 @@ int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,if (error && !param->is_delete) { entry =tomoyo_commit_ok (new_entry, size);if (entry) { +lockdep_assert_held (&tomoyo_policy_lock);list_add_tail_rcu (&entry->list, list); error =0 ; }
@@ -138,6 +139,7 @@ int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,if (error && !is_delete) { entry =tomoyo_commit_ok (new_entry, size);if (entry) { +lockdep_assert_held (&tomoyo_policy_lock);list_add_tail_rcu (&entry->list, list); error =0 ; }
@@ -576,6 +578,7 @@ struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname, entry =tomoyo_commit_ok (&e,sizeof (e));if (entry) {INIT_LIST_HEAD (&entry->acl_info_list); +lockdep_assert_held (&tomoyo_policy_lock);list_add_tail_rcu (&entry->list, &tomoyo_domain_list); created = true; }
security/tomoyo/gc.c +8 -1
@@ -29,6 +29,8 @@ static LIST_HEAD(tomoyo_io_buffer_list);/* Lock for protecting tomoyo_io_buffer_list. */ static DEFINE_SPINLOCK (tomoyo_io_buffer_list_lock); +static DEFINE_MUTEX (tomoyo_gc_mutex); +/** * tomoyo_struct_used_by_io_buffer - Check whether the list element is used by /sys/kernel/security/tomoyo/ users or not. *
@@ -392,8 +394,11 @@ static void tomoyo_try_to_gc(const enum tomoyo_policy_id type,* tomoyo_domain_list). Also, synchronize_srcu() guarantees that the * list element became no longer referenced by syscall users. */ +struct list_head *head = element->prev; +__list_del_entry (element);mutex_unlock (&tomoyo_policy_lock); +lockdep_assert_held (&tomoyo_gc_mutex);synchronize_srcu (&tomoyo_ss);/* * However, there are two users which may still be using the list
@@ -470,7 +475,10 @@ static void tomoyo_try_to_gc(const enum tomoyo_policy_id type,* exclusively executed by tomoyo_gc_mutex mutex. * are true. */ +lockdep_assert_held (&tomoyo_gc_mutex);mutex_lock (&tomoyo_policy_lock); +printk ("Reinjecting list=%px type=%d\n" , element, type); +BUG_ON (element->prev != head);list_add_rcu (element, element->prev); }
@@ -612,7 +620,6 @@ static void tomoyo_collect_entry(void)static int tomoyo_gc_thread (void *unused) {/* Garbage collector thread is exclusive. */ -static DEFINE_MUTEX (tomoyo_gc_mutex);if (!mutex_trylock (&tomoyo_gc_mutex)) goto out;
security/tomoyo/memory.c +4 -0
@@ -123,6 +123,7 @@ struct tomoyo_group *tomoyo_get_group(struct tomoyo_acl_param *param,if (entry) {INIT_LIST_HEAD (&entry->member_list);atomic_set (&entry->head.users,1 ); +lockdep_assert_held (&tomoyo_policy_lock);list_add_tail_rcu (&entry->head.list, list); group = entry; found = true;
@@ -176,6 +177,7 @@ const struct tomoyo_path_info *tomoyo_get_name(const char *name)memmove ((char *) ptr->entry.name, name, len);atomic_set (&ptr->head.users,1 );tomoyo_fill_path_info (&ptr->entry); +lockdep_assert_held (&tomoyo_policy_lock);list_add_tail (&ptr->head.list, head); }else {kfree (ptr);
@@ -199,7 +201,9 @@ void __init tomoyo_mm_init(void)for (idx =0 ; idx <TOMOYO_MAX_HASH ; idx++)INIT_LIST_HEAD (&tomoyo_name_list[idx]); tomoyo_kernel_namespace.name ="<kernel>" ; +mutex_lock (&tomoyo_policy_lock);tomoyo_init_policy_namespace (&tomoyo_kernel_namespace); +mutex_unlock (&tomoyo_policy_lock); tomoyo_kernel_domain.ns = &tomoyo_kernel_namespace;INIT_LIST_HEAD (&tomoyo_kernel_domain.acl_info_list); tomoyo_kernel_domain.domainname =tomoyo_get_name ("<kernel>" );
syzbot
syzbotsyzbot has tested the proposed patch but the reproducer is still triggering an issue:
Hello,
syzbot has tested the proposed patch but the reproducer is still triggering an issue:
general protection fault in tomoyo_init_request_info Oops: general protection fault, probably for non-canonical address 0xdffffc000000000a: 0000 [#1] PREEMPT SMP KASAN PTI KASAN: null-ptr-deref in range [0x0000000000000050-0x0000000000000057] CPU: 1 UID: 0 PID: 6698 Comm: syz.2.57 Not tainted 6.13.0-rc3-syzkaller-g8faabc041a00-dirty #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 11/25/2024 RIP: 0010:tomoyo_init_request_info+0x6f/0x370 security/tomoyo/util.c:1028 Code: 48 89 fa 48 c1 ea 03 80 3c 02 00 0f 85 98 02 00 00 48 8d 7d 50 48 89 6b 10 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 06 0f 8e 5d 02 00 00 48 8d 7b 4b 44 0f b6 6d RSP: 0018:ffffc90003eef790 EFLAGS: 00010206 RAX: dffffc0000000000 RBX: ffffc90003eef808 RCX: 0000000000000000 RDX: 000000000000000a RSI: ffffffff8452e107 RDI: 0000000000000050 RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000000 R10: ffffc90003eef808 R11: 0000000000000000 R12: 0000000000000001 R13: 0000000000048000 R14: ffff8880760cf040 R15: 0000000000000004 FS: 00007f79ac9fe6c0(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000008 CR3: 000000001dea8000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: <TASK> tomoyo_check_open_permission+0x27a/0x3c0 security/tomoyo/file.c:769 tomoyo_file_open+0x6b/0x90 security/tomoyo/tomoyo.c:334 security_file_open+0x84/0x1e0 security/security.c:3105 do_dentry_open+0x57e/0x1ea0 fs/open.c:928 vfs_open+0x82/0x3f0 fs/open.c:1075 do_open fs/namei.c:3828 [inline] path_openat+0x1e6a/0x2d60 fs/namei.c:3987 do_filp_open+0x20c/0x470 fs/namei.c:4014 do_sys_openat2+0x17a/0x1e0 fs/open.c:1402 do_sys_open fs/open.c:1417 [inline] __do_sys_openat fs/open.c:1433 [inline] __se_sys_openat fs/open.c:1428 [inline] __x64_sys_openat+0x175/0x210 fs/open.c:1428 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xcd/0x250 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f79ad785d19 Code: ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 40 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 a8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f79ac9fe038 EFLAGS: 00000246 ORIG_RAX: 0000000000000101 RAX: ffffffffffffffda RBX: 00007f79ad975fa0 RCX: 00007f79ad785d19 RDX: 0000000000040000 RSI: 0000000020000040 RDI: ffffffffffffff9c RBP: 00007f79ad801a20 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 0000000000000000 R14: 00007f79ad975fa0 R15: 00007ffe8d39dad8 </TASK> Modules linked in: ---[ end trace 0000000000000000 ]--- RIP: 0010:tomoyo_init_request_info+0x6f/0x370 security/tomoyo/util.c:1028 Code: 48 89 fa 48 c1 ea 03 80 3c 02 00 0f 85 98 02 00 00 48 8d 7d 50 48 89 6b 10 48 b8 00 00 00 00 00 fc ff df 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 06 0f 8e 5d 02 00 00 48 8d 7b 4b 44 0f b6 6d RSP: 0018:ffffc90003eef790 EFLAGS: 00010206 RAX: dffffc0000000000 RBX: ffffc90003eef808 RCX: 0000000000000000 RDX: 000000000000000a RSI: ffffffff8452e107 RDI: 0000000000000050 RBP: 0000000000000000 R08: 0000000000000001 R09: 0000000000000000 R10: ffffc90003eef808 R11: 0000000000000000 R12: 0000000000000001 R13: 0000000000048000 R14: ffff8880760cf040 R15: 0000000000000004 FS: 00007f79ac9fe6c0(0000) GS:ffff8880b8700000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000000c006f48000 CR3: 000000001dea8000 CR4: 00000000003526f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 ---------------- Code disassembly (best guess): 0: 48 89 fa mov %rdi,%rdx 3: 48 c1 ea 03 shr $0x3,%rdx 7: 80 3c 02 00 cmpb $0x0,(%rdx,%rax,1) b: 0f 85 98 02 00 00 jne 0x2a9 11: 48 8d 7d 50 lea 0x50(%rbp),%rdi 15: 48 89 6b 10 mov %rbp,0x10(%rbx) 19: 48 b8 00 00 00 00 00 movabs $0xdffffc0000000000,%rax 20: fc ff df 23: 48 89 fa mov %rdi,%rdx 26: 48 c1 ea 03 shr $0x3,%rdx * 2a: 0f b6 04 02 movzbl (%rdx,%rax,1),%eax <-- trapping instruction 2e: 84 c0 test %al,%al 30: 74 06 je 0x38 32: 0f 8e 5d 02 00 00 jle 0x295 38: 48 8d 7b 4b lea 0x4b(%rbx),%rdi 3c: 44 rex.R 3d: 0f .byte 0xf 3e: b6 6d mov $0x6d,%dh
Tested on:
commit: 8faabc04 Merge tag 'net-6.13-rc4' of git://git.kernel... git tree: upstream console output: https://syzkaller.appspot.com/x/log.txt?x=13f200c4580000 kernel config: https://syzkaller.appspot.com/x/.config?x=c22efbd20f8da769 dashboard link: https://syzkaller.appspot.com/bug?extid=bf6351831bc4f9148d98 compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40 patch: https://syzkaller.appspot.com/x/patch.diff?x=170dcf30580000
Tetsuo Handa
maintainer#syz dup: general protection fault in account_kernel_stack (3)