Skip to content

Commit

Permalink
Fix a bug that could produce a segmentation fault when dumping the cr…
Browse files Browse the repository at this point in the history
…ash log with hipe enabled and natively compiled modules

When loading a module, code area is allocated and header fields code[MI_ATTR_SIZE] as well as code[MI_COMPILE_SIZE] are not cleared. They are only set later when freeze_code is called, if the module has attributes and compilation info, which should always be the case. When loading a native module (as a stub), code is allocated as well (to contain the stub functions), and code[MI_ATTR_SIZE] as well as code[MI_COMPILE_SIZE] are not cleared either. Yet, freeze_code will not be called (since there is no threaded code to freeze for native modules), and as a result, these header fields are never set. They can contain any garbage.

Later on, when writing a crash dump, the attributes and compilation info are dumped, using these particular header fields. If the size is garbage, the dump attribute function will iterate until it segfaults.

The fix consists in clearing code[MI_ATTR_SIZE] and code[MI_COMPILE_SIZE] in both cases (threaded code and native code). Even if non-native modules should contain code and attributes and therefore the values code[MI_ATTR_SIZE] and code[MI_COMPILE_SIZE] should be set by freeze_code, it seems cleaner and easier to maintain to clear the whole the header in the "initialize code area" section. As a result, crash dump will not segfault. Instead, native modules will have an empty attributes and compilation info section in the crash dump.
  • Loading branch information
pguyot committed Jul 6, 2010
1 parent 91078fb commit 089e48c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions erts/emulator/beam/beam_load.c
Expand Up @@ -1379,8 +1379,10 @@ read_code_header(LoaderState* stp)
stp->ci = MI_FUNCTIONS + stp->num_functions + 1;

stp->code[MI_ATTR_PTR] = 0;
stp->code[MI_ATTR_SIZE] = 0;
stp->code[MI_ATTR_SIZE_ON_HEAP] = 0;
stp->code[MI_COMPILE_PTR] = 0;
stp->code[MI_COMPILE_SIZE] = 0;
stp->code[MI_COMPILE_SIZE_ON_HEAP] = 0;
stp->code[MI_NUM_BREAKPOINTS] = 0;

Expand Down Expand Up @@ -5198,8 +5200,10 @@ erts_make_stub_module(Process* p, Eterm Mod, Eterm Beam, Eterm Info)

code[MI_NUM_FUNCTIONS] = n;
code[MI_ATTR_PTR] = 0;
code[MI_ATTR_SIZE] = 0;
code[MI_ATTR_SIZE_ON_HEAP] = 0;
code[MI_COMPILE_PTR] = 0;
code[MI_COMPILE_SIZE] = 0;
code[MI_COMPILE_SIZE_ON_HEAP] = 0;
code[MI_NUM_BREAKPOINTS] = 0;
code[MI_ON_LOAD_FUNCTION_PTR] = 0;
Expand Down

0 comments on commit 089e48c

Please sign in to comment.