linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* general protection fault in ima_free_template_entry
@ 2020-06-04 14:23 syzbot
  2020-06-04 15:09 ` Roberto Sassu
  0 siblings, 1 reply; 2+ messages in thread
From: syzbot @ 2020-06-04 14:23 UTC (permalink / raw)
  To: dmitry.kasatkin, jmorris, linux-integrity, linux-kernel,
	linux-security-module, roberto.sassu, serge, syzkaller-bugs,
	zohar

Hello,

syzbot found the following crash on:

HEAD commit:    e7b08814 Add linux-next specific files for 20200529
git tree:       linux-next
console output: https://syzkaller.appspot.com/x/log.txt?x=12d7b391100000
kernel config:  https://syzkaller.appspot.com/x/.config?x=1e62421a5de6da96
dashboard link: https://syzkaller.appspot.com/bug?extid=223310b454ba6b75974e
compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=108575d2100000
C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=13291661100000

The bug was bisected to:

commit aa724fe18a8a8285d0071c3bfc932efb090d142d
Author: Roberto Sassu <roberto.sassu@huawei.com>
Date:   Wed Mar 25 10:47:09 2020 +0000

    ima: Switch to dynamically allocated buffer for template digests

bisection log:  https://syzkaller.appspot.com/x/bisect.txt?x=1616e896100000
final crash:    https://syzkaller.appspot.com/x/report.txt?x=1516e896100000
console output: https://syzkaller.appspot.com/x/log.txt?x=1116e896100000

IMPORTANT: if you fix the bug, please add the following tag to the commit:
Reported-by: syzbot+223310b454ba6b75974e@syzkaller.appspotmail.com
Fixes: aa724fe18a8a ("ima: Switch to dynamically allocated buffer for template digests")

RBP: 000000000000dcd4 R08: 0000000000000002 R09: 00000000004002c8
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000402160
R13: 00000000004021f0 R14: 0000000000000000 R15: 0000000000000000
general protection fault, probably for non-canonical address 0xdffffc0000000004: 0000 [#1] PREEMPT SMP KASAN
KASAN: null-ptr-deref in range [0x0000000000000020-0x0000000000000027]
CPU: 0 PID: 6811 Comm: syz-executor925 Not tainted 5.7.0-rc7-next-20200529-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
RIP: 0010:ima_free_template_entry+0x4a/0x170 security/integrity/ima/ima_api.c:27
Code: fc ff df 48 c1 ea 03 80 3c 02 00 0f 85 25 01 00 00 48 b8 00 00 00 00 00 fc ff df 48 8b 5d 10 48 8d 7b 20 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e d1 00 00 00 8b 5b 20 31 ff 89
RSP: 0018:ffffc900018e7598 EFLAGS: 00010202
RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 1ffff9200031cece
RDX: 0000000000000004 RSI: ffffffff836d8716 RDI: 0000000000000020
RBP: ffff88809a078d80 R08: 0000000000000000 R09: ffffed1015cc719c
R10: ffff8880ae638cdb R11: ffffed1015cc719b R12: ffffc900018e7670
R13: ffffffff8a06d650 R14: ffff88809a078d90 R15: 00000000fffffff4
FS:  0000000000bc7880(0000) GS:ffff8880ae600000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000000 CR3: 00000000a6570000 CR4: 00000000001406f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 ima_alloc_init_template+0x3de/0x570 security/integrity/ima/ima_api.c:80
 ima_add_violation+0x109/0x1e0 security/integrity/ima/ima_api.c:148
 ima_rdwr_violation_check security/integrity/ima/ima_main.c:140 [inline]
 process_measurement+0x1144/0x1750 security/integrity/ima/ima_main.c:237
 ima_file_check+0xb9/0x100 security/integrity/ima/ima_main.c:491
 do_open fs/namei.c:3236 [inline]
 path_openat+0x17a4/0x27d0 fs/namei.c:3351
 do_filp_open+0x192/0x260 fs/namei.c:3378
 do_sys_openat2+0x585/0x7a0 fs/open.c:1173
 do_sys_open+0xc3/0x140 fs/open.c:1189
 do_syscall_64+0x60/0xe0 arch/x86/entry/common.c:359
 entry_SYSCALL_64_after_hwframe+0x44/0xa9
RIP: 0033:0x441219
Code: e8 5c ae 02 00 48 83 c4 18 c3 0f 1f 80 00 00 00 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 0f 83 bb 0a fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007ffca22cc218 EFLAGS: 00000246 ORIG_RAX: 0000000000000002
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 0000000000441219
RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000020000180
RBP: 000000000000dcd4 R08: 0000000000000002 R09: 00000000004002c8
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000402160
R13: 00000000004021f0 R14: 0000000000000000 R15: 0000000000000000
Modules linked in:
---[ end trace d5e7ae4ed8ee55df ]---
RIP: 0010:ima_free_template_entry+0x4a/0x170 security/integrity/ima/ima_api.c:27
Code: fc ff df 48 c1 ea 03 80 3c 02 00 0f 85 25 01 00 00 48 b8 00 00 00 00 00 fc ff df 48 8b 5d 10 48 8d 7b 20 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03 0f 8e d1 00 00 00 8b 5b 20 31 ff 89
RSP: 0018:ffffc900018e7598 EFLAGS: 00010202
RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 1ffff9200031cece
RDX: 0000000000000004 RSI: ffffffff836d8716 RDI: 0000000000000020
RBP: ffff88809a078d80 R08: 0000000000000000 R09: ffffed1015cc719c
R10: ffff8880ae638cdb R11: ffffed1015cc719b R12: ffffc900018e7670
R13: ffffffff8a06d650 R14: ffff88809a078d90 R15: 00000000fffffff4
FS:  0000000000bc7880(0000) GS:ffff8880ae600000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007f1d9c03f078 CR3: 00000000a6570000 CR4: 00000000001406f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400


---
This bug 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 bug report. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection
syzbot can test patches for this bug, for details see:
https://goo.gl/tpsmEJ#testing-patches

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

* RE: general protection fault in ima_free_template_entry
  2020-06-04 14:23 general protection fault in ima_free_template_entry syzbot
@ 2020-06-04 15:09 ` Roberto Sassu
  0 siblings, 0 replies; 2+ messages in thread
From: Roberto Sassu @ 2020-06-04 15:09 UTC (permalink / raw)
  To: syzbot, dmitry.kasatkin, jmorris, linux-integrity, linux-kernel,
	linux-security-module, serge, syzkaller-bugs, zohar,
	Silviu Vlasceanu

> From: syzbot
> [mailto:syzbot+223310b454ba6b75974e@syzkaller.appspotmail.com]
> Sent: Thursday, June 4, 2020 4:23 PM
> Hello,
> 
> syzbot found the following crash on:
> 
> HEAD commit:    e7b08814 Add linux-next specific files for 20200529
> git tree:       linux-next
> console output: https://syzkaller.appspot.com/x/log.txt?x=12d7b391100000
> kernel config:
> https://syzkaller.appspot.com/x/.config?x=1e62421a5de6da96
> dashboard link:
> https://syzkaller.appspot.com/bug?extid=223310b454ba6b75974e
> compiler:       gcc (GCC) 9.0.0 20181231 (experimental)
> syz repro:      https://syzkaller.appspot.com/x/repro.syz?x=108575d2100000
> C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=13291661100000
> 
> The bug was bisected to:
> 
> commit aa724fe18a8a8285d0071c3bfc932efb090d142d
> Author: Roberto Sassu <roberto.sassu@huawei.com>
> Date:   Wed Mar 25 10:47:09 2020 +0000
> 
>     ima: Switch to dynamically allocated buffer for template digests

I think I found the issue.

        digests = kcalloc(NR_BANKS(ima_tpm_chip) + ima_extra_slots,
                          sizeof(*digests), GFP_NOFS);
        if (!digests) {
                result = -ENOMEM;
                goto out;
        }

        (*entry)->digests = digests;
        (*entry)->template_desc = template_desc;
[...]
out:
        ima_free_template_entry(*entry);

If digest is NULL we are going to ima_free_template_entry() without
initializing (*entry)->template_desc. But we are using it in
ima_free_template_entry():

void ima_free_template_entry(struct ima_template_entry *entry)
{
        int i;

        for (i = 0; i < entry->template_desc->num_fields; i++)
                kfree(entry->template_data[i].data);

Will send a patch shortly.

Roberto

HUAWEI TECHNOLOGIES Duesseldorf GmbH, HRB 56063
Managing Director: Li Peng, Li Jian, Shi Yanli

> bisection log:
> https://syzkaller.appspot.com/x/bisect.txt?x=1616e896100000
> final crash:    https://syzkaller.appspot.com/x/report.txt?x=1516e896100000
> console output: https://syzkaller.appspot.com/x/log.txt?x=1116e896100000
> 
> IMPORTANT: if you fix the bug, please add the following tag to the commit:
> Reported-by: syzbot+223310b454ba6b75974e@syzkaller.appspotmail.com
> Fixes: aa724fe18a8a ("ima: Switch to dynamically allocated buffer for
> template digests")
> 
> RBP: 000000000000dcd4 R08: 0000000000000002 R09: 00000000004002c8
> R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000402160
> R13: 00000000004021f0 R14: 0000000000000000 R15: 0000000000000000
> general protection fault, probably for non-canonical address
> 0xdffffc0000000004: 0000 [#1] PREEMPT SMP KASAN
> KASAN: null-ptr-deref in range [0x0000000000000020-0x0000000000000027]
> CPU: 0 PID: 6811 Comm: syz-executor925 Not tainted 5.7.0-rc7-next-
> 20200529-syzkaller #0
> Hardware name: Google Google Compute Engine/Google Compute Engine,
> BIOS Google 01/01/2011
> RIP: 0010:ima_free_template_entry+0x4a/0x170
> security/integrity/ima/ima_api.c:27
> Code: fc ff df 48 c1 ea 03 80 3c 02 00 0f 85 25 01 00 00 48 b8 00 00 00 00 00 fc ff
> df 48 8b 5d 10 48 8d 7b 20 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03
> 0f 8e d1 00 00 00 8b 5b 20 31 ff 89
> RSP: 0018:ffffc900018e7598 EFLAGS: 00010202
> RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 1ffff9200031cece
> RDX: 0000000000000004 RSI: ffffffff836d8716 RDI: 0000000000000020
> RBP: ffff88809a078d80 R08: 0000000000000000 R09: ffffed1015cc719c
> R10: ffff8880ae638cdb R11: ffffed1015cc719b R12: ffffc900018e7670
> R13: ffffffff8a06d650 R14: ffff88809a078d90 R15: 00000000fffffff4
> FS:  0000000000bc7880(0000) GS:ffff8880ae600000(0000)
> knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 0000000000000000 CR3: 00000000a6570000 CR4: 00000000001406f0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> Call Trace:
>  ima_alloc_init_template+0x3de/0x570 security/integrity/ima/ima_api.c:80
>  ima_add_violation+0x109/0x1e0 security/integrity/ima/ima_api.c:148
>  ima_rdwr_violation_check security/integrity/ima/ima_main.c:140 [inline]
>  process_measurement+0x1144/0x1750
> security/integrity/ima/ima_main.c:237
>  ima_file_check+0xb9/0x100 security/integrity/ima/ima_main.c:491
>  do_open fs/namei.c:3236 [inline]
>  path_openat+0x17a4/0x27d0 fs/namei.c:3351
>  do_filp_open+0x192/0x260 fs/namei.c:3378
>  do_sys_openat2+0x585/0x7a0 fs/open.c:1173
>  do_sys_open+0xc3/0x140 fs/open.c:1189
>  do_syscall_64+0x60/0xe0 arch/x86/entry/common.c:359
>  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> RIP: 0033:0x441219
> Code: e8 5c ae 02 00 48 83 c4 18 c3 0f 1f 80 00 00 00 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 0f 83 bb 0a
> fc ff c3 66 2e 0f 1f 84 00 00 00 00
> RSP: 002b:00007ffca22cc218 EFLAGS: 00000246 ORIG_RAX:
> 0000000000000002
> RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 0000000000441219
> RDX: 0000000000000000 RSI: 0000000000000000 RDI: 0000000020000180
> RBP: 000000000000dcd4 R08: 0000000000000002 R09: 00000000004002c8
> R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000402160
> R13: 00000000004021f0 R14: 0000000000000000 R15: 0000000000000000
> Modules linked in:
> ---[ end trace d5e7ae4ed8ee55df ]---
> RIP: 0010:ima_free_template_entry+0x4a/0x170
> security/integrity/ima/ima_api.c:27
> Code: fc ff df 48 c1 ea 03 80 3c 02 00 0f 85 25 01 00 00 48 b8 00 00 00 00 00 fc ff
> df 48 8b 5d 10 48 8d 7b 20 48 89 fa 48 c1 ea 03 <0f> b6 04 02 84 c0 74 08 3c 03
> 0f 8e d1 00 00 00 8b 5b 20 31 ff 89
> RSP: 0018:ffffc900018e7598 EFLAGS: 00010202
> RAX: dffffc0000000000 RBX: 0000000000000000 RCX: 1ffff9200031cece
> RDX: 0000000000000004 RSI: ffffffff836d8716 RDI: 0000000000000020
> RBP: ffff88809a078d80 R08: 0000000000000000 R09: ffffed1015cc719c
> R10: ffff8880ae638cdb R11: ffffed1015cc719b R12: ffffc900018e7670
> R13: ffffffff8a06d650 R14: ffff88809a078d90 R15: 00000000fffffff4
> FS:  0000000000bc7880(0000) GS:ffff8880ae600000(0000)
> knlGS:0000000000000000
> CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
> CR2: 00007f1d9c03f078 CR3: 00000000a6570000 CR4: 00000000001406f0
> DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
> DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
> 
> 
> ---
> This bug 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 bug report. See:
> https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
> For information about bisection process see:
> https://goo.gl/tpsmEJ#bisection
> syzbot can test patches for this bug, for details see:
> https://goo.gl/tpsmEJ#testing-patches

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

end of thread, other threads:[~2020-06-04 15:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-04 14:23 general protection fault in ima_free_template_entry syzbot
2020-06-04 15:09 ` Roberto Sassu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).