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
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
11 Fix this by making sure that the index is always bounded by the
14 This is CVE-2015-3456.
16 Signed-off-by: Petr Matousek <pmatouse@redhat.com>
18 hw/block/fdc.c | 17 +++++++++++------
19 1 file changed, 11 insertions(+), 6 deletions(-)
21 diff --git a/hw/block/fdc.c b/hw/block/fdc.c
22 index f72a392..d8a8edd 100644
25 @@ -1497,7 +1497,7 @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
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)
37 pos = fdctrl->data_pos;
38 + pos %= FD_SECTOR_LEN;
39 if (fdctrl->msr & FD_MSR_NONDMA) {
40 - pos %= FD_SECTOR_LEN;
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)
47 FDrive *cur_drv = get_cur_drv(fdctrl);
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];
60 @@ -1955,7 +1958,7 @@ static uint8_t command_to_handler[256];
61 static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
68 if (!(fdctrl->dor & FD_DOR_nRESET)) {
69 @@ -2004,7 +2007,9 @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
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