KEMBAR78
Initialize rem_* in DwarfParser.parseInstructions. by krk · Pull Request #1039 · async-profiler/async-profiler · GitHub
Skip to content

Conversation

krk
Copy link
Contributor

@krk krk commented Oct 23, 2024

Description

rem_* variables may not be initialized in all code paths.

How has this been tested?

make test

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

src/dwarf.cpp Outdated
u32 rem_cfa_reg = 0;
int rem_cfa_off = 0;
int rem_fp_off = 0;
int rem_pc_off = 0;
Copy link
Member

Choose a reason for hiding this comment

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

What problem does this fix?
rem values are valid only after they have been assigned to by DW_CFA_remember_state instruction. Otherwise, 0 is just as much garbage as any other random value.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is from a static analyzer finding. Hypothetically, there may be a corrupt dwarf file, causing uninitialized values to be used, which would add an invalid frame description.

Copy link
Member

Choose a reason for hiding this comment

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

I understand. My point is it's not a fix anyway. I.e., when using 0 instead of uninitialized values, it will be just a similar invalid frame descriptor.

Copy link
Member

Choose a reason for hiding this comment

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

Initializing with an empty frame descriptor would be slightly better, but does not change the situation fundamentally. I mean, bogus dwarf will result in an invalid or truncated stack trace anyway.

Copy link
Contributor Author

@krk krk Oct 25, 2024

Choose a reason for hiding this comment

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

I was able to make DwarfParser use uninitialized variables with this eh_frame_hdr, which could lead to undefined behavior:

00000000: 0103 0333 6100 0000 0100 0000 0100 0000  ...3a...........
00000010: 3000 0000 0000 0000 0000 0000 0000 0000  0...............
00000020: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000030: 1400 0000 0400 0000 0900 0000 0400 0000  ................
00000040: 000b 0000 00                             .....
DwarfParser p("name", 0, eh_frame_hdr);

I haven't investigated if invalid or malicious values could lead to a crash.

Updated the code to use the empty frame descriptor.

@apangin apangin merged commit 116504c into async-profiler:master Oct 26, 2024
2 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.

2 participants