Skip to contentSkip to conversation

ps2: check PS2Queue wptr pointer in post_load routine

PATCH In review liujunjie 3 participants 4 messages Jun 7, 2018 – Jun 18, 2018

lore
Share & tools
lore

liujunjie

author
#0 lore raw

PATCH 1/1 ps2: check PS2Queue wptr pointer in post_load routine

In commit 802cbcb7300, most issues have been fixed when qemu guest migration. But the queue size still need to check whether is equal to PS2_QUEUE_SIZE. If yes, the wptr should set as 0. Or, wptr would larger than PS2_QUEUE_SIZE and never come back when ps2_queue_noirq is called. This could lead to OOB access, add check to avoid it.

---
 hw/input/ps2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/input/ps2.c +1 -1
index eeec618..fdfcadf 100644
@@ -927,7 +927,7 @@ static void ps2_common_post_load(PS2State *s)
 
     /* reset rptr/wptr/count */
     q->rptr = 0;
-    q->wptr = size;
+    q->wptr = (size == PS2_QUEUE_SIZE) ? 0 : size;
     q->count = size;
     s->update_irq(s->update_arg, q->count != 0);
 }
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines

-----Original Message-----
From: liujunjie (A)
Sent: Thursday, June 07, 2018 4:03 PM
To: [email protected]; [email protected]
Cc: Gonglei (Arei) <[email protected]>; wangxin (U) <[email protected]>; Huangweidong (C) <[email protected]>; fangying <[email protected]>; [email protected]; liujunjie (A) <[email protected]>
Subject: [PATCH] ps2: check PS2Queue wptr pointer in post_load routine

In commit 802cbcb7300, most issues have been fixed when qemu guest migration. But the queue size still need to check whether is equal to PS2_QUEUE_SIZE. If yes, the wptr should set as 0. Or, wptr would larger than PS2_QUEUE_SIZE and never come back when ps2_queue_noirq is called. This could lead to OOB access, add check to avoid it.

---
 hw/input/ps2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/input/ps2.c +0 -0
index eeec618..fdfcadf 100644

hw/input/ps2.c static void ps2_common_post_load(PS2State *s)

Quoted 9 lines
hw/input/ps2.c +1 -2
@@ -927,7 +927,7 @@ static void ps2_common_post_load(PS2State *s)
 
     /* reset rptr/wptr/count */
     q->rptr = 0;
-    q->wptr = size;
+    q->wptr = (size == PS2_QUEUE_SIZE) ? 0 : size;
     q->count = size;
     s->update_irq(s->update_arg, q->count != 0);
 }
--
#2 lore raw
In reply to liujunjie

ping

Quoted 35 lines

-----Original Message-----
From: liujunjie (A)
Sent: Thursday, June 07, 2018 4:03 PM
To: [email protected]; [email protected]
Cc: Gonglei (Arei) <[email protected]>; wangxin (U) <[email protected]>; Huangweidong (C) <[email protected]>; fangying <[email protected]>; [email protected]; liujunjie (A) <[email protected]>
Subject: [PATCH] ps2: check PS2Queue wptr pointer in post_load routine

In commit 802cbcb7300, most issues have been fixed when qemu guest migration. But the queue size still need to check whether is equal to PS2_QUEUE_SIZE. If yes, the wptr should set as 0. Or, wptr would larger than PS2_QUEUE_SIZE and never come back when ps2_queue_noirq is called. This could lead to OOB access, add check to avoid it.

---
 hw/input/ps2.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/input/ps2.c +1 -2
@@ -927,7 +927,7 @@ static void ps2_common_post_load(PS2State *s)
 
     /* reset rptr/wptr/count */
     q->rptr = 0;
-    q->wptr = size;
+    q->wptr = (size == PS2_QUEUE_SIZE) ? 0 : size;
     q->count = size;
     s->update_irq(s->update_arg, q->count != 0);  }
--

1.8.3.1

#3 lore raw
Quoted 1 line · liujunjie (A)

ping

Not much activity on input devices, so we have rare pull requests ...

Preparing one now, with this patch added.

cheers,
Gerd