Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix memory misuse potential in json_stream_sampler #1360

Merged
merged 1 commit into from
Mar 4, 2024

Conversation

baallan
Copy link
Collaborator

@baallan baallan commented Feb 12, 2024

JSON_LIST_VALUE_setter now:
checks for malloc failure in asprintf
stops potential use after free on rec_type_name
puts out error messages if malloc fails
checks for rec_idx being set properly before use.
stops cross-iteration control value pollution.

This also shuts up several gcc warnings on gcc 4.8.

JSON_LIST_VALUE_setter now:
 checks for malloc failure in asprintf
 stops potential use after free on rec_type_name
 puts out error messages if malloc fails
 checks for rec_idx being set properly before use.
@tom95858
Copy link
Collaborator

@narategithub does this actually do anything. It seems like the metric lookup would fail if the memory allocation fails in asprintf. Also if the asprintf memory allocation fails LERROR would almost certainly fail as well. @baallan, is this fix to quell a compiler/tools warning?

@@ -379,14 +379,28 @@ int JSON_LIST_VALUE_setter(ldms_set_t set, ldms_mval_t list_mval,
LDMS_V_CHAR_ARRAY, 255);
break;
case JSON_DICT_VALUE:
rec_idx = -1;
if (!rec_type_name) {
rc = asprintf(&rec_type_name, "%s_record", (char *)ctxt);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tom95858 This patch covers the case that there is an error in asprintf (rc < 0) here. This case was not handled before this patch.

@baallan
Copy link
Collaborator Author

baallan commented Feb 13, 2024

@narategithub does this actually do anything. It seems like the metric lookup would fail if the memory allocation fails in asprintf. Also if the asprintf memory allocation fails LERROR would almost certainly fail as well. @baallan, is this fix to quell a compiler/tools warning?

@tom95858 This fix is to fix actual bugs (as listed). What drew inspection of the code was a build fail under -Werr, as noted.

Anecdotally, it's usually easy for asprint to succeed after a large data allocation request fails.
Separately, if the ovis_log implementation doesn't deliver at least the first 1k of error message, we need to fix it; it is trivial to guarantee delivery (read as 'avoid or go around fails in asprint') by including in each log object a base buffer of 1k. This buffer can be used until snprintf reports a truncation, or it can be used for a fallback to snprintf when asprintf reports alloc failure (probably preferred). Either ensures the first 1k bytes of any error get delivered, which is of course critical to explaining memory allocation failures.

@tom95858
Copy link
Collaborator

tom95858 commented Feb 13, 2024 via email

@baallan
Copy link
Collaborator Author

baallan commented Feb 13, 2024

@tom95858 this is hpc: independent of daemon process limits, we run out of memory regularly with memory hungry applications and there is almost never backing storage. However, memory reserved when the daemon starts is not subject to the whims of later application overallocating.

And, yes, as stated in the original PR description, this also addresses (validated) compiler warnings.

@tom95858 tom95858 merged commit 0e890f1 into ovis-hpc:OVIS-4 Mar 4, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants