Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame^] | 1 | CVE: CVE-2018-20216 |
| 2 | Upstream-Status: Backport [https://git.qemu.org/?p=qemu.git;a=commit;h=f1e2e38] |
| 3 | |
| 4 | Signed-off-by: Kai Kang <kai.kang@windriver.com> |
| 5 | |
| 6 | From f1e2e38ee0136b7710a2caa347049818afd57a1b Mon Sep 17 00:00:00 2001 |
| 7 | From: Prasad J Pandit <pjp@fedoraproject.org> |
| 8 | Date: Thu, 13 Dec 2018 01:00:39 +0530 |
| 9 | Subject: [PATCH] pvrdma: check return value from pvrdma_idx_ring_has_ routines |
| 10 | |
| 11 | pvrdma_idx_ring_has_[data/space] routines also return invalid |
| 12 | index PVRDMA_INVALID_IDX[=-1], if ring has no data/space. Check |
| 13 | return value from these routines to avoid plausible infinite loops. |
| 14 | |
| 15 | Reported-by: Li Qiang <liq3ea@163.com> |
| 16 | Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org> |
| 17 | Reviewed-by: Yuval Shaia <yuval.shaia@oracle.com> |
| 18 | Signed-off-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com> |
| 19 | --- |
| 20 | hw/rdma/vmw/pvrdma_dev_ring.c | 29 +++++++++++------------------ |
| 21 | 1 file changed, 11 insertions(+), 18 deletions(-) |
| 22 | |
| 23 | diff --git a/hw/rdma/vmw/pvrdma_dev_ring.c b/hw/rdma/vmw/pvrdma_dev_ring.c |
| 24 | index 01247fc041..e8e5b502f6 100644 |
| 25 | --- a/hw/rdma/vmw/pvrdma_dev_ring.c |
| 26 | +++ b/hw/rdma/vmw/pvrdma_dev_ring.c |
| 27 | @@ -73,23 +73,16 @@ out: |
| 28 | |
| 29 | void *pvrdma_ring_next_elem_read(PvrdmaRing *ring) |
| 30 | { |
| 31 | + int e; |
| 32 | unsigned int idx = 0, offset; |
| 33 | |
| 34 | - /* |
| 35 | - pr_dbg("%s: t=%d, h=%d\n", ring->name, ring->ring_state->prod_tail, |
| 36 | - ring->ring_state->cons_head); |
| 37 | - */ |
| 38 | - |
| 39 | - if (!pvrdma_idx_ring_has_data(ring->ring_state, ring->max_elems, &idx)) { |
| 40 | + e = pvrdma_idx_ring_has_data(ring->ring_state, ring->max_elems, &idx); |
| 41 | + if (e <= 0) { |
| 42 | pr_dbg("No more data in ring\n"); |
| 43 | return NULL; |
| 44 | } |
| 45 | |
| 46 | offset = idx * ring->elem_sz; |
| 47 | - /* |
| 48 | - pr_dbg("idx=%d\n", idx); |
| 49 | - pr_dbg("offset=%d\n", offset); |
| 50 | - */ |
| 51 | return ring->pages[offset / TARGET_PAGE_SIZE] + (offset % TARGET_PAGE_SIZE); |
| 52 | } |
| 53 | |
| 54 | @@ -105,20 +98,20 @@ void pvrdma_ring_read_inc(PvrdmaRing *ring) |
| 55 | |
| 56 | void *pvrdma_ring_next_elem_write(PvrdmaRing *ring) |
| 57 | { |
| 58 | - unsigned int idx, offset, tail; |
| 59 | + int idx; |
| 60 | + unsigned int offset, tail; |
| 61 | |
| 62 | - /* |
| 63 | - pr_dbg("%s: t=%d, h=%d\n", ring->name, ring->ring_state->prod_tail, |
| 64 | - ring->ring_state->cons_head); |
| 65 | - */ |
| 66 | - |
| 67 | - if (!pvrdma_idx_ring_has_space(ring->ring_state, ring->max_elems, &tail)) { |
| 68 | + idx = pvrdma_idx_ring_has_space(ring->ring_state, ring->max_elems, &tail); |
| 69 | + if (idx <= 0) { |
| 70 | pr_dbg("CQ is full\n"); |
| 71 | return NULL; |
| 72 | } |
| 73 | |
| 74 | idx = pvrdma_idx(&ring->ring_state->prod_tail, ring->max_elems); |
| 75 | - /* TODO: tail == idx */ |
| 76 | + if (idx < 0 || tail != idx) { |
| 77 | + pr_dbg("invalid idx\n"); |
| 78 | + return NULL; |
| 79 | + } |
| 80 | |
| 81 | offset = idx * ring->elem_sz; |
| 82 | return ring->pages[offset / TARGET_PAGE_SIZE] + (offset % TARGET_PAGE_SIZE); |
| 83 | -- |
| 84 | 2.20.1 |
| 85 | |