All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Prasad J Pandit <pjp@fedoraproject.org>,
	Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PULL 3/7] ps2: check PS2Queue pointers in post_load routine
Date: Mon, 29 Jan 2018 11:23:16 +0100	[thread overview]
Message-ID: <20180129102320.21534-4-kraxel@redhat.com> (raw)
In-Reply-To: <20180129102320.21534-1-kraxel@redhat.com>

From: Prasad J Pandit <pjp@fedoraproject.org>

During Qemu guest migration, a destination process invokes ps2
post_load function. In that, if 'rptr' and 'count' values were
invalid, it could lead to OOB access or infinite loop issue.
Add check to avoid it.

Reported-by: Cyrille Chatras <cyrille.chatras@orange.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
Message-id: 20171116075155.22378-1-ppandit@redhat.com
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/input/ps2.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

diff --git a/hw/input/ps2.c b/hw/input/ps2.c
index f388a23c8e..de171a28dd 100644
--- a/hw/input/ps2.c
+++ b/hw/input/ps2.c
@@ -1225,24 +1225,21 @@ static void ps2_common_reset(PS2State *s)
 static void ps2_common_post_load(PS2State *s)
 {
     PS2Queue *q = &s->queue;
-    int size;
-    int i;
-    int tmp_data[PS2_QUEUE_SIZE];
+    uint8_t i, size;
+    uint8_t tmp_data[PS2_QUEUE_SIZE];
 
     /* set the useful data buffer queue size, < PS2_QUEUE_SIZE */
-    size = q->count > PS2_QUEUE_SIZE ? 0 : q->count;
+    size = (q->count < 0 || q->count > PS2_QUEUE_SIZE) ? 0 : q->count;
 
     /* move the queue elements to the start of data array */
-    if (size > 0) {
-        for (i = 0; i < size; i++) {
-            /* move the queue elements to the temporary buffer */
-            tmp_data[i] = q->data[q->rptr];
-            if (++q->rptr == 256) {
-                q->rptr = 0;
-            }
+    for (i = 0; i < size; i++) {
+        if (q->rptr < 0 || q->rptr >= sizeof(q->data)) {
+            q->rptr = 0;
         }
-        memcpy(q->data, tmp_data, size);
+        tmp_data[i] = q->data[q->rptr++];
     }
+    memcpy(q->data, tmp_data, size);
+
     /* reset rptr/wptr/count */
     q->rptr = 0;
     q->wptr = size;
-- 
2.9.3

  parent reply	other threads:[~2018-01-29 10:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-29 10:23 [Qemu-devel] [PULL 0/7] Input 20180129 v2 patches Gerd Hoffmann
2018-01-29 10:23 ` [Qemu-devel] [PULL 1/7] input: add mouse side buttons to virtio input Gerd Hoffmann
2018-01-29 10:23 ` [Qemu-devel] [PULL 2/7] input: virtio: don't send mouse wheel event twice Gerd Hoffmann
2018-01-29 10:23 ` Gerd Hoffmann [this message]
2018-01-29 10:23 ` [Qemu-devel] [PULL 4/7] hw: convert ps2 device to keycodemapdb Gerd Hoffmann
2018-01-29 10:23 ` [Qemu-devel] [PULL 5/7] hw: convert the escc " Gerd Hoffmann
2022-03-31 10:03   ` Peter Maydell
2022-03-31 10:10     ` Daniel P. Berrangé
2018-01-29 10:23 ` [Qemu-devel] [PULL 6/7] ui: fix alphabetical ordering of keymaps Gerd Hoffmann
2018-01-29 10:23 ` [Qemu-devel] [PULL 7/7] hw: convert virtio-input-hid device to keycodemapdb Gerd Hoffmann
2018-01-29 17:17 ` [Qemu-devel] [PULL 0/7] Input 20180129 v2 patches Peter Maydell
  -- strict thread matches above, loose matches on Subject: below --
2018-01-26  9:13 [Qemu-devel] [PULL 0/7] Input 20180126 patches Gerd Hoffmann
2018-01-26  9:13 ` [Qemu-devel] [PULL 3/7] ps2: check PS2Queue pointers in post_load routine Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180129102320.21534-4-kraxel@redhat.com \
    --to=kraxel@redhat.com \
    --cc=pjp@fedoraproject.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.