Skip to content

Commit 9cc3aac

Browse files
committed
ipmi:ipmi_ipmb: Fix null-ptr-deref in ipmi_unregister_smi()
KASAN report null-ptr-deref as follows: KASAN: null-ptr-deref in range [0x0000000000000008-0x000000000000000f] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1ubuntu1.1 04/01/2014 RIP: 0010:ipmi_unregister_smi+0x7d/0xd50 drivers/char/ipmi/ipmi_msghandler.c:3680 Call Trace: ipmi_ipmb_remove+0x138/0x1a0 drivers/char/ipmi/ipmi_ipmb.c:443 ipmi_ipmb_probe+0x409/0xda1 drivers/char/ipmi/ipmi_ipmb.c:548 i2c_device_probe+0x959/0xac0 drivers/i2c/i2c-core-base.c:563 really_probe+0x3f3/0xa70 drivers/base/dd.c:541 In ipmi_ipmb_probe(), 'iidev->intf' is not set before ipmi_register_smi() success. And in the error handling case, ipmi_ipmb_remove() is called to release resources, ipmi_unregister_smi() is called without check 'iidev->intf', this will cause KASAN null-ptr-deref issue. General kernel style is to allow NULL to be passed into unregister calls, so fix it that way. This allows a NULL check to be removed in other code. Fixes: 57c9e3c ("ipmi:ipmi_ipmb: Unregister the SMI on remove") Reported-by: Hulk Robot <[email protected]> Cc: [email protected] # v5.17+ Cc: Wei Yongjun <[email protected]> Signed-off-by: Corey Minyard <[email protected]>
1 parent 3d092ef commit 9cc3aac

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

drivers/char/ipmi/ipmi_msghandler.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3677,8 +3677,11 @@ static void cleanup_smi_msgs(struct ipmi_smi *intf)
36773677
void ipmi_unregister_smi(struct ipmi_smi *intf)
36783678
{
36793679
struct ipmi_smi_watcher *w;
3680-
int intf_num = intf->intf_num, index;
3680+
int intf_num, index;
36813681

3682+
if (!intf)
3683+
return;
3684+
intf_num = intf->intf_num;
36823685
mutex_lock(&ipmi_interfaces_mutex);
36833686
intf->intf_num = -1;
36843687
intf->in_shutdown = true;

drivers/char/ipmi/ipmi_si_intf.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2220,10 +2220,7 @@ static void cleanup_one_si(struct smi_info *smi_info)
22202220
return;
22212221

22222222
list_del(&smi_info->link);
2223-
2224-
if (smi_info->intf)
2225-
ipmi_unregister_smi(smi_info->intf);
2226-
2223+
ipmi_unregister_smi(smi_info->intf);
22272224
kfree(smi_info);
22282225
}
22292226

0 commit comments

Comments
 (0)