vma/util: ASAN problem fix.#1150
Open
strike-kokhotnikov wants to merge 1 commit intoMellanox:masterfrom
Open
Conversation
|
Can one of the admins verify this patch? |
Greptile OverviewGreptile SummaryThis PR fixes ASAN compatibility issues that occur when both ASAN and libvma override libc functions during initialization. Key Changes:
Both changes are necessary to enable ASAN-based debugging and memory analysis for VMA. Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Init as VMA Initialization
participant SysVars as sys_vars.cpp
participant Utils as utils.cpp
participant LibC as libc (open/read)
Note over Init,LibC: ASAN-safe initialization
Init->>Utils: read_file_to_int(path, default)
Utils->>LibC: open(path, O_RDONLY)
LibC-->>Utils: fd
alt fd >= 0
Utils->>LibC: read(fd, buffer, 20)
LibC-->>Utils: bytes read
alt sscanf succeeds
Utils->>LibC: close(fd)
Utils-->>Init: parsed value
else sscanf fails
Utils->>LibC: close(fd)
Utils-->>Init: default_value
end
else fd < 0
Utils-->>Init: default_value
end
Init->>SysVars: env_to_cpuset("-1", cpu_set)
alt input is "-1"
SysVars->>SysVars: CPU_ZERO(cpu_set)
SysVars-->>Init: success (0)
else input is hex (0x...)
SysVars->>SysVars: hex_to_cpuset()
SysVars-->>Init: result
else input is list
SysVars->>SysVars: list_to_cpuset()
SysVars-->>Init: result
end
|
src/vma/util/sys_vars.cpp
Outdated
| { | ||
| int ret; | ||
| char* start = strdup(orig_start); // save the caller string from strtok destruction. | ||
| memset(&(cpu_set->__bits), 0, sizeof(cpu_set->__bits)); |
There was a problem hiding this comment.
style: directly accessing __bits field breaks encapsulation - use CPU_ZERO(cpu_set) instead
Suggested change
| memset(&(cpu_set->__bits), 0, sizeof(cpu_set->__bits)); | |
| CPU_ZERO(cpu_set); |
a5b54e4 to
9df92f3
Compare
9df92f3 to
6a9a480
Compare
src/vma/util/utils.cpp
Outdated
| if (sz > 0) { | ||
| int value; | ||
| c[sz] = '\0'; | ||
| int n = sscanf(reinterpret_cast<const char *>(&c), "%d", &value); |
There was a problem hiding this comment.
style: unnecessary cast - c already decays to const char*
Suggested change
| int n = sscanf(reinterpret_cast<const char *>(&c), "%d", &value); | |
| int n = sscanf(c, "%d", &value); |
src/vma/util/sys_vars.cpp
Outdated
| { | ||
| int ret; | ||
| char* start = strdup(orig_start); // save the caller string from strtok destruction. | ||
| CPU_ZERO(cpu_set); |
There was a problem hiding this comment.
style: CPU_ZERO will be called again in hex_to_cpuset or list_to_cpuset - move this call to after the "-1" check to avoid redundant operation
Suggested change
| CPU_ZERO(cpu_set); | |
| int len = strlen(orig_start); | |
| if (len == 2 && orig_start[0] == '-' && orig_start[1] == '1') { | |
| CPU_ZERO(cpu_set); | |
| return 0; | |
| } |
6a9a480 to
5a1dd09
Compare
5a1dd09 to
8883af9
Compare
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The changes is required to run the code compiled with ASAN. The problem is that both ASAN and libvma override libc standard functions and during initialization process some kind of "racing conditions" is possible. Function
read_file_to_intmost probably, has false-positive alert, but functionenv_to_cpusetis not. The default value-1is passed to fromenv_to_cpusettolist_to_cpusetfunction, which can't parse it correctly.What
Fix ASAN problems.
Why ?
ASAN can help to debug memory problems in some cases much more efficient, than e.g. valgrind.
Change type
What kind of change does this PR introduce?
Check list