Update qemu package to mitigate CVE-2015-3456
[packages/centos6/qemu.git] / 0025-fdc-force-the-fifo-access-to-be-in-bounds-of-the-allocated-buffer.patch
1 From ac7ddbe342d7aa2303c39ca731cc6229dbbd739b Mon Sep 17 00:00:00 2001
2 From: Petr Matousek <pmatouse@redhat.com>
3 Date: Wed, 6 May 2015 09:48:59 +0200
4 Subject: [PATCH] fdc: force the fifo access to be in bounds of the allocated buffer
5
6 During processing of certain commands such as FD_CMD_READ_ID and
7 FD_CMD_DRIVE_SPECIFICATION_COMMAND the fifo memory access could
8 get out of bounds leading to memory corruption with values coming
9 from the guest.
10
11 Fix this by making sure that the index is always bounded by the
12 allocated memory.
13
14 This is CVE-2015-3456.
15
16 Signed-off-by: Petr Matousek <pmatouse@redhat.com>
17 ---
18  hw/block/fdc.c | 17 +++++++++++------
19  1 file changed, 11 insertions(+), 6 deletions(-)
20
21 diff --git a/hw/block/fdc.c b/hw/block/fdc.c
22 index f72a392..d8a8edd 100644
23 --- a/hw/block/fdc.c
24 +++ b/hw/block/fdc.c
25 @@ -1497,7 +1497,7 @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
26  {
27      FDrive *cur_drv;
28      uint32_t retval = 0;
29 -    int pos;
30 +    uint32_t pos;
31  
32      cur_drv = get_cur_drv(fdctrl);
33      fdctrl->dsr &= ~FD_DSR_PWRDOWN;
34 @@ -1506,8 +1506,8 @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
35          return 0;
36      }
37      pos = fdctrl->data_pos;
38 +    pos %= FD_SECTOR_LEN;
39      if (fdctrl->msr & FD_MSR_NONDMA) {
40 -        pos %= FD_SECTOR_LEN;
41          if (pos == 0) {
42              if (fdctrl->data_pos != 0)
43                  if (!fdctrl_seek_to_next_sect(fdctrl, cur_drv)) {
44 @@ -1852,10 +1852,13 @@ static void fdctrl_handle_option(FDCtrl *fdctrl, int direction)
45  static void fdctrl_handle_drive_specification_command(FDCtrl *fdctrl, int direction)
46  {
47      FDrive *cur_drv = get_cur_drv(fdctrl);
48 +    uint32_t pos;
49  
50 -    if (fdctrl->fifo[fdctrl->data_pos - 1] & 0x80) {
51 +    pos = fdctrl->data_pos - 1;
52 +    pos %= FD_SECTOR_LEN;
53 +    if (fdctrl->fifo[pos] & 0x80) {
54          /* Command parameters done */
55 -        if (fdctrl->fifo[fdctrl->data_pos - 1] & 0x40) {
56 +        if (fdctrl->fifo[pos] & 0x40) {
57              fdctrl->fifo[0] = fdctrl->fifo[1];
58              fdctrl->fifo[2] = 0;
59              fdctrl->fifo[3] = 0;
60 @@ -1955,7 +1958,7 @@ static uint8_t command_to_handler[256];
61  static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
62  {
63      FDrive *cur_drv;
64 -    int pos;
65 +    uint32_t pos;
66  
67      /* Reset mode */
68      if (!(fdctrl->dor & FD_DOR_nRESET)) {
69 @@ -2004,7 +2007,9 @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
70      }
71  
72      FLOPPY_DPRINTF("%s: %02x\n", __func__, value);
73 -    fdctrl->fifo[fdctrl->data_pos++] = value;
74 +    pos = fdctrl->data_pos++;
75 +    pos %= FD_SECTOR_LEN;
76 +    fdctrl->fifo[pos] = value;
77      if (fdctrl->data_pos == fdctrl->data_len) {
78          /* We now have all parameters
79           * and will be able to treat the command
80 -- 
81 2.1.0
82