Skip to contentSkip to conversation

range-checking bug in route.c

Openvpn-devel Gert Doering 2 participants 2 messages Dec 30, 2011 – Jan 4, 2012

lore
Share & tools
lore
#0 lore raw

Hi,

when implementing the missing helpers for saving/restoring ipv6 route option lists, I noticed that the existing code has safeguards against buffer overruns, but they do not work in all circumstances.

Imagine:

- source list: capacity = 20, n = 5 (only 5 items in there)
- destination list: capacity = 10

the check was "src->n > dst->capacity", which is OK, but then the full source list of "20 items" is copied over to dst - overrunning the memory.

Change to compare src->capacity to dst->capacity. (We could change the logic to copy only src->n items instead, and restore dst->capacity later on, but that's just another way to fix things :) ).

Applies to master, on top of the previous patch.

gert

Signature · 4 lines
USENET is *not* the non-clickable part of WWW!
                                                           //www.muc.de/~gert/
Gert Doering - Munich, Germany                             [email protected]...
fax: +49-89-35655025                        [email protected]...

From 95597af44714ccd350e849a0fc14e89db7e1529e Mon Sep 17 00:00:00 2001
From: Gert Doering <[email protected]...>
Date: Fri, 30 Dec 2011 21:42:13 +0100
Subject: [PATCH] Fix list-overrun checks in copy_route_[ipv6_]option_list()

The old code checks how many items are in use(!) in the source list, but then copies the full list over the destination memory arena. Check the source list *capacity*.

---
 route.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
route.c +4 -4
index e95292c..ce17f1f 100644
@@ -121,8 +121,8 @@ void
 copy_route_option_list (struct route_option_list *dest, const struct route_option_list *src)
 {
   const size_t src_size = array_mult_safe (sizeof(struct route_option), src->capacity, sizeof(struct route_option_list));
-  if (src->n > dest->capacity)
-    msg (M_FATAL, PACKAGE_NAME " ROUTE: (copy) number of route options in src (%d) is greater than route list capacity in dest (%d)", src->n, dest->capacity);
+  if (src->capacity > dest->capacity)
+    msg (M_FATAL, PACKAGE_NAME " ROUTE: (copy) number of route options in src (%d) is greater than route list capacity in dest (%d)", src->capacity, dest->capacity);
   memcpy (dest, src, src_size);
 }
 
@@ -131,8 +131,8 @@ copy_route_ipv6_option_list (struct route_ipv6_option_list *dest,
 			     const struct route_ipv6_option_list *src)
 {
   const size_t src_size = array_mult_safe (sizeof(struct route_ipv6_option), src->capacity, sizeof(struct route_ipv6_option_list));
-  if (src->n > dest->capacity)
-    msg (M_FATAL, PACKAGE_NAME " ROUTE: (copy) number of route options in src (%d) is greater than route list capacity in dest (%d)", src->n, dest->capacity);
+  if (src->capacity > dest->capacity)
+    msg (M_FATAL, PACKAGE_NAME " ROUTE: (copy) number of route options in src (%d) is greater than route list capacity in dest (%d)", src->capacity, dest->capacity);
   memcpy (dest, src, src_size);
 }
 
Signature · 1 line
1.7.3.4
#1 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 15 lines · Gert Doering

Hi,

when implementing the missing helpers for saving/restoring ipv6 route option lists, I noticed that the existing code has safeguards against buffer overruns, but they do not work in all circumstances.

Imagine:

- source list: capacity = 20, n = 5 (only 5 items in there) - destination list: capacity = 10

the check was "src->n > dst->capacity", which is OK, but then the full source list of "20 items" is copied over to dst - overrunning the memory.

Quoted 8 lines

Change to compare src->capacity to dst->capacity. (We could change the logic to copy only src->n items instead, and restore dst->capacity later on, but that's just another way to fix things :) ).

Applies to master, on top of the previous patch.

gert

ACK. Applied to master on -testing and -stable trees.

commit 6abb6cdd46e50b61452b1b2d3d796ab0061e9128

Author: Gert Doering <[email protected]...>
Date:   Fri Dec 30 21:42:13 2011 +0100

Fix list-overrun checks in copy_route_[ipv6_]option_list()

The old code checks how many items are in use(!) in the source list, but then copies the full list over the destination memory arena. Check the source list *capacity*.

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk8EP3gACgkQDC186MBRfrrLOACfXyrGjwgP/fSzL4eTXwWdEpXy P4kAoIX1H8HSV5lXw+wd3JCifUP/+ko8
=yjMx
-----END PGP SIGNATURE-----