Skip to content

ASoC: SOF: Fix NULL pointer exception in sof_pci_probe callback#3606

Merged
plbossart merged 1 commit intothesofproject:topic/sof-devfrom
ajitkupandey:fix_null
Apr 25, 2022
Merged

ASoC: SOF: Fix NULL pointer exception in sof_pci_probe callback#3606
plbossart merged 1 commit intothesofproject:topic/sof-devfrom
ajitkupandey:fix_null

Conversation

@ajitkupandey
Copy link

We are accessing "desc->ops" in sof_pci_probe without checking "desc"
pointer. This results in NULL pointer exception if pci_id->driver_data
i.e desc pointer isn't defined in sof device probe:

BUG: kernel NULL pointer dereference, address: 0000000000000060
PGD 0 P4D 0
Oops: 0000 [#1] PREEMPT SMP NOPTI
RIP: 0010:sof_pci_probe+0x1e/0x17f [snd_sof_pci]
Code: Unable to access opcode bytes at RIP 0xffffffffc043dff4.
RSP: 0018:ffffac4b03b9b8d8 EFLAGS: 00010246

Add NULL pointer check for sof_dev_desc pointer to avoid such exception.

Signed-off-by: Ajit Kumar Pandey AjitKumar.Pandey@amd.com

We are accessing "desc->ops" in sof_pci_probe without checking "desc"
pointer. This results in NULL pointer exception if pci_id->driver_data
i.e desc pointer isn't defined in sof device probe:

BUG: kernel NULL pointer dereference, address: 0000000000000060
PGD 0 P4D 0
Oops: 0000 [#1] PREEMPT SMP NOPTI
RIP: 0010:sof_pci_probe+0x1e/0x17f [snd_sof_pci]
Code: Unable to access opcode bytes at RIP 0xffffffffc043dff4.
RSP: 0018:ffffac4b03b9b8d8 EFLAGS: 00010246

Add NULL pointer check for sof_dev_desc pointer to avoid such exception.

Signed-off-by: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
dev_err(dev, "error: no matching PCI descriptor\n");
return -ENODEV;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ajitkupandey this can only happen if you add a PCI_DEVICE without the matching .driver_data set, right? That's typically only in developer workspaces, and even then that's pretty bad, isn't it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this happens only when .driver_data isn't set in pci driver. Actually i ended up in this exception once due to missing driver data so thought to fix this one. I agree that's pretty bad and part of developer workspace only but I guess avoiding exceptions in core code is always good.
If this double NULL check looks weird here may be fixup like adding a "pci_id->driver_data" NULL check in sof pci device probe like "hda_pci_intel_probe" before invoking sof_pci_probe can be done to avoid such exceptions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to do it here, just that you should add in the commit message that this is a paranoia check for something that should not happen for an actual released product.

@plbossart plbossart merged commit 7615f51 into thesofproject:topic/sof-dev Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants