Francois Toguo Fotso has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/32083
Change subject: payload/libpayload: This is a fixe for potential NULL pointer dereferences ......................................................................
payload/libpayload: This is a fixe for potential NULL pointer dereferences
These potential issues are flagged in Klockwork reports
BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 76 insertions(+), 19 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/1
diff --git a/payloads/libpayload/drivers/usb/ehci.c b/payloads/libpayload/drivers/usb/ehci.c index 30cf191..61a39a7 100644 --- a/payloads/libpayload/drivers/usb/ehci.c +++ b/payloads/libpayload/drivers/usb/ehci.c @@ -634,6 +634,8 @@
/* create #reqcount transfer descriptors (qTDs) */ intrq->head = (intr_qtd_t *)dma_memalign(64, sizeof(intr_qtd_t)); + if (!intrq->head) + fatal("Not enough memory to create #reqcount transfer descriptors. \n"); intr_qtd_t *cur_td = intrq->head; for (i = 0; i < reqcount; ++i) { fill_intr_queue_td(intrq, cur_td, data); @@ -642,6 +644,11 @@ /* create one more qTD */ intr_qtd_t *const next_td = (intr_qtd_t *)dma_memalign(64, sizeof(intr_qtd_t)); + if (!next_td) { + usb_debug("Not enough memory to add transfer descriptor. \n"); + free(next_td); + continue; + } cur_td->td.next_qtd = virt_to_phys(&next_td->td); cur_td->next = next_td; cur_td = next_td; @@ -651,6 +658,8 @@
/* create spare qTD */ intrq->spare = (intr_qtd_t *)dma_memalign(64, sizeof(intr_qtd_t)); + if (!intrq->spare) + fatal("Not enough memory to create spare transfer descriptors.\n"); intrq->spare->data = data;
/* initialize QH */ @@ -824,15 +833,20 @@ * and doesn't violate the standard. */ EHCI_INST(controller)->dummy_qh = (ehci_qh_t *)dma_memalign(64, sizeof(ehci_qh_t)); - memset((void *)EHCI_INST(controller)->dummy_qh, 0, - sizeof(*EHCI_INST(controller)->dummy_qh)); - EHCI_INST(controller)->dummy_qh->horiz_link_ptr = QH_TERMINATE; - EHCI_INST(controller)->dummy_qh->td.next_qtd = QH_TERMINATE; - EHCI_INST(controller)->dummy_qh->td.alt_next_qtd = QH_TERMINATE; - for (i = 0; i < 1024; ++i) - periodic_list[i] = virt_to_phys(EHCI_INST(controller)->dummy_qh) - | PS_TYPE_QH; - + if (EHCI_INST(controller)->dummy_qh) { + memset((void *)EHCI_INST(controller)->dummy_qh, 0, + sizeof(*EHCI_INST(controller)->dummy_qh)); + EHCI_INST(controller)->dummy_qh->horiz_link_ptr = QH_TERMINATE; + EHCI_INST(controller)->dummy_qh->td.next_qtd = QH_TERMINATE; + EHCI_INST(controller)->dummy_qh->td.alt_next_qtd = QH_TERMINATE; + for (i = 0; i < 1024; ++i) + periodic_list[i] = virt_to_phys(EHCI_INST(controller)->dummy_qh) + | PS_TYPE_QH; + } else { + usb_debug("Not enough DMA memory for EHCI dummy QH!\n"); + free(EHCI_INST(controller)->dummy_qh); + } + /* Make sure periodic schedule is disabled */ ehci_set_periodic_schedule(EHCI_INST(controller), 0); /* Set periodic frame list pointer */ diff --git a/payloads/libpayload/drivers/usb/ohci.c b/payloads/libpayload/drivers/usb/ohci.c index 1964689..045bb7a 100644 --- a/payloads/libpayload/drivers/usb/ohci.c +++ b/payloads/libpayload/drivers/usb/ohci.c @@ -212,6 +212,8 @@ udelay (10); /* at most 10us for reset to complete. State must be set to Operational within 2ms (5.1.1.4) */ OHCI_INST (controller)->opreg->HcFmInterval = interval; OHCI_INST (controller)->hcca = dma_memalign(256, 256); + if (!OHCI_INST(controller)->hcca) + fatal("Not enough DMA memory for OHCI hcca.\n"); memset((void*)OHCI_INST (controller)->hcca, 0, 256);
if (dma_initialized()) { @@ -223,6 +225,8 @@ /* Initialize interrupt table. */ u32 *const intr_table = OHCI_INST(controller)->hcca->HccaInterruptTable; ed_t *const periodic_ed = dma_memalign(sizeof(ed_t), sizeof(ed_t)); + if (!periodic_ed) + fatal("Not enough DMA memory for OHCI interrupt table .\n"); memset((void *)periodic_ed, 0, sizeof(*periodic_ed)); for (i = 0; i < 32; ++i) intr_table[i] = virt_to_phys(periodic_ed); @@ -378,6 +382,8 @@
/* First TD. */ td_t *const first_td = (td_t *)dma_memalign(sizeof(td_t), sizeof(td_t)); + if (!first_td) + fatal("Not enough DMA memory for OHCI first TD in buffer.\n"); memset((void *)first_td, 0, sizeof(*first_td)); cur = first_td;
@@ -392,6 +398,8 @@ while (pages > 0) { /* One more TD. */ td_t *const next = (td_t *)dma_memalign(sizeof(td_t), sizeof(td_t)); + if (!next) + fatal("Not enough DMA memory for OHCI new page.\n"); memset((void *)next, 0, sizeof(*next)); /* Linked to the previous. */ cur->next_td = virt_to_phys(next); @@ -426,6 +434,8 @@
/* One more TD. */ td_t *const next_td = (td_t *)dma_memalign(sizeof(td_t), sizeof(td_t)); + if (!next_td) + fatal("Not enough DMA memory for OHCI additional TD.\n"); memset((void *)next_td, 0, sizeof(*next_td)); /* Linked to the previous. */ cur->next_td = virt_to_phys(next_td); @@ -441,12 +451,18 @@
/* Final dummy TD. */ td_t *const final_td = (td_t *)dma_memalign(sizeof(td_t), sizeof(td_t)); - memset((void *)final_td, 0, sizeof(*final_td)); - /* Linked to the previous. */ - cur->next_td = virt_to_phys(final_td); - + if (final_td) { + memset((void *)final_td, 0, sizeof(*final_td)); + /* Linked to the previous. */ + cur->next_td = virt_to_phys(final_td); + } else { + usb_debug("Not enough DMA memory for OHCI dummy TD!\n"); + free(final_td); + } /* Data structures */ ed_t *head = dma_memalign(sizeof(ed_t), sizeof(ed_t)); + if (!head) + fatal("Not enough DMA memory for OHCI data structures.\n"); memset((void*)head, 0, sizeof(*head)); head->config = (dev->address << ED_FUNC_SHIFT) | (0 << ED_EP_SHIFT) | @@ -519,6 +535,8 @@
/* First TD. */ td_t *const first_td = (td_t *)dma_memalign(sizeof(td_t), sizeof(td_t)); + if (!first_td) + fatal("Not enough DMA memory for OHCI first TD of bulk transfer.\n"); memset((void *)first_td, 0, sizeof(*first_td)); cur = next = first_td;
@@ -557,6 +575,10 @@ } /* One more TD. */ next = (td_t *)dma_memalign(sizeof(td_t), sizeof(td_t)); + if (!next) { + usb_debug("Not enough DMA memory for OHCI addition TD in bulk transfer.\n"); + break; + } memset((void *)next, 0, sizeof(*next)); /* Linked to the previous. */ cur->next_td = virt_to_phys(next); @@ -569,6 +591,8 @@
/* Data structures */ ed_t *head = dma_memalign(sizeof(ed_t), sizeof(ed_t)); + if (!head) + fatal("Not enough DMA memory for OHCI bulk transfer's head.\n"); memset((void*)head, 0, sizeof(*head)); head->config = (ep->dev->address << ED_FUNC_SHIFT) | ((ep->endpoint & 0xf) << ED_EP_SHIFT) | @@ -665,6 +689,11 @@
intr_queue_t *const intrq = (intr_queue_t *)dma_memalign(sizeof(intrq->ed), sizeof(*intrq)); + if (!intrq) { + usb_debug("Not enough DMA memory for intr queue \n"); + free(final_td); + return NULL; + } memset(intrq, 0, sizeof(*intrq)); intrq->data = (u8 *)dma_malloc(reqcount * reqsize); intrq->reqsize = reqsize; @@ -674,6 +703,11 @@ u8 *cur_data = intrq->data; for (i = 0; i < reqcount; ++i) { intrq_td_t *const td = dma_memalign(sizeof(td->td), sizeof(*td)); + if (!td) { + usb_debug("Not enough memory to add transfer descriptor. \n"); + free(td); + continue; + } ++intrq->remaining_tds; ohci_fill_intrq_td(td, intrq, cur_data); cur_data += reqsize; @@ -686,12 +720,17 @@
/* Create last, dummy TD. */ intrq_td_t *dummy_td = dma_memalign(sizeof(dummy_td->td), sizeof(*dummy_td)); - memset(dummy_td, 0, sizeof(*dummy_td)); - dummy_td->intrq = intrq; - if (last_td) - last_td->td.next_td = virt_to_phys(&dummy_td->td); - last_td = dummy_td; - + if (dummy_td) { + memset(dummy_td, 0, sizeof(*dummy_td)); + dummy_td->intrq = intrq; + if (last_td) + last_td->td.next_td = virt_to_phys(&dummy_td->td); + last_td = dummy_td; + } else { + usb_debug("Not enough memory to add dummy TD. \n"); + free(dummy_td); + } + /* Initialize ED. */ intrq->ed.config = (ep->dev->address << ED_FUNC_SHIFT) | ((ep->endpoint & 0xf) << ED_EP_SHIFT) | diff --git a/payloads/libpayload/drivers/usb/uhci.c b/payloads/libpayload/drivers/usb/uhci.c index 70071eb..e62fd25 100644 --- a/payloads/libpayload/drivers/usb/uhci.c +++ b/payloads/libpayload/drivers/usb/uhci.c @@ -317,6 +317,8 @@ unsigned short req = ((unsigned short *) devreq)[0]; int i; td_t *tds = memalign (16, sizeof (td_t) * count); + if (!tds) + fatal("Not enough memory for uhci control.\n"); memset (tds, 0, sizeof (td_t) * count); count--; /* to compensate for 0-indexed array */ for (i = 0; i < count; i++) { @@ -386,6 +388,8 @@ if (numpackets == 0) return 0; td_t *tds = memalign (16, sizeof (td_t) * numpackets); + if (!tds) + fatal("Not enough memory for packets scheduling.\n"); memset (tds, 0, sizeof (td_t) * numpackets); int i; for (i = 0; i < numpackets; i++) {
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fixe for potential NULL pointer dereferences ......................................................................
Patch Set 1:
(26 comments)
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... PS1, Line 638: fatal("Not enough memory to create #reqcount transfer descriptors. \n"); line over 80 characters
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... PS1, Line 638: fatal("Not enough memory to create #reqcount transfer descriptors. \n"); unnecessary whitespace before a quoted newline
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... PS1, Line 648: usb_debug("Not enough memory to add transfer descriptor. \n"); unnecessary whitespace before a quoted newline
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... PS1, Line 662: fatal("Not enough memory to create spare transfer descriptors.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... PS1, Line 843: periodic_list[i] = virt_to_phys(EHCI_INST(controller)->dummy_qh) line over 80 characters
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... PS1, Line 849: trailing whitespace
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 215: if (!OHCI_INST(controller)->hcca) suspect code indent for conditional statements (8, 24)
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 228: if (!periodic_ed) suspect code indent for conditional statements (8, 24)
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 229: fatal("Not enough DMA memory for OHCI interrupt table .\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 385: if (!first_td) suspect code indent for conditional statements (8, 24)
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 386: fatal("Not enough DMA memory for OHCI first TD in buffer.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 437: if (!next_td) suspect code indent for conditional statements (8, 24)
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 438: fatal("Not enough DMA memory for OHCI additional TD.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 464: if (!head) suspect code indent for conditional statements (8, 24)
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 465: fatal("Not enough DMA memory for OHCI data structures.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 538: if (!first_td) suspect code indent for conditional statements (8, 24)
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 539: fatal("Not enough DMA memory for OHCI first TD of bulk transfer.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 594: if (!head) suspect code indent for conditional statements (8, 24)
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 595: fatal("Not enough DMA memory for OHCI bulk transfer's head.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 693: usb_debug("Not enough DMA memory for intr queue \n"); unnecessary whitespace before a quoted newline
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 707: usb_debug("Not enough memory to add transfer descriptor. \n"); code indent should use tabs where possible
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 707: usb_debug("Not enough memory to add transfer descriptor. \n"); please, no space before tabs
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 707: usb_debug("Not enough memory to add transfer descriptor. \n"); please, no spaces at the start of a line
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 707: usb_debug("Not enough memory to add transfer descriptor. \n"); unnecessary whitespace before a quoted newline
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 730: usb_debug("Not enough memory to add dummy TD. \n"); unnecessary whitespace before a quoted newline
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 733: trailing whitespace
Francois Toguo Fotso has uploaded a new patch set (#2) to the change originally created by Francois Toguo Fotso. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fixe for potential NULL pointer dereferences ......................................................................
payload/libpayload: This is a fixe for potential NULL pointer dereferences
These potential issues are flagged in Klockwork reports
BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 74 insertions(+), 17 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/2
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fixe for potential NULL pointer dereferences ......................................................................
Patch Set 2:
(3 comments)
https://review.coreboot.org/#/c/32083/2/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/2/payloads/libpayload/drivers/usb/ehci... PS2, Line 638: fatal("Not enough memory to create #reqcount transfer descriptors.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/2/payloads/libpayload/drivers/usb/ehci... PS2, Line 843: periodic_list[i] = virt_to_phys(EHCI_INST(controller)->dummy_qh) line over 80 characters
https://review.coreboot.org/#/c/32083/2/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/2/payloads/libpayload/drivers/usb/ohci... PS2, Line 539: fatal("Not enough DMA memory for OHCI first TD of bulk transfer.\n"); line over 80 characters
Francois Toguo Fotso has uploaded a new patch set (#3) to the change originally created by Francois Toguo Fotso. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
payload/libpayload: This is a fix for potential NULL pointer dereferences
These potential issues are flagged in Klockwork reports
BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 74 insertions(+), 17 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/3
Francois Toguo Fotso has uploaded a new patch set (#4) to the change originally created by Francois Toguo Fotso. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
payload/libpayload: This is a fix for potential NULL pointer dereferences
These potential issues are flagged in Klockwork reports
BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 77 insertions(+), 17 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/4
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 4:
(1 comment)
https://review.coreboot.org/#/c/32083/4/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/4/payloads/libpayload/drivers/usb/ehci... PS4, Line 844: periodic_list[i] = trailing whitespace
Francois Toguo Fotso has uploaded a new patch set (#5) to the change originally created by Francois Toguo Fotso. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
payload/libpayload: This is a fix for potential NULL pointer dereferences
These potential issues are flagged in Klockwork reports
BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 77 insertions(+), 17 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/5
Francois Toguo Fotso has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 5:
(26 comments)
Gentlemen,
Would you please review the following patch?
Regards, Francois
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... PS1, Line 638: fatal("Not enough memory to create #reqcount transfer descriptors. \n");
line over 80 characters
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... PS1, Line 638: fatal("Not enough memory to create #reqcount transfer descriptors. \n");
unnecessary whitespace before a quoted newline
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... PS1, Line 648: usb_debug("Not enough memory to add transfer descriptor. \n");
unnecessary whitespace before a quoted newline
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... PS1, Line 662: fatal("Not enough memory to create spare transfer descriptors.\n");
line over 80 characters
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... PS1, Line 843: periodic_list[i] = virt_to_phys(EHCI_INST(controller)->dummy_qh)
line over 80 characters
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ehci... PS1, Line 849:
trailing whitespace
Done
https://review.coreboot.org/#/c/32083/2/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/2/payloads/libpayload/drivers/usb/ehci... PS2, Line 638: fatal("Not enough memory to create #reqcount transfer descriptors.\n");
line over 80 characters
Done
https://review.coreboot.org/#/c/32083/2/payloads/libpayload/drivers/usb/ehci... PS2, Line 843: periodic_list[i] = virt_to_phys(EHCI_INST(controller)->dummy_qh)
line over 80 characters
Done
https://review.coreboot.org/#/c/32083/4/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/4/payloads/libpayload/drivers/usb/ehci... PS4, Line 844: periodic_list[i] =
trailing whitespace
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 215: if (!OHCI_INST(controller)->hcca)
suspect code indent for conditional statements (8, 24)
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 228: if (!periodic_ed)
suspect code indent for conditional statements (8, 24)
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 229: fatal("Not enough DMA memory for OHCI interrupt table .\n");
line over 80 characters
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 385: if (!first_td)
suspect code indent for conditional statements (8, 24)
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 386: fatal("Not enough DMA memory for OHCI first TD in buffer.\n");
line over 80 characters
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 437: if (!next_td)
suspect code indent for conditional statements (8, 24)
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 438: fatal("Not enough DMA memory for OHCI additional TD.\n");
line over 80 characters
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 465: fatal("Not enough DMA memory for OHCI data structures.\n");
line over 80 characters
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 539: fatal("Not enough DMA memory for OHCI first TD of bulk transfer.\n");
line over 80 characters
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 594: if (!head)
suspect code indent for conditional statements (8, 24)
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 595: fatal("Not enough DMA memory for OHCI bulk transfer's head.\n");
line over 80 characters
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 693: usb_debug("Not enough DMA memory for intr queue \n");
unnecessary whitespace before a quoted newline
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 707: usb_debug("Not enough memory to add transfer descriptor. \n");
please, no space before tabs
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 707: usb_debug("Not enough memory to add transfer descriptor. \n");
code indent should use tabs where possible
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 707: usb_debug("Not enough memory to add transfer descriptor. \n");
unnecessary whitespace before a quoted newline
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 730: usb_debug("Not enough memory to add dummy TD. \n");
unnecessary whitespace before a quoted newline
Done
https://review.coreboot.org/#/c/32083/1/payloads/libpayload/drivers/usb/ohci... PS1, Line 733:
trailing whitespace
Done
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 5:
(9 comments)
LGTM in general but I don't think you can just continue in all those cases where an allocation failed. I think you should just use fatal() everywhere.
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ehci... PS5, Line 638: memory nit: clarify to "DMA memory"? this may come from a different allocation pool than the main heap
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ehci... PS5, Line 651: continue; I don't think continue is appropriate here? I think this kills the EHCI stack. Another fatal() would probably be better.
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ehci... PS5, Line 837: if (EHCI_INST(controller)->dummy_qh) { Same here, I don't think it makes sense to continue if the allocation failed.
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... PS5, Line 216: hcca nit: HCCA in all caps (short for Host Controller <something> Area)
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... PS5, Line 454: if (final_td) { Shouldn't continue without this. (If you want to fail gracefully, the correct behavior would be to roll the whole function back and return an error code, but OOM errors shouldn't really happen in practice anyway so I think a fatal() is also good enough.)
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... PS5, Line 540: "first TD of bulk transfer.\n"); Please don't break strings (it's permissible to go beyond 80 characters if necessary to not break a string).
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... PS5, Line 581: break; Again can't just break here
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... PS5, Line 710: continue; ...and here
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... PS5, Line 733: } ...and here
Francois Toguo Fotso has uploaded a new patch set (#6) to the change originally created by Francois Toguo Fotso. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
payload/libpayload: This is a fix for potential NULL pointer dereferences
These potential issues are flagged in Klockwork reports
BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 42 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/6
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 6:
(5 comments)
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ehci... PS6, Line 647: if (!next_td) trailing whitespace
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ehci... PS6, Line 648: fatal("Not enough DMA memory to create #reqcount TD.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ehci... PS6, Line 833: if (!EHCI_INST(controller)->dummy_qh) trailing whitespace
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ohci... PS6, Line 577: fatal("Not enough DMA memory for OHCI addition TD in bulk transfer.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ohci... PS6, Line 703: fatal("Not enough memory to add transfer descriptor.\n"); line over 80 characters
Francois Toguo Fotso has uploaded a new patch set (#7) to the change originally created by Francois Toguo Fotso. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
payload/libpayload: This is a fix for potential NULL pointer dereferences
These potential issues are flagged in Klockwork reports
BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 42 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/7
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 7:
(2 comments)
https://review.coreboot.org/#/c/32083/7/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/7/payloads/libpayload/drivers/usb/ohci... PS7, Line 577: fatal("Not enough DMA memory for OHCI addition TD in bulk transfer.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/7/payloads/libpayload/drivers/usb/ohci... PS7, Line 703: fatal("Not enough memory to add transfer descriptor.\n"); line over 80 characters
Francois Toguo Fotso has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 7:
(15 comments)
Patch Set 5:
(26 comments)
Gentlemen,
Would you please review the following patch?
Regards, Francois
Julius,
Your comments have been addressed.
Regards, Francois
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ehci... PS5, Line 638: memory
nit: clarify to "DMA memory"? this may come from a different allocation pool than the main heap
Done
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ehci... PS5, Line 651: continue;
I don't think continue is appropriate here? I think this kills the EHCI stack. […]
Done
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ehci... PS5, Line 837: if (EHCI_INST(controller)->dummy_qh) {
Same here, I don't think it makes sense to continue if the allocation failed.
Done
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ehci... PS6, Line 647: if (!next_td)
trailing whitespace
Done
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ehci... PS6, Line 648: fatal("Not enough DMA memory to create #reqcount TD.\n");
line over 80 characters
Ack
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ehci... PS6, Line 833: if (!EHCI_INST(controller)->dummy_qh)
trailing whitespace
Done
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... PS5, Line 216: hcca
nit: HCCA in all caps (short for Host Controller <something> Area)
Done
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... PS5, Line 454: if (final_td) {
Shouldn't continue without this. […]
Done
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... PS5, Line 540: "first TD of bulk transfer.\n");
Please don't break strings (it's permissible to go beyond 80 characters if necessary to not break a […]
Done
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... PS5, Line 581: break;
Again can't just break here
Done
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... PS5, Line 710: continue;
... […]
Done
https://review.coreboot.org/#/c/32083/5/payloads/libpayload/drivers/usb/ohci... PS5, Line 733: }
... […]
Done
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ohci... PS6, Line 577: fatal("Not enough DMA memory for OHCI addition TD in bulk transfer.\n");
line over 80 characters
Ack
https://review.coreboot.org/#/c/32083/6/payloads/libpayload/drivers/usb/ohci... PS6, Line 703: fatal("Not enough memory to add transfer descriptor.\n");
line over 80 characters
Ack
https://review.coreboot.org/#/c/32083/7/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/7/payloads/libpayload/drivers/usb/ohci... PS7, Line 703: fatal("Not enough memory to add transfer descriptor.\n");
line over 80 characters
Ack
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 7: Code-Review+2
Looks good, thanks!
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 7:
(1 comment)
Oh, wait, Jenkins actually thinks it doesn't look good. But after you fix that typo it looks good to me.
https://review.coreboot.org/#/c/32083/7/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/7/payloads/libpayload/drivers/usb/ohci... PS7, Line 690: final_td This must be 'intrq'
Francois Toguo Fotso has uploaded a new patch set (#8) to the change originally created by Francois Toguo Fotso. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
payload/libpayload: This is a fix for potential NULL pointer dereferences
These potential issues are flagged in Klockwork reports
BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 42 insertions(+), 1 deletion(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/8
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 8:
(2 comments)
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ohci... PS8, Line 577: fatal("Not enough DMA memory for OHCI addition TD in bulk transfer.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ohci... PS8, Line 703: fatal("Not enough memory to add transfer descriptor.\n"); line over 80 characters
Julius Werner has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 8: Code-Review+2
HAOUAS Elyes has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 8:
(1 comment)
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ehci... PS8, Line 842: related ?
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 8: Code-Review-1
(4 comments)
https://review.coreboot.org/#/c/32083/8//COMMIT_MSG Commit Message:
https://review.coreboot.org/#/c/32083/8//COMMIT_MSG@7 PS8, Line 7: payload/libpayload: This is a fix for potential NULL pointer dereferences Please use:
libpayload: Fix potential NULL pointer dereference
https://review.coreboot.org/#/c/32083/8//COMMIT_MSG@10 PS8, Line 10: Just add a tag:
Found-by: Klockwork
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ehci... PS8, Line 659: memory Also *DMA memory* here?
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ohci... PS8, Line 703: memory DMA memory
Francois Toguo Fotso has uploaded a new patch set (#9) to the change originally created by Francois Toguo Fotso. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
payload/libpayload: This is a fix for potential NULL pointer dereferences
These potential issues are flagged in Klockwork reports
BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 42 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/9
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: payload/libpayload: This is a fix for potential NULL pointer dereferences ......................................................................
Patch Set 9:
(3 comments)
https://review.coreboot.org/#/c/32083/9/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/9/payloads/libpayload/drivers/usb/ehci... PS9, Line 841: periodic_list[i] = virt_to_phys(EHCI_INST(controller)->dummy_qh) | PS_TYPE_QH; line over 80 characters
https://review.coreboot.org/#/c/32083/9/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/9/payloads/libpayload/drivers/usb/ohci... PS9, Line 577: fatal("Not enough DMA memory for OHCI addition TD in bulk transfer.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/9/payloads/libpayload/drivers/usb/ohci... PS9, Line 703: fatal("Not enough DMA memory to add transfer descriptor.\n"); line over 80 characters
Francois Toguo Fotso has uploaded a new patch set (#10) to the change originally created by Francois Toguo Fotso. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: libpayload: Fix potential NULL pointer dereference ......................................................................
libpayload: Fix potential NULL pointer dereference
Found-by: Klockwork BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 42 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/10
Francois Toguo Fotso has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: libpayload: Fix potential NULL pointer dereference ......................................................................
Patch Set 10:
(11 comments)
Patch Set 8: Code-Review-1
(4 comments)
Paul and HAOUAS,
You findings have been implemenented. Please take a look.
Regards, Francois
https://review.coreboot.org/#/c/32083/8//COMMIT_MSG Commit Message:
https://review.coreboot.org/#/c/32083/8//COMMIT_MSG@7 PS8, Line 7: payload/libpayload: This is a fix for potential NULL pointer dereferences
Please use: […]
Done
https://review.coreboot.org/#/c/32083/8//COMMIT_MSG@10 PS8, Line 10:
Just add a tag: […]
Done
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ehci... PS8, Line 659: memory
Also *DMA memory* here?
Done
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ehci... PS8, Line 659: memory
Also *DMA memory* here?
Done
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ehci... PS8, Line 842:
related ?
Done
https://review.coreboot.org/#/c/32083/9/payloads/libpayload/drivers/usb/ehci... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/9/payloads/libpayload/drivers/usb/ehci... PS9, Line 841: periodic_list[i] = virt_to_phys(EHCI_INST(controller)->dummy_qh) | PS_TYPE_QH;
line over 80 characters
Ack
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ohci... PS8, Line 577: fatal("Not enough DMA memory for OHCI addition TD in bulk transfer.\n");
line over 80 characters
Ack
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ohci... PS8, Line 703: memory
DMA memory
Done
https://review.coreboot.org/#/c/32083/8/payloads/libpayload/drivers/usb/ohci... PS8, Line 703: fatal("Not enough memory to add transfer descriptor.\n");
line over 80 characters
Ack
https://review.coreboot.org/#/c/32083/9/payloads/libpayload/drivers/usb/ohci... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/9/payloads/libpayload/drivers/usb/ohci... PS9, Line 577: fatal("Not enough DMA memory for OHCI addition TD in bulk transfer.\n");
line over 80 characters
Ack
https://review.coreboot.org/#/c/32083/9/payloads/libpayload/drivers/usb/ohci... PS9, Line 703: fatal("Not enough DMA memory to add transfer descriptor.\n");
line over 80 characters
Ack
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: libpayload: Fix potential NULL pointer dereference ......................................................................
Patch Set 11:
(3 comments)
https://review.coreboot.org/#/c/32083/11/payloads/libpayload/drivers/usb/ehc... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/11/payloads/libpayload/drivers/usb/ehc... PS11, Line 841: periodic_list[i] = virt_to_phys(EHCI_INST(controller)->dummy_qh) | PS_TYPE_QH; line over 80 characters
https://review.coreboot.org/#/c/32083/11/payloads/libpayload/drivers/usb/ohc... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/11/payloads/libpayload/drivers/usb/ohc... PS11, Line 577: fatal("Not enough DMA memory for OHCI addition TD in bulk transfer.\n"); line over 80 characters
https://review.coreboot.org/#/c/32083/11/payloads/libpayload/drivers/usb/ohc... PS11, Line 703: fatal("Not enough DMA memory to add transfer descriptor.\n"); line over 80 characters
Lijian Zhao has uploaded a new patch set (#12) to the change originally created by Francois Toguo Fotso. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: libpayload: Fix potential NULL pointer dereference ......................................................................
libpayload: Fix potential NULL pointer dereference
Found-by: Klockwork BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 43 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/12
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: libpayload: Fix potential NULL pointer dereference ......................................................................
Patch Set 12:
(2 comments)
https://review.coreboot.org/#/c/32083/12/payloads/libpayload/drivers/usb/ehc... File payloads/libpayload/drivers/usb/ehci.c:
https://review.coreboot.org/#/c/32083/12/payloads/libpayload/drivers/usb/ehc... PS12, Line 842: virt_to_phys(EHCI_INST(controller)->dummy_qh) | PS_TYPE_QH; line over 80 characters
https://review.coreboot.org/#/c/32083/12/payloads/libpayload/drivers/usb/ohc... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/12/payloads/libpayload/drivers/usb/ohc... PS12, Line 577: fatal("Not enough DMA mem for OHCI addition TD bulk transfer.\n"); line over 80 characters
Lijian Zhao has uploaded a new patch set (#13) to the change originally created by Francois Toguo Fotso. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: libpayload: Fix potential NULL pointer dereference ......................................................................
libpayload: Fix potential NULL pointer dereference
Found-by: Klockwork BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 44 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/13
build bot (Jenkins) has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: libpayload: Fix potential NULL pointer dereference ......................................................................
Patch Set 13:
(1 comment)
https://review.coreboot.org/#/c/32083/13/payloads/libpayload/drivers/usb/ohc... File payloads/libpayload/drivers/usb/ohci.c:
https://review.coreboot.org/#/c/32083/13/payloads/libpayload/drivers/usb/ohc... PS13, Line 577: fatal("Not enough DMA mem for OCHI TD bulk transfer.\n"); line over 80 characters
Lijian Zhao has uploaded a new patch set (#14) to the change originally created by Francois Toguo Fotso. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: libpayload: Fix potential NULL pointer dereference ......................................................................
libpayload: Fix potential NULL pointer dereference
Found-by: Klockwork BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 44 insertions(+), 2 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/83/32083/14
Lijian Zhao has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: libpayload: Fix potential NULL pointer dereference ......................................................................
Patch Set 14: Code-Review+2
Paul Menzel has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: libpayload: Fix potential NULL pointer dereference ......................................................................
Patch Set 14: Code-Review+1
Patrick Georgi has posted comments on this change. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: libpayload: Fix potential NULL pointer dereference ......................................................................
Patch Set 14: Code-Review+2
Patrick Georgi has submitted this change and it was merged. ( https://review.coreboot.org/c/coreboot/+/32083 )
Change subject: libpayload: Fix potential NULL pointer dereference ......................................................................
libpayload: Fix potential NULL pointer dereference
Found-by: Klockwork BUG=NONE TEST=Boot to OS on GLK Sparky
Signed-off-by: Francois Toguo francois.toguo.fotso@intel.com Change-Id: I9d4636f0429de829e746909492c2f543026a02ac Reviewed-on: https://review.coreboot.org/c/coreboot/+/32083 Tested-by: build bot (Jenkins) no-reply@coreboot.org Reviewed-by: Lijian Zhao lijian.zhao@intel.com Reviewed-by: Paul Menzel paulepanter@users.sourceforge.net Reviewed-by: Patrick Georgi pgeorgi@google.com --- M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/uhci.c 3 files changed, 44 insertions(+), 2 deletions(-)
Approvals: build bot (Jenkins): Verified Patrick Georgi: Looks good to me, approved Paul Menzel: Looks good to me, but someone else must approve Lijian Zhao: Looks good to me, approved
diff --git a/payloads/libpayload/drivers/usb/ehci.c b/payloads/libpayload/drivers/usb/ehci.c index 30cf191..3d6c077 100644 --- a/payloads/libpayload/drivers/usb/ehci.c +++ b/payloads/libpayload/drivers/usb/ehci.c @@ -634,6 +634,8 @@
/* create #reqcount transfer descriptors (qTDs) */ intrq->head = (intr_qtd_t *)dma_memalign(64, sizeof(intr_qtd_t)); + if (!intrq->head) + fatal("Not enough DMA memory to create #reqcount TD.\n"); intr_qtd_t *cur_td = intrq->head; for (i = 0; i < reqcount; ++i) { fill_intr_queue_td(intrq, cur_td, data); @@ -642,6 +644,8 @@ /* create one more qTD */ intr_qtd_t *const next_td = (intr_qtd_t *)dma_memalign(64, sizeof(intr_qtd_t)); + if (!next_td) + fatal("Not enough DMA memory to create TD.\n"); cur_td->td.next_qtd = virt_to_phys(&next_td->td); cur_td->next = next_td; cur_td = next_td; @@ -651,6 +655,8 @@
/* create spare qTD */ intrq->spare = (intr_qtd_t *)dma_memalign(64, sizeof(intr_qtd_t)); + if (!intrq->spare) + fatal("Not enough DMA memory to create spare qTD.\n"); intrq->spare->data = data;
/* initialize QH */ @@ -824,14 +830,17 @@ * and doesn't violate the standard. */ EHCI_INST(controller)->dummy_qh = (ehci_qh_t *)dma_memalign(64, sizeof(ehci_qh_t)); + if (!EHCI_INST(controller)->dummy_qh) + fatal("Not enough DMA memory for EHCI dummy TD.\n"); memset((void *)EHCI_INST(controller)->dummy_qh, 0, sizeof(*EHCI_INST(controller)->dummy_qh)); EHCI_INST(controller)->dummy_qh->horiz_link_ptr = QH_TERMINATE; EHCI_INST(controller)->dummy_qh->td.next_qtd = QH_TERMINATE; EHCI_INST(controller)->dummy_qh->td.alt_next_qtd = QH_TERMINATE; for (i = 0; i < 1024; ++i) - periodic_list[i] = virt_to_phys(EHCI_INST(controller)->dummy_qh) - | PS_TYPE_QH; + periodic_list[i] = + virt_to_phys(EHCI_INST(controller)->dummy_qh) + | PS_TYPE_QH;
/* Make sure periodic schedule is disabled */ ehci_set_periodic_schedule(EHCI_INST(controller), 0); diff --git a/payloads/libpayload/drivers/usb/ohci.c b/payloads/libpayload/drivers/usb/ohci.c index 1964689..ecd1084 100644 --- a/payloads/libpayload/drivers/usb/ohci.c +++ b/payloads/libpayload/drivers/usb/ohci.c @@ -212,6 +212,8 @@ udelay (10); /* at most 10us for reset to complete. State must be set to Operational within 2ms (5.1.1.4) */ OHCI_INST (controller)->opreg->HcFmInterval = interval; OHCI_INST (controller)->hcca = dma_memalign(256, 256); + if (!OHCI_INST(controller)->hcca) + fatal("Not enough DMA memory for OHCI HCCA.\n"); memset((void*)OHCI_INST (controller)->hcca, 0, 256);
if (dma_initialized()) { @@ -223,6 +225,8 @@ /* Initialize interrupt table. */ u32 *const intr_table = OHCI_INST(controller)->hcca->HccaInterruptTable; ed_t *const periodic_ed = dma_memalign(sizeof(ed_t), sizeof(ed_t)); + if (!periodic_ed) + fatal("Not enough DMA memory for OHCI interrupt table.\n"); memset((void *)periodic_ed, 0, sizeof(*periodic_ed)); for (i = 0; i < 32; ++i) intr_table[i] = virt_to_phys(periodic_ed); @@ -378,6 +382,8 @@
/* First TD. */ td_t *const first_td = (td_t *)dma_memalign(sizeof(td_t), sizeof(td_t)); + if (!first_td) + fatal("Not enough DMA memory for OHCI first TD in buffer.\n"); memset((void *)first_td, 0, sizeof(*first_td)); cur = first_td;
@@ -392,6 +398,8 @@ while (pages > 0) { /* One more TD. */ td_t *const next = (td_t *)dma_memalign(sizeof(td_t), sizeof(td_t)); + if (!next) + fatal("Not enough DMA memory for OHCI new page.\n"); memset((void *)next, 0, sizeof(*next)); /* Linked to the previous. */ cur->next_td = virt_to_phys(next); @@ -426,6 +434,8 @@
/* One more TD. */ td_t *const next_td = (td_t *)dma_memalign(sizeof(td_t), sizeof(td_t)); + if (!next_td) + fatal("Not enough DMA memory for OHCI additional TD.\n"); memset((void *)next_td, 0, sizeof(*next_td)); /* Linked to the previous. */ cur->next_td = virt_to_phys(next_td); @@ -441,12 +451,16 @@
/* Final dummy TD. */ td_t *const final_td = (td_t *)dma_memalign(sizeof(td_t), sizeof(td_t)); + if (!final_td) + fatal("Not enough DMA memory for OHCI dummy TD!\n"); memset((void *)final_td, 0, sizeof(*final_td)); /* Linked to the previous. */ cur->next_td = virt_to_phys(final_td);
/* Data structures */ ed_t *head = dma_memalign(sizeof(ed_t), sizeof(ed_t)); + if (!head) + fatal("Not enough DMA memory for OHCI data structures.\n"); memset((void*)head, 0, sizeof(*head)); head->config = (dev->address << ED_FUNC_SHIFT) | (0 << ED_EP_SHIFT) | @@ -519,6 +533,8 @@
/* First TD. */ td_t *const first_td = (td_t *)dma_memalign(sizeof(td_t), sizeof(td_t)); + if (!first_td) + fatal("Not enough DMA memory for OHCI bulk transfer.\n"); memset((void *)first_td, 0, sizeof(*first_td)); cur = next = first_td;
@@ -557,6 +573,8 @@ } /* One more TD. */ next = (td_t *)dma_memalign(sizeof(td_t), sizeof(td_t)); + if (!next) + fatal("Not enough DMA mem for TD bulk transfer.\n"); memset((void *)next, 0, sizeof(*next)); /* Linked to the previous. */ cur->next_td = virt_to_phys(next); @@ -569,6 +587,8 @@
/* Data structures */ ed_t *head = dma_memalign(sizeof(ed_t), sizeof(ed_t)); + if (!head) + fatal("Not enough DMA memory for OHCI bulk transfer's head.\n"); memset((void*)head, 0, sizeof(*head)); head->config = (ep->dev->address << ED_FUNC_SHIFT) | ((ep->endpoint & 0xf) << ED_EP_SHIFT) | @@ -665,6 +685,11 @@
intr_queue_t *const intrq = (intr_queue_t *)dma_memalign(sizeof(intrq->ed), sizeof(*intrq)); + if (!intrq) { + usb_debug("Not enough DMA memory for intr queue.\n"); + free(intrq); + return NULL; + } memset(intrq, 0, sizeof(*intrq)); intrq->data = (u8 *)dma_malloc(reqcount * reqsize); intrq->reqsize = reqsize; @@ -674,6 +699,8 @@ u8 *cur_data = intrq->data; for (i = 0; i < reqcount; ++i) { intrq_td_t *const td = dma_memalign(sizeof(td->td), sizeof(*td)); + if (!td) + fatal("Not enough DMA mem to transfer descriptor.\n"); ++intrq->remaining_tds; ohci_fill_intrq_td(td, intrq, cur_data); cur_data += reqsize; @@ -686,6 +713,8 @@
/* Create last, dummy TD. */ intrq_td_t *dummy_td = dma_memalign(sizeof(dummy_td->td), sizeof(*dummy_td)); + if (!dummy_td) + fatal("Not enough memory to add dummy TD.\n"); memset(dummy_td, 0, sizeof(*dummy_td)); dummy_td->intrq = intrq; if (last_td) diff --git a/payloads/libpayload/drivers/usb/uhci.c b/payloads/libpayload/drivers/usb/uhci.c index 70071eb..e62fd25 100644 --- a/payloads/libpayload/drivers/usb/uhci.c +++ b/payloads/libpayload/drivers/usb/uhci.c @@ -317,6 +317,8 @@ unsigned short req = ((unsigned short *) devreq)[0]; int i; td_t *tds = memalign (16, sizeof (td_t) * count); + if (!tds) + fatal("Not enough memory for uhci control.\n"); memset (tds, 0, sizeof (td_t) * count); count--; /* to compensate for 0-indexed array */ for (i = 0; i < count; i++) { @@ -386,6 +388,8 @@ if (numpackets == 0) return 0; td_t *tds = memalign (16, sizeof (td_t) * numpackets); + if (!tds) + fatal("Not enough memory for packets scheduling.\n"); memset (tds, 0, sizeof (td_t) * numpackets); int i; for (i = 0; i < numpackets; i++) {