Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame^] | 1 | From 00837731d254908a841d69298a4f9f077babaf24 Mon Sep 17 00:00:00 2001 |
| 2 | From: Stefan Weil <sw@weilnetz.de> |
| 3 | Date: Fri, 20 Nov 2015 08:42:33 +0100 |
| 4 | Subject: [PATCH] eepro100: Prevent two endless loops |
| 5 | |
| 6 | http://lists.nongnu.org/archive/html/qemu-devel/2015-11/msg04592.html |
| 7 | shows an example how an endless loop in function action_command can |
| 8 | be achieved. |
| 9 | |
| 10 | During my code review, I noticed a 2nd case which can result in an |
| 11 | endless loop. |
| 12 | |
| 13 | Reported-by: Qinghao Tang <luodalongde@gmail.com> |
| 14 | Signed-off-by: Stefan Weil <sw@weilnetz.de> |
| 15 | Signed-off-by: Jason Wang <jasowang@redhat.com> |
| 16 | |
| 17 | Upstream-Status: Backport |
| 18 | |
| 19 | http://git.qemu.org/?p=qemu.git;a=commit;h=00837731d254908a841d69298a4f9f077babaf24 |
| 20 | |
| 21 | CVE: CVE-2015-8345 |
| 22 | [Yocto # 9013] |
| 23 | |
| 24 | Signed-off-by: Armin Kuster <akuster@mvista.com> |
| 25 | |
| 26 | --- |
| 27 | hw/net/eepro100.c | 16 ++++++++++++++++ |
| 28 | 1 file changed, 16 insertions(+) |
| 29 | |
| 30 | diff --git a/hw/net/eepro100.c b/hw/net/eepro100.c |
| 31 | index 60333b7..685a478 100644 |
| 32 | --- a/hw/net/eepro100.c |
| 33 | +++ b/hw/net/eepro100.c |
| 34 | @@ -774,6 +774,11 @@ static void tx_command(EEPRO100State *s) |
| 35 | #if 0 |
| 36 | uint16_t tx_buffer_el = lduw_le_pci_dma(&s->dev, tbd_address + 6); |
| 37 | #endif |
| 38 | + if (tx_buffer_size == 0) { |
| 39 | + /* Prevent an endless loop. */ |
| 40 | + logout("loop in %s:%u\n", __FILE__, __LINE__); |
| 41 | + break; |
| 42 | + } |
| 43 | tbd_address += 8; |
| 44 | TRACE(RXTX, logout |
| 45 | ("TBD (simplified mode): buffer address 0x%08x, size 0x%04x\n", |
| 46 | @@ -855,6 +860,10 @@ static void set_multicast_list(EEPRO100State *s) |
| 47 | |
| 48 | static void action_command(EEPRO100State *s) |
| 49 | { |
| 50 | + /* The loop below won't stop if it gets special handcrafted data. |
| 51 | + Therefore we limit the number of iterations. */ |
| 52 | + unsigned max_loop_count = 16; |
| 53 | + |
| 54 | for (;;) { |
| 55 | bool bit_el; |
| 56 | bool bit_s; |
| 57 | @@ -870,6 +879,13 @@ static void action_command(EEPRO100State *s) |
| 58 | #if 0 |
| 59 | bool bit_sf = ((s->tx.command & COMMAND_SF) != 0); |
| 60 | #endif |
| 61 | + |
| 62 | + if (max_loop_count-- == 0) { |
| 63 | + /* Prevent an endless loop. */ |
| 64 | + logout("loop in %s:%u\n", __FILE__, __LINE__); |
| 65 | + break; |
| 66 | + } |
| 67 | + |
| 68 | s->cu_offset = s->tx.link; |
| 69 | TRACE(OTHER, |
| 70 | logout("val=(cu start), status=0x%04x, command=0x%04x, link=0x%08x\n", |
| 71 | -- |
| 72 | 2.3.5 |
| 73 | |