Skip to contentSkip to conversation

xen: fix potential integer overflow in queue_reply

PATCH Superseded Insu Yun 2 participants 5 messages Jan 18, 2016 Xen hypervisor interface

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Insu Yun

author
#0 lore raw

PATCH 1/1 xen: fix potential integer overflow in queue_reply

When len is greater than UINT_MAX - sizeof(*rb), in next allocation, it can overflow integer range and allocates small size of heap. After that, memcpy will overflow the allocated heap. Therefore, it needs to check the size of given length.

---
 drivers/xen/xenbus/xenbus_dev_frontend.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/xen/xenbus/xenbus_dev_frontend.c +1 -1
index 9433e46..b45ed69 100644
@@ -186,7 +186,7 @@ static int queue_reply(struct list_head *queue, const void *data, size_t len)
 {
 	struct read_buffer *rb;
 
-	if (len == 0)
+	if (len == 0 || len >= UINT_MAX - sizeof(*rb))
 		return 0;
 
 	rb = kmalloc(sizeof(*rb) + len, GFP_KERNEL);
Signature · 1 line
1.9.1
#1 lore raw
Quoted 4 lines · Insu Yun

When len is greater than UINT_MAX - sizeof(*rb), in next allocation, it can overflow integer range and allocates small size of heap. After that, memcpy will overflow the allocated heap. Therefore, it needs to check the size of given length.

[...]

drivers/xen/xenbus/xenbus_dev_frontend.c static int queue_reply(struct list_head *queue, const void *data, size_t len) · line 189

Quoted 8 lines
drivers/xen/xenbus/xenbus_dev_frontend.c +1 -1
@@ -186,7 +186,7 @@ static int queue_reply(struct list_head *queue, const void *data, size_t len)
 {
 	struct read_buffer *rb;
 
-	if (len == 0)
+	if (len == 0 || len >= UINT_MAX - sizeof(*rb))
                               ^^^^^^^^^^^^^^^^^^^^^^

Please check

len > XENSTORE_PAYLOAD_MAX

instead.

David

#2 lore raw
In reply to Insu Yun
Quoted 4 lines · Insu Yun

When len is greater than UINT_MAX - sizeof(*rb), in next allocation, it can overflow integer range and allocates small size of heap. After that, memcpy will overflow the allocated heap. Therefore, it needs to check the size of given length.

[...]

drivers/xen/xenbus/xenbus_dev_frontend.c static int queue_reply(struct list_head *queue, const void *data, size_t len) · line 189

Quoted 8 lines
drivers/xen/xenbus/xenbus_dev_frontend.c +1 -1
@@ -186,7 +186,7 @@ static int queue_reply(struct list_head *queue, const void *data, size_t len)
 {
 	struct read_buffer *rb;
 
-	if (len == 0)
+	if (len == 0 || len >= UINT_MAX - sizeof(*rb))
                               ^^^^^^^^^^^^^^^^^^^^^^

Please check

len > XENSTORE_PAYLOAD_MAX

instead.

David

#3 lore raw
Quoted 12 lines · David Vrabel
Quoted 4 lines · Insu Yun

When len is greater than UINT_MAX - sizeof(*rb), in next allocation, it can overflow integer range and allocates small size of heap. After that, memcpy will overflow the allocated heap. Therefore, it needs to check the size of given length.

[...]

Quoted 6 lines
drivers/xen/xenbus/xenbus_dev_frontend.c +0 -0
@@ -186,7 +186,7 @@ static int queue_reply(struct list_head *queue, const void *data, size_t len)
 {
 	struct read_buffer *rb;
 
Quoted 8 lines

drivers/xen/xenbus/xenbus_dev_frontend.c static int queue_reply(struct list_head *queue, const void *data, size_t len) · line 189

Quoted 2 lines
drivers/xen/xenbus/xenbus_dev_frontend.c +1 -1
-	if (len == 0)
+	if (len == 0 || len >= UINT_MAX - sizeof(*rb))
                               ^^^^^^^^^^^^^^^^^^^^^^

Please check

len > XENSTORE_PAYLOAD_MAX

instead.

And return -EINVAL in this case (not zero).

David

#4 lore raw
In reply to David Vrabel
Quoted 12 lines · David Vrabel
Quoted 4 lines · Insu Yun

When len is greater than UINT_MAX - sizeof(*rb), in next allocation, it can overflow integer range and allocates small size of heap. After that, memcpy will overflow the allocated heap. Therefore, it needs to check the size of given length.

[...]

Quoted 6 lines
drivers/xen/xenbus/xenbus_dev_frontend.c +0 -0
@@ -186,7 +186,7 @@ static int queue_reply(struct list_head *queue, const void *data, size_t len)
 {
 	struct read_buffer *rb;
 
Quoted 8 lines

drivers/xen/xenbus/xenbus_dev_frontend.c static int queue_reply(struct list_head *queue, const void *data, size_t len) · line 189

Quoted 2 lines
drivers/xen/xenbus/xenbus_dev_frontend.c +1 -1
-	if (len == 0)
+	if (len == 0 || len >= UINT_MAX - sizeof(*rb))
                               ^^^^^^^^^^^^^^^^^^^^^^

Please check

len > XENSTORE_PAYLOAD_MAX

instead.

And return -EINVAL in this case (not zero).

David