From: "cron2 (Code Review)" Date: Fri, 12 Dec 2025 12:06:31 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <8ebe554906d200be81ffd7afbc4eba1fd8ab1fed-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Mt/C0OZaENg="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: buffer: Change limits for array_mult_safe List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --Mt/C0OZaENg= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#2) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1436?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: buffer: Change limits for array_mult_safe ...................................................................... buffer: Change limits for array_mult_safe - Lower the limit to 1GB on 32bit systems. The limit of 4GB-1 makes no sense on systems that usually don't allow a single process to allocate anything near to this limit. - Increate the limit from 4GB-1 to 4GB on other systems. It makes no difference in protection but makes it much easier to use the limit in other contexts, e.g. if dividing it. Change-Id: I4f95edd7ce2098180aa620a231727217f333a12d Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1436 Message-Id: <20251212100920.7671-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg35= 044.html Signed-off-by: Gert Doering --- M src/openvpn/buffer.c M src/openvpn/buffer.h 2 files changed, 13 insertions(+), 1 deletion(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/1436/2 diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index 293622f..40baca6 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -39,7 +39,7 @@ size_t array_mult_safe(const size_t m1, const size_t m2, const size_t extra) { - const size_t limit =3D 0xFFFFFFFF; + const size_t limit =3D ALLOC_SIZE_MAX; unsigned long long res =3D (unsigned long long)m1 * (unsigned long long)m2 + (unsigned long l= ong)extra; if (unlikely(m1 > limit) || unlikely(m2 > limit) || unlikely(extra > l= imit) diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index ab2a29d..1dbe0b2 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -1044,6 +1044,18 @@ * Allocate memory to hold a structure */ +/* When allocating arrays make sure we do not use a excessive amount + * of memory. + */ +#if UINTPTR_MAX <=3D UINT32_MAX +/* 1 GB on 32bit systems, they usually can only allocate 2 GB for the + * whole process. + */ +#define ALLOC_SIZE_MAX (1u << 30) +#else +#define ALLOC_SIZE_MAX ((size_t)1 << 32) /* 4 GB */ +#endif + #define ALLOC_OBJ(dptr, type) \ { \ check_malloc_return((dptr) =3D (type *)malloc(sizeof(type))); \ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1436?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I4f95edd7ce2098180aa620a231727217f333a12d Gerrit-Change-Number: 1436 Gerrit-PatchSet: 2 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --Mt/C0OZaENg= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #2 to the change originally created by flichtenhel= d.

View Change

The following approvals got outdated and were remove= d: Code-Review+2 by cron2

buffer: Change limits for array_mul=
t_safe

- Lower the limit to 1GB on 32bit systems.
The limit of = 4GB-1 makes no sense on systems that usually
don't allow a single = process to allocate anything near to
this limit.
- Increate the lim= it from 4GB-1 to 4GB on other systems. It
makes no difference in prote= ction but makes it much easier
to use the limit in other contexts, e.g= . if dividing it.

Change-Id: I4f95edd7ce2098180aa620a231727217f333a1= 2d
Signed-off-by: Frank Lichtenheld <frank@...2641...>
Acked-by= : Gert Doering <gert@...1296...>
Gerrit URL: https://gerrit.openvp= n.net/c/openvpn/+/1436
Message-Id: <20251212100920.7671-1-gert@...1826...= 6...>
URL: https://www.mail-archive.com/openvpn-devel@...1768...= ge.net/msg35044.html
Signed-off-by: Gert Doering <gert@...1296...>=
---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
2 files chan= ged, 13 insertions(+), 1 deletion(-)

git pull ss=
h://gerrit.openvpn.net:29418/openvpn refs/changes/36/1436/2
diff --=
git a/src/openvpn/buffer.c b/src/openvpn/buffer.c
index 293= 622f..40baca6 100644
--- a/src/openvpn/buffer.c
<= span>+++ b/src/openvpn/buffer.c
@@ -39,7 +39,7 @@ size_t
array_mult_safe(const size_t m1, const size= _t m2, const size_t extra)
{
- const size_t limit =3D 0xFFFFFFFF;
+ const size_t limit =3D ALLOC= _SIZE_MAX;
unsigned long long res =3D
= (unsigned long long)m1 * (unsigned long long)m2 + (unsigned long l= ong)extra;
if (unlikely(m1 > limit) || unlikely(m2 = > limit) || unlikely(extra > limit)
diff --git a/src/= openvpn/buffer.h b/src/openvpn/buffer.h
index ab2a29d..1dbe= 0b2 100644
--- a/src/openvpn/buffer.h
+++ b= /src/openvpn/buffer.h
@@ -1044,6 +1044,18 @@
* Allocate memory to hold a structure
*/

+/* When alloca= ting arrays make sure we do not use a excessive amount
+ * of memory.
+ */
+#if UINTPTR_MAX <=3D UINT32_MAX
+/* 1 GB on 32bit systems, they usually can only= allocate 2 GB for the
= + */
+#define ALLOC_S= IZE_MAX (1u << 30)
+#else
+#define A= LLOC_SIZE_MAX ((size_t)1 << 32) /* 4 GB */
+#endif
+
#define ALLOC_OBJ(dptr, type) = \
{ = \
check_mal= loc_return((dptr) =3D (type *)malloc(sizeof(type))); \

To view, visit change 1436. To unsubscribe, or for help writing= mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4f95edd7ce2098180aa620a2317= 27217f333a12d
Gerrit-Change-Number: 1436
Gerrit-PatchSet: 2
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --Mt/C0OZaENg=--