Skip to content

Commit 1b47fd4

Browse files
Colin Ian Kingbjorn-helgaas
authored andcommitted
PCI: acpiphp_ibm: Fix null dereferences on null ibm_slot
ibm_slot_from_id() can return null if the des header signature is not "aPCI" or if the kmalloc() for the return ACPI descriptor fails, causing potential null pointer dereferences on the return null descriptor. Handle the null case with appropriate check and error return. Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
1 parent 64609ea commit 1b47fd4

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎drivers/pci/hotplug/acpiphp_ibm.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ static union apci_descriptor *ibm_slot_from_id(int id)
154154
ibm_slot_done:
155155
if (ret) {
156156
ret = kmalloc(sizeof(union apci_descriptor), GFP_KERNEL);
157-
memcpy(ret, des, sizeof(union apci_descriptor));
157+
if (ret)
158+
memcpy(ret, des, sizeof(union apci_descriptor));
158159
}
159160
kfree(table);
160161
return ret;
@@ -175,8 +176,13 @@ static int ibm_set_attention_status(struct hotplug_slot *slot, u8 status)
175176
acpi_status stat;
176177
unsigned long long rc;
177178
union apci_descriptor *ibm_slot;
179+
int id = hpslot_to_sun(slot);
178180

179-
ibm_slot = ibm_slot_from_id(hpslot_to_sun(slot));
181+
ibm_slot = ibm_slot_from_id(id);
182+
if (!ibm_slot) {
183+
pr_err("APLS null ACPI descriptor for slot %d\n", id);
184+
return -ENODEV;
185+
}
180186

181187
pr_debug("%s: set slot %d (%d) attention status to %d\n", __func__,
182188
ibm_slot->slot.slot_num, ibm_slot->slot.slot_id,
@@ -215,8 +221,13 @@ static int ibm_set_attention_status(struct hotplug_slot *slot, u8 status)
215221
static int ibm_get_attention_status(struct hotplug_slot *slot, u8 *status)
216222
{
217223
union apci_descriptor *ibm_slot;
224+
int id = hpslot_to_sun(slot);
218225

219-
ibm_slot = ibm_slot_from_id(hpslot_to_sun(slot));
226+
ibm_slot = ibm_slot_from_id(id);
227+
if (!ibm_slot) {
228+
pr_err("APLS null ACPI descriptor for slot %d\n", id);
229+
return -ENODEV;
230+
}
220231

221232
if (ibm_slot->slot.attn & 0xa0 || ibm_slot->slot.status[1] & 0x08)
222233
*status = 1;

0 commit comments

Comments
 (0)