Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM: xHCI: Check trb pointer before use it #6173

Merged
merged 1 commit into from Jun 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
DM: xHCI: Check trb pointer before use it
The trb pointer may be NULL when get the address from user space, add
the pointer check before use the trb.

Tracked-On: #6172
Signed-off-by: Liu Long <long.liu@intel.com>
Reviewed-by: Shuo A Liu <shuo.a.liu@intel.com>
Acked-by: Yu Wang <yu1.wang@intel.com>
  • Loading branch information
liudlong committed Jun 8, 2021
commit 330359921e2e4c2f3f3a10b5bab86942d63c4428
5 changes: 5 additions & 0 deletions devicemodel/hw/pci/xhci.c
Expand Up @@ -2627,6 +2627,10 @@ pci_xhci_complete_commands(struct pci_xhci_vdev *xdev)
trb = xdev->opregs.cr_p;
ccs = xdev->opregs.crcr & XHCI_CRCR_LO_RCS;
crcr = xdev->opregs.crcr & ~0xF;
if (!trb) {
UPRINTF(LDBG, "Get the invalid guest address!\r\n");
Copy link
Contributor

@dbkinder dbkinder Jun 8, 2021

Choose a reason for hiding this comment

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

Shouldn't the DM code honor the LOGLEVEL setting for reporting messages? Also, this isn't a very descriptive message for an ACRN user to understand what happened and what they should do.

goto out;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh. I haven't noticed this gudieline, it required to be followed for both hypervisor and device model? The goto is everywhere even in Linux kernel... And there have hundreds goto in acrn-dm, we need a cleanup if it is needed.

}

while (1) {
xdev->opregs.cr_p = trb;
Expand Down Expand Up @@ -2759,6 +2763,7 @@ pci_xhci_complete_commands(struct pci_xhci_vdev *xdev)
}
}

out:
xdev->opregs.crcr = crcr | (xdev->opregs.crcr & XHCI_CRCR_LO_CA) | ccs;
xdev->opregs.crcr &= ~XHCI_CRCR_LO_CRR;
return 0;
Expand Down