mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
Fix tcache count maximum (BZ #24531)
The tcache counts[] array is a char, which has a very small range and thus may overflow. When setting tcache_count tunable, there is no overflow check. However the tunable must not be larger than the maximum value of the tcache counts[] array, otherwise it can overflow when filling the tcache. [BZ #24531] * malloc/malloc.c (MAX_TCACHE_COUNT): New define. (do_set_tcache_count): Only update if count is small enough. * manual/tunables.texi (glibc.malloc.tcache_count): Document max value.
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
2019-05-10 Wilco Dijkstra <wdijkstr@arm.com>
|
||||||
|
|
||||||
|
[BZ #24531]
|
||||||
|
* malloc/malloc.c (MAX_TCACHE_COUNT): New define.
|
||||||
|
(do_set_tcache_count): Only update if count is small enough.
|
||||||
|
* manual/tunables.texi (glibc.malloc.tcache_count): Document max value.
|
||||||
|
|
||||||
2019-05-10 Florian Weimer <fweimer@redhat.com>
|
2019-05-10 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
* nptl/sem_close.c (struct walk_closure): Define.
|
* nptl/sem_close.c (struct walk_closure): Define.
|
||||||
|
@ -2905,6 +2905,8 @@ typedef struct tcache_perthread_struct
|
|||||||
tcache_entry *entries[TCACHE_MAX_BINS];
|
tcache_entry *entries[TCACHE_MAX_BINS];
|
||||||
} tcache_perthread_struct;
|
} tcache_perthread_struct;
|
||||||
|
|
||||||
|
#define MAX_TCACHE_COUNT 127 /* Maximum value of counts[] entries. */
|
||||||
|
|
||||||
static __thread bool tcache_shutting_down = false;
|
static __thread bool tcache_shutting_down = false;
|
||||||
static __thread tcache_perthread_struct *tcache = NULL;
|
static __thread tcache_perthread_struct *tcache = NULL;
|
||||||
|
|
||||||
@ -5098,8 +5100,11 @@ do_set_tcache_max (size_t value)
|
|||||||
static __always_inline int
|
static __always_inline int
|
||||||
do_set_tcache_count (size_t value)
|
do_set_tcache_count (size_t value)
|
||||||
{
|
{
|
||||||
LIBC_PROBE (memory_tunable_tcache_count, 2, value, mp_.tcache_count);
|
if (value <= MAX_TCACHE_COUNT)
|
||||||
mp_.tcache_count = value;
|
{
|
||||||
|
LIBC_PROBE (memory_tunable_tcache_count, 2, value, mp_.tcache_count);
|
||||||
|
mp_.tcache_count = value;
|
||||||
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,8 +189,8 @@ per-thread cache. The default (and maximum) value is 1032 bytes on
|
|||||||
|
|
||||||
@deftp Tunable glibc.malloc.tcache_count
|
@deftp Tunable glibc.malloc.tcache_count
|
||||||
The maximum number of chunks of each size to cache. The default is 7.
|
The maximum number of chunks of each size to cache. The default is 7.
|
||||||
There is no upper limit, other than available system memory. If set
|
The upper limit is 127. If set to zero, the per-thread cache is effectively
|
||||||
to zero, the per-thread cache is effectively disabled.
|
disabled.
|
||||||
|
|
||||||
The approximate maximum overhead of the per-thread cache is thus equal
|
The approximate maximum overhead of the per-thread cache is thus equal
|
||||||
to the number of bins times the chunk count in each bin times the size
|
to the number of bins times the chunk count in each bin times the size
|
||||||
|
Reference in New Issue
Block a user