|
|
a72a7c |
From 9c4eaf150662ad40607923389d4519bc83b93540 Mon Sep 17 00:00:00 2001
|
|
|
a72a7c |
From: Sebastien <seb@fedora-2.home>
|
|
|
a72a7c |
Date: Sat, 15 Oct 2022 14:24:22 +0200
|
|
|
a72a7c |
Subject: [PATCH] Fix size_t overflow in sa_common.c (GHSL-2022-074)
|
|
|
a72a7c |
|
|
|
a72a7c |
allocate_structures function located in sa_common.c insufficiently
|
|
|
a72a7c |
checks bounds before arithmetic multiplication allowing for an
|
|
|
a72a7c |
overflow in the size allocated for the buffer representing system
|
|
|
a72a7c |
activities.
|
|
|
a72a7c |
|
|
|
a72a7c |
This patch checks that the post-multiplied value is not greater than
|
|
|
a72a7c |
UINT_MAX.
|
|
|
a72a7c |
|
|
|
a72a7c |
Signed-off-by: Sebastien <seb@fedora-2.home>
|
|
|
a72a7c |
---
|
|
|
a72a7c |
common.c | 25 +++++++++++++++++++++++++
|
|
|
a72a7c |
common.h | 2 ++
|
|
|
a72a7c |
sa_common.c | 6 ++++++
|
|
|
a72a7c |
3 files changed, 33 insertions(+)
|
|
|
a72a7c |
|
|
|
a72a7c |
diff --git a/common.c b/common.c
|
|
|
a72a7c |
index 81c77624..1a84b052 100644
|
|
|
a72a7c |
--- a/common.c
|
|
|
a72a7c |
+++ b/common.c
|
|
|
a72a7c |
@@ -1655,4 +1655,29 @@ int parse_values(char *strargv, unsigned char bitmap[], int max_val, const char
|
|
|
a72a7c |
|
|
|
a72a7c |
return 0;
|
|
|
a72a7c |
}
|
|
|
a72a7c |
+
|
|
|
a72a7c |
+/*
|
|
|
a72a7c |
+ ***************************************************************************
|
|
|
a72a7c |
+ * Check if the multiplication of the 3 values may be greater than UINT_MAX.
|
|
|
a72a7c |
+ *
|
|
|
a72a7c |
+ * IN:
|
|
|
a72a7c |
+ * @val1 First value.
|
|
|
a72a7c |
+ * @val2 Second value.
|
|
|
a72a7c |
+ * @val3 Third value.
|
|
|
a72a7c |
+ ***************************************************************************
|
|
|
a72a7c |
+ */
|
|
|
a72a7c |
+void check_overflow(size_t val1, size_t val2, size_t val3)
|
|
|
a72a7c |
+{
|
|
|
a72a7c |
+ if ((unsigned long long) val1 *
|
|
|
a72a7c |
+ (unsigned long long) val2 *
|
|
|
a72a7c |
+ (unsigned long long) val3 > UINT_MAX) {
|
|
|
a72a7c |
+#ifdef DEBUG
|
|
|
a72a7c |
+ fprintf(stderr, "%s: Overflow detected (%llu). Aborting...\n",
|
|
|
a72a7c |
+ __FUNCTION__,
|
|
|
a72a7c |
+ (unsigned long long) val1 * (unsigned long long) val2 * (unsigned long long) val3);
|
|
|
a72a7c |
+#endif
|
|
|
a72a7c |
+ exit(4);
|
|
|
a72a7c |
+ }
|
|
|
a72a7c |
+}
|
|
|
a72a7c |
+
|
|
|
a72a7c |
#endif /* SOURCE_SADC undefined */
|
|
|
a72a7c |
diff --git a/common.h b/common.h
|
|
|
a72a7c |
index 55b6657d..e8ab98ab 100644
|
|
|
a72a7c |
--- a/common.h
|
|
|
a72a7c |
+++ b/common.h
|
|
|
a72a7c |
@@ -260,6 +260,8 @@ int check_dir
|
|
|
a72a7c |
(char *);
|
|
|
a72a7c |
|
|
|
a72a7c |
#ifndef SOURCE_SADC
|
|
|
a72a7c |
+void check_overflow
|
|
|
a72a7c |
+ (size_t, size_t, size_t);
|
|
|
a72a7c |
int count_bits
|
|
|
a72a7c |
(void *, int);
|
|
|
a72a7c |
int count_csvalues
|
|
|
a72a7c |
diff --git a/sa_common.c b/sa_common.c
|
|
|
a72a7c |
index 3699a840..b2cec4ad 100644
|
|
|
a72a7c |
--- a/sa_common.c
|
|
|
a72a7c |
+++ b/sa_common.c
|
|
|
a72a7c |
@@ -459,7 +459,13 @@ void allocate_structures(struct activity *act[])
|
|
|
a72a7c |
int i, j;
|
|
|
a72a7c |
|
|
|
a72a7c |
for (i = 0; i < NR_ACT; i++) {
|
|
|
a72a7c |
+
|
|
|
a72a7c |
if (act[i]->nr_ini > 0) {
|
|
|
a72a7c |
+
|
|
|
a72a7c |
+ /* Look for a possible overflow */
|
|
|
a72a7c |
+ check_overflow((size_t) act[i]->msize, (size_t) act[i]->nr_ini,
|
|
|
a72a7c |
+ (size_t) act[i]->nr2);
|
|
|
a72a7c |
+
|
|
|
a72a7c |
for (j = 0; j < 3; j++) {
|
|
|
a72a7c |
SREALLOC(act[i]->buf[j], void,
|
|
|
a72a7c |
(size_t) act[i]->msize * (size_t) act[i]->nr_ini * (size_t) act[i]->nr2);
|