[syzbot] KASAN: use-after-free Read in cipso_v4_doi_add

Started by syzbot on Oct 19, 2021 · 3 messages from 3 authors · Last reply Oct 22, 2021

open the first message on its own page

  1. [PATCH] smackfs: use netlbl_cfg_cipsov4_del() for deleting cipso_v4_doi
    Related patches
Message details and related content
Hello,

syzbot found the following issue on:

HEAD commit:    26d657410983 MAINTAINERS: Update entry for the Stratix10 f..
git tree:       upstream
console output: https://syzkaller.appspot.com/x/log.txt?x=110cb258b00000
kernel config:  https://syzkaller.appspot.com/x/.config?x=1de5da8af5c2277d
dashboard link: https://syzkaller.appspot.com/bug?extid=93dba5b91f0fed312cbd
compiler:       Debian clang version 11.0.1-2, GNU ld (GNU Binutils for Debian) 2.35.2

Unfortunately, I don't have any reproducer for this issue yet.

IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: <redacted>

==================================================================
BUG: KASAN: use-after-free in cipso_v4_doi_search net/ipv4/cipso_ipv4.c:363 [inline]
BUG: KASAN: use-after-free in cipso_v4_doi_add+0x4e0/0x7c0 net/ipv4/cipso_ipv4.c:420
Read of size 4 at addr ffff88803f6a5a00 by task syz-executor.3/14359

CPU: 1 PID: 14359 Comm: syz-executor.3 Not tainted 5.15.0-rc5-syzkaller #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:88 [inline]
 dump_stack_lvl+0x1dc/0x2d8 lib/dump_stack.c:106
 print_address_description+0x66/0x3e0 mm/kasan/report.c:256
 __kasan_report mm/kasan/report.c:442 [inline]
 kasan_report+0x19a/0x1f0 mm/kasan/report.c:459
 cipso_v4_doi_search net/ipv4/cipso_ipv4.c:363 [inline]
 cipso_v4_doi_add+0x4e0/0x7c0 net/ipv4/cipso_ipv4.c:420
 smk_cipso_doi+0x2d3/0x580 security/smack/smackfs.c:706
 smk_write_doi+0x1ab/0x270 security/smack/smackfs.c:1615
 vfs_write+0x327/0xe90 fs/read_write.c:592
 ksys_write+0x18f/0x2c0 fs/read_write.c:647
 do_syscall_x64 arch/x86/entry/common.c:50 [inline]
 do_syscall_64+0x44/0xd0 arch/x86/entry/common.c:80
 entry_SYSCALL_64_after_hwframe+0x44/0xae
RIP: 0033:0x7f31447cba39
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 bc ff ff ff f7 d8 64 89 01 48

105 more lines

ffff88803f6a5a00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
                   ^
 ffff88803f6a5a80: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
 ffff88803f6a5b00: fa fb fb fb fb fb fb fb fc fc fc fc fc fc fc fc
==================================================================


---
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.

[PATCH] smackfs: use netlbl_cfg_cipsov4_del() for deleting cipso_v4_doi

Message details and related content
syzbot is reporting UAF at cipso_v4_doi_search() [1], for smk_cipso_doi()
is calling kfree() without removing from the cipso_v4_doi_list list after
netlbl_cfg_cipsov4_map_add() returned an error. We need to use
netlbl_cfg_cipsov4_del() in order to remove from the list and wait for
RCU grace period before kfree().

Link: https://syzkaller.appspot.com/bug?extid=93dba5b91f0fed312cbd [1]
Reported-by: syzbot <redacted>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Fixes: 6c2e8ac0953fccdd ("netlabel: Update kernel configuration API")
---
 security/smack/smackfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 3a75d2a8f517..83b90442f963 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -714,7 +714,7 @@ static void smk_cipso_doi(void)
 	if (rc != 0) {
 		printk(KERN_WARNING "%s:%d map add rc = %d\n",
 		       __func__, __LINE__, rc);
-		kfree(doip);
+		netlbl_cfg_cipsov4_del(doip->doi, &nai);
 		return;
 	}
 }
-- 
2.18.4

Re: [PATCH] smackfs: use netlbl_cfg_cipsov4_del() for deleting cipso_v4_doi

Message details and related content
On 10/19/2021 4:27 AM, Tetsuo Handa wrote:
syzbot is reporting UAF at cipso_v4_doi_search() [1], for smk_cipso_doi()
is calling kfree() without removing from the cipso_v4_doi_list list after
netlbl_cfg_cipsov4_map_add() returned an error. We need to use
netlbl_cfg_cipsov4_del() in order to remove from the list and wait for
RCU grace period before kfree().

Link: https://syzkaller.appspot.com/bug?extid=93dba5b91f0fed312cbd [1]
Reported-by: syzbot <redacted>
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Fixes: 6c2e8ac0953fccdd ("netlabel: Update kernel configuration API")
Added to smack-next. Thank you.
quoted hunk
---
  security/smack/smackfs.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 3a75d2a8f517..83b90442f963 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -714,7 +714,7 @@ static void smk_cipso_doi(void)
  	if (rc != 0) {
  		printk(KERN_WARNING "%s:%d map add rc = %d\n",
  		       __func__, __LINE__, rc);
-		kfree(doip);
+		netlbl_cfg_cipsov4_del(doip->doi, &nai);
  		return;
  	}
  }
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help