Skip to contentSkip to conversation

scsi/megaraid: Prevent kernel-infoleak in kioc_to_mimd()

PATCH In review Peilin Ye 2 participants 4 messages Jul 27, 2020 – Jul 28, 2020

Subsystems (2)
lore
Share & tools
lore

Peilin Ye

author
#0 lore raw

PATCH 1/1 scsi/megaraid: Prevent kernel-infoleak in kioc_to_mimd()

hinfo_to_cinfo() does no operation on cinfo when hinfo is NULL, causing kioc_to_mimd() to copy uninitialized stack memory to userspace. Fix it by initializing cinfo with memset().

Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")
---
 drivers/scsi/megaraid/megaraid_mm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/scsi/megaraid/megaraid_mm.c +2 -0
index 8df53446641a..9df0e6b253a8 100644
@@ -816,6 +816,8 @@ kioc_to_mimd(uioc_t *kioc, mimd_t __user *mimd)
 
 		case MEGAIOC_QADAPINFO:
 
+			memset(&cinfo, 0, sizeof(cinfo));
+
 			hinfo = (mraid_hba_info_t *)(unsigned long)
 					kioc->buf_vaddr;
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 3 lines · Peilin Ye

hinfo_to_cinfo() does no operation on cinfo when hinfo is NULL, causing kioc_to_mimd() to copy uninitialized stack memory to userspace. Fix it by initializing cinfo with memset().

But "hinfo" can't be NULL so this patch isn't required. It's a bit hard for Smatch to follow the code.

We know that "opcode" is 82 so the buffer is allocated by mimd_to_kioc() -> mraid_mm_attach_buf().

Generally, don't silence static checker warnings unless it makes the code more readable. It's the checker writer's job to fix their own code. In this case, that's me, but parsing the code is quite complicated and I don't have a plan for how to fix it.

regards,
dan carpenter

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#2 lore raw
Quoted 4 lines · Dan Carpenter

Generally, don't silence static checker warnings unless it makes the code more readable. It's the checker writer's job to fix their own code. In this case, that's me, but parsing the code is quite complicated and I don't have a plan for how to fix it.

Actually, looking at this some more, it's not so complicated. By this time next year hopefully this warning will be silenced.

regards,
dan carpenter

author
#3 lore raw
In reply to Dan Carpenter
Quoted 10 lines · Dan Carpenter
Quoted 3 lines · Peilin Ye

hinfo_to_cinfo() does no operation on cinfo when hinfo is NULL, causing kioc_to_mimd() to copy uninitialized stack memory to userspace. Fix it by initializing cinfo with memset().

But "hinfo" can't be NULL so this patch isn't required. It's a bit hard for Smatch to follow the code.

We know that "opcode" is 82 so the buffer is allocated by mimd_to_kioc() -> mraid_mm_attach_buf().

You are right. mraid_mm_ioctl() returns -ENOMEM and never reaches kioc_to_mimd() if mraid_mm_attach_buf() failed to get a buffer, so hinfo can never be NULL for kioc_to_mimd().

Next time I will trace the data flow more carefully. Thank you for pointing this out!

Peilin Ye

Quoted 8 lines

Generally, don't silence static checker warnings unless it makes the code more readable. It's the checker writer's job to fix their own code. In this case, that's me, but parsing the code is quite complicated and I don't have a plan for how to fix it.

regards,
dan carpenter

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees