Commit b3c5b399 authored by Andrew Donnellan's avatar Andrew Donnellan Committed by Greg Kroah-Hartman

cxl: fix potential NULL dereference in free_adapter()

commit 8fbaa51d upstream.

If kzalloc() fails when allocating adapter->guest in
cxl_guest_init_adapter(), we call free_adapter() before erroring out.
free_adapter() in turn attempts to dereference adapter->guest, which in
this case is NULL.

In free_adapter(), skip the adapter->guest cleanup if adapter->guest is
NULL.

Fixes: 14baf4d9 ("cxl: Add guest-specific code")
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarAndrew Donnellan <andrew.donnellan@au1.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent b7d9885f
......@@ -1052,6 +1052,7 @@ static void free_adapter(struct cxl *adapter)
struct irq_avail *cur;
int i;
if (adapter->guest) {
if (adapter->guest->irq_avail) {
for (i = 0; i < adapter->guest->irq_nranges; i++) {
cur = &adapter->guest->irq_avail[i];
......@@ -1060,8 +1061,9 @@ static void free_adapter(struct cxl *adapter)
kfree(adapter->guest->irq_avail);
}
kfree(adapter->guest->status);
cxl_remove_adapter_nr(adapter);
kfree(adapter->guest);
}
cxl_remove_adapter_nr(adapter);
kfree(adapter);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment