mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-29 11:41:21 +03:00
Fix range check in do_tunable_update_val
Current implementation of tunables does not set arena_max and arena_test values. Any value provided by glibc.malloc.arena_max and glibc.malloc.arena_test parameters is ignored. These tunables have minval value set to 1 (see elf/dl-tunables.list file) and undefined maxval value. In that case default value (which is 0. see scripts/gen-tunables.awk) is being used to set maxval. For instance, generated tunable_list[] entry for arena_max is: (gdb) p *cur $1 = {name = 0x7ffff7df6217 "glibc.malloc.arena_max", type = {type_code = TUNABLE_TYPE_SIZE_T, min = 1, max = 0}, val = {numval = 0, strval = 0x0}, initialized = false, security_level = TUNABLE_SECLEVEL_SXID_IGNORE, env_alias = 0x7ffff7df622e "MALLOC_ARENA_MAX"} As a result, any value of glibc.malloc.arena_max is ignored by TUNABLE_SET_VAL_IF_VALID_RANGE macro __type min = (__cur)->type.min; <- initialized to 1 __type max = (__cur)->type.max; <- initialized to 0! if (min == max) <- false { min = __default_min; max = __default_max; } if ((__type) (__val) >= min && (__type) (val) <= max) <- false { (__cur)->val.numval = val; (__cur)->initialized = true; } Assigning correct min/max values at a build time fixes a problem. Plus, a bit of optimization: Setting of default min/max values for the given type at a run time might be eliminated. * elf/dl-tunables.c (do_tunable_update_val): Range checking fix. * scripts/gen-tunables.awk: Set unspecified minval and/or maxval values to correct default value for given type.
This commit is contained in:
committed by
Siddhesh Poyarekar
parent
592d5c7539
commit
cebcb9f864
@ -1,3 +1,9 @@
|
|||||||
|
2017-09-26 Alexey Makhalov <amakhalov@vmware.com>
|
||||||
|
|
||||||
|
* elf/dl-tunables.c (do_tunable_update_val): Range checking fix.
|
||||||
|
* scripts/gen-tunables.awk: Set unspecified minval and/or maxval
|
||||||
|
values to correct default value for given type.
|
||||||
|
|
||||||
2017-09-26 H.J. Lu <hongjiu.lu@intel.com>
|
2017-09-26 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
[BZ #22101]
|
[BZ #22101]
|
||||||
|
@ -89,18 +89,11 @@ get_next_env (char **envp, char **name, size_t *namelen, char **val,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TUNABLE_SET_VAL_IF_VALID_RANGE(__cur, __val, __type, __default_min, \
|
#define TUNABLE_SET_VAL_IF_VALID_RANGE(__cur, __val, __type) \
|
||||||
__default_max) \
|
|
||||||
({ \
|
({ \
|
||||||
__type min = (__cur)->type.min; \
|
__type min = (__cur)->type.min; \
|
||||||
__type max = (__cur)->type.max; \
|
__type max = (__cur)->type.max; \
|
||||||
\
|
\
|
||||||
if (min == max) \
|
|
||||||
{ \
|
|
||||||
min = __default_min; \
|
|
||||||
max = __default_max; \
|
|
||||||
} \
|
|
||||||
\
|
|
||||||
if ((__type) (__val) >= min && (__type) (val) <= max) \
|
if ((__type) (__val) >= min && (__type) (val) <= max) \
|
||||||
{ \
|
{ \
|
||||||
(__cur)->val.numval = val; \
|
(__cur)->val.numval = val; \
|
||||||
@ -120,17 +113,17 @@ do_tunable_update_val (tunable_t *cur, const void *valp)
|
|||||||
{
|
{
|
||||||
case TUNABLE_TYPE_INT_32:
|
case TUNABLE_TYPE_INT_32:
|
||||||
{
|
{
|
||||||
TUNABLE_SET_VAL_IF_VALID_RANGE (cur, val, int64_t, INT32_MIN, INT32_MAX);
|
TUNABLE_SET_VAL_IF_VALID_RANGE (cur, val, int64_t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TUNABLE_TYPE_UINT_64:
|
case TUNABLE_TYPE_UINT_64:
|
||||||
{
|
{
|
||||||
TUNABLE_SET_VAL_IF_VALID_RANGE (cur, val, uint64_t, 0, UINT64_MAX);
|
TUNABLE_SET_VAL_IF_VALID_RANGE (cur, val, uint64_t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TUNABLE_TYPE_SIZE_T:
|
case TUNABLE_TYPE_SIZE_T:
|
||||||
{
|
{
|
||||||
TUNABLE_SET_VAL_IF_VALID_RANGE (cur, val, uint64_t, 0, SIZE_MAX);
|
TUNABLE_SET_VAL_IF_VALID_RANGE (cur, val, uint64_t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TUNABLE_TYPE_STRING:
|
case TUNABLE_TYPE_STRING:
|
||||||
|
@ -1,6 +1,14 @@
|
|||||||
# Generate dl-tunable-list.h from dl-tunables.list
|
# Generate dl-tunable-list.h from dl-tunables.list
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
|
min_of["STRING"]="0"
|
||||||
|
max_of["STRING"]="0"
|
||||||
|
min_of["INT_32"]="INT32_MIN"
|
||||||
|
max_of["INT_32"]="INT32_MAX"
|
||||||
|
min_of["UINT_64"]="0"
|
||||||
|
max_of["UINT_64"]="UINT64_MAX"
|
||||||
|
min_of["SIZE_T"]="0"
|
||||||
|
max_of["SIZE_T"]="SIZE_MAX"
|
||||||
tunable=""
|
tunable=""
|
||||||
ns=""
|
ns=""
|
||||||
top_ns=""
|
top_ns=""
|
||||||
@ -43,10 +51,10 @@ $1 == "}" {
|
|||||||
types[top_ns,ns,tunable] = "STRING"
|
types[top_ns,ns,tunable] = "STRING"
|
||||||
}
|
}
|
||||||
if (!minvals[top_ns,ns,tunable]) {
|
if (!minvals[top_ns,ns,tunable]) {
|
||||||
minvals[top_ns,ns,tunable] = "0"
|
minvals[top_ns,ns,tunable] = min_of[types[top_ns,ns,tunable]]
|
||||||
}
|
}
|
||||||
if (!maxvals[top_ns,ns,tunable]) {
|
if (!maxvals[top_ns,ns,tunable]) {
|
||||||
maxvals[top_ns,ns,tunable] = "0"
|
maxvals[top_ns,ns,tunable] = max_of[types[top_ns,ns,tunable]]
|
||||||
}
|
}
|
||||||
if (!env_alias[top_ns,ns,tunable]) {
|
if (!env_alias[top_ns,ns,tunable]) {
|
||||||
env_alias[top_ns,ns,tunable] = "NULL"
|
env_alias[top_ns,ns,tunable] = "NULL"
|
||||||
|
Reference in New Issue
Block a user