|
|
f57669 |
Short description: CVE-2015-5220: calloc() returns non-zeroed memory.
|
|
|
f57669 |
Author(s): Ondrej Bilka
|
|
|
f57669 |
Origin: git://sourceware.org/git/glibc.git
|
|
|
f57669 |
Bug-RHEL: #1296453 (rhel-7.2.z), #1293976 (rhel-7.3), #1256285 (SRT)
|
|
|
f57669 |
Bug-Fedora: NA
|
|
|
f57669 |
Bug-Upstream: NA
|
|
|
f57669 |
Upstream status: committed
|
|
|
f57669 |
#
|
|
|
f57669 |
# commit e8349efd466cfedc0aa98be61d88ca8795c9e565
|
|
|
f57669 |
# Author: Ondřej Bílka <neleai@seznam.cz>
|
|
|
f57669 |
# Date: Mon Dec 9 17:25:19 2013 +0100
|
|
|
f57669 |
#
|
|
|
f57669 |
# Simplify perturb_byte logic.
|
|
|
f57669 |
#
|
|
|
f57669 |
diff --git a/malloc/malloc.c b/malloc/malloc.c
|
|
|
f57669 |
index 4821deb..ac8c3f6 100644
|
|
|
f57669 |
--- a/malloc/malloc.c
|
|
|
f57669 |
+++ b/malloc/malloc.c
|
|
|
f57669 |
@@ -1870,8 +1870,20 @@ static int check_action = DEFAULT_CHECK_ACTION;
|
|
|
f57669 |
|
|
|
f57669 |
static int perturb_byte;
|
|
|
f57669 |
|
|
|
f57669 |
-#define alloc_perturb(p, n) memset (p, (perturb_byte ^ 0xff) & 0xff, n)
|
|
|
f57669 |
-#define free_perturb(p, n) memset (p, perturb_byte & 0xff, n)
|
|
|
f57669 |
+static inline void
|
|
|
f57669 |
+alloc_perturb (char *p, size_t n)
|
|
|
f57669 |
+{
|
|
|
f57669 |
+ if (__glibc_unlikely (perturb_byte))
|
|
|
f57669 |
+ memset (p, perturb_byte ^ 0xff, n);
|
|
|
f57669 |
+}
|
|
|
f57669 |
+
|
|
|
f57669 |
+static inline void
|
|
|
f57669 |
+free_perturb (char *p, size_t n)
|
|
|
f57669 |
+{
|
|
|
f57669 |
+ if (__glibc_unlikely (perturb_byte))
|
|
|
f57669 |
+ memset (p, perturb_byte, n);
|
|
|
f57669 |
+}
|
|
|
f57669 |
+
|
|
|
f57669 |
|
|
|
f57669 |
|
|
|
f57669 |
#include <stap-probe.h>
|
|
|
f57669 |
@@ -3287,8 +3299,7 @@ _int_malloc(mstate av, size_t bytes)
|
|
|
f57669 |
}
|
|
|
f57669 |
check_remalloced_chunk(av, victim, nb);
|
|
|
f57669 |
void *p = chunk2mem(victim);
|
|
|
f57669 |
- if (__builtin_expect (perturb_byte, 0))
|
|
|
f57669 |
- alloc_perturb (p, bytes);
|
|
|
f57669 |
+ alloc_perturb (p, bytes);
|
|
|
f57669 |
return p;
|
|
|
f57669 |
}
|
|
|
f57669 |
}
|
|
|
f57669 |
@@ -3323,8 +3334,7 @@ _int_malloc(mstate av, size_t bytes)
|
|
|
f57669 |
victim->size |= NON_MAIN_ARENA;
|
|
|
f57669 |
check_malloced_chunk(av, victim, nb);
|
|
|
f57669 |
void *p = chunk2mem(victim);
|
|
|
f57669 |
- if (__builtin_expect (perturb_byte, 0))
|
|
|
f57669 |
- alloc_perturb (p, bytes);
|
|
|
f57669 |
+ alloc_perturb (p, bytes);
|
|
|
f57669 |
return p;
|
|
|
f57669 |
}
|
|
|
f57669 |
}
|
|
|
f57669 |
@@ -3403,8 +3413,7 @@ _int_malloc(mstate av, size_t bytes)
|
|
|
f57669 |
|
|
|
f57669 |
check_malloced_chunk(av, victim, nb);
|
|
|
f57669 |
void *p = chunk2mem(victim);
|
|
|
f57669 |
- if (__builtin_expect (perturb_byte, 0))
|
|
|
f57669 |
- alloc_perturb (p, bytes);
|
|
|
f57669 |
+ alloc_perturb (p, bytes);
|
|
|
f57669 |
return p;
|
|
|
f57669 |
}
|
|
|
f57669 |
|
|
|
f57669 |
@@ -3420,8 +3429,7 @@ _int_malloc(mstate av, size_t bytes)
|
|
|
f57669 |
victim->size |= NON_MAIN_ARENA;
|
|
|
f57669 |
check_malloced_chunk(av, victim, nb);
|
|
|
f57669 |
void *p = chunk2mem(victim);
|
|
|
f57669 |
- if (__builtin_expect (perturb_byte, 0))
|
|
|
f57669 |
- alloc_perturb (p, bytes);
|
|
|
f57669 |
+ alloc_perturb (p, bytes);
|
|
|
f57669 |
return p;
|
|
|
f57669 |
}
|
|
|
f57669 |
|
|
|
f57669 |
@@ -3545,8 +3553,7 @@ _int_malloc(mstate av, size_t bytes)
|
|
|
f57669 |
}
|
|
|
f57669 |
check_malloced_chunk(av, victim, nb);
|
|
|
f57669 |
void *p = chunk2mem(victim);
|
|
|
f57669 |
- if (__builtin_expect (perturb_byte, 0))
|
|
|
f57669 |
- alloc_perturb (p, bytes);
|
|
|
f57669 |
+ alloc_perturb (p, bytes);
|
|
|
f57669 |
return p;
|
|
|
f57669 |
}
|
|
|
f57669 |
}
|
|
|
f57669 |
@@ -3649,8 +3656,7 @@ _int_malloc(mstate av, size_t bytes)
|
|
|
f57669 |
}
|
|
|
f57669 |
check_malloced_chunk(av, victim, nb);
|
|
|
f57669 |
void *p = chunk2mem(victim);
|
|
|
f57669 |
- if (__builtin_expect (perturb_byte, 0))
|
|
|
f57669 |
- alloc_perturb (p, bytes);
|
|
|
f57669 |
+ alloc_perturb (p, bytes);
|
|
|
f57669 |
return p;
|
|
|
f57669 |
}
|
|
|
f57669 |
}
|
|
|
f57669 |
@@ -3684,8 +3690,7 @@ _int_malloc(mstate av, size_t bytes)
|
|
|
f57669 |
|
|
|
f57669 |
check_malloced_chunk(av, victim, nb);
|
|
|
f57669 |
void *p = chunk2mem(victim);
|
|
|
f57669 |
- if (__builtin_expect (perturb_byte, 0))
|
|
|
f57669 |
- alloc_perturb (p, bytes);
|
|
|
f57669 |
+ alloc_perturb (p, bytes);
|
|
|
f57669 |
return p;
|
|
|
f57669 |
}
|
|
|
f57669 |
|
|
|
f57669 |
@@ -3705,7 +3710,7 @@ _int_malloc(mstate av, size_t bytes)
|
|
|
f57669 |
*/
|
|
|
f57669 |
else {
|
|
|
f57669 |
void *p = sysmalloc(nb, av);
|
|
|
f57669 |
- if (p != NULL && __builtin_expect (perturb_byte, 0))
|
|
|
f57669 |
+ if (p != NULL)
|
|
|
f57669 |
alloc_perturb (p, bytes);
|
|
|
f57669 |
return p;
|
|
|
f57669 |
}
|
|
|
f57669 |
@@ -3798,8 +3803,7 @@ _int_free(mstate av, mchunkptr p, int have_lock)
|
|
|
f57669 |
}
|
|
|
f57669 |
}
|
|
|
f57669 |
|
|
|
f57669 |
- if (__builtin_expect (perturb_byte, 0))
|
|
|
f57669 |
- free_perturb (chunk2mem(p), size - 2 * SIZE_SZ);
|
|
|
f57669 |
+ free_perturb (chunk2mem(p), size - 2 * SIZE_SZ);
|
|
|
f57669 |
|
|
|
f57669 |
set_fastchunks(av);
|
|
|
f57669 |
unsigned int idx = fastbin_index(size);
|
|
|
f57669 |
@@ -3881,8 +3885,7 @@ _int_free(mstate av, mchunkptr p, int have_lock)
|
|
|
f57669 |
goto errout;
|
|
|
f57669 |
}
|
|
|
f57669 |
|
|
|
f57669 |
- if (__builtin_expect (perturb_byte, 0))
|
|
|
f57669 |
- free_perturb (chunk2mem(p), size - 2 * SIZE_SZ);
|
|
|
f57669 |
+ free_perturb (chunk2mem(p), size - 2 * SIZE_SZ);
|
|
|
f57669 |
|
|
|
f57669 |
/* consolidate backward */
|
|
|
f57669 |
if (!prev_inuse(p)) {
|