Skip to content

Commit

Permalink
cxl: fix potential NULL dereference in free_adapter()
Browse files Browse the repository at this point in the history
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: 14baf4d ("cxl: Add guest-specific code")
Reported-by: Dan Carpenter <[email protected]>
Signed-off-by: Andrew Donnellan <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
  • Loading branch information
ajdlinux authored and mpe committed Jul 19, 2016
1 parent 1e44727 commit 8fbaa51
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions drivers/misc/cxl/guest.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,16 +1055,18 @@ static void free_adapter(struct cxl *adapter)
struct irq_avail *cur;
int i;

if (adapter->guest->irq_avail) {
for (i = 0; i < adapter->guest->irq_nranges; i++) {
cur = &adapter->guest->irq_avail[i];
kfree(cur->bitmap);
if (adapter->guest) {
if (adapter->guest->irq_avail) {
for (i = 0; i < adapter->guest->irq_nranges; i++) {
cur = &adapter->guest->irq_avail[i];
kfree(cur->bitmap);
}
kfree(adapter->guest->irq_avail);
}
kfree(adapter->guest->irq_avail);
kfree(adapter->guest->status);
kfree(adapter->guest);
}
kfree(adapter->guest->status);
cxl_remove_adapter_nr(adapter);
kfree(adapter->guest);
kfree(adapter);
}

Expand Down

0 comments on commit 8fbaa51

Please sign in to comment.