advanced-microcode-patching / shiva

A custom ELF linker/loader for installing ET_REL binary patches at runtime
Other
152 stars 13 forks source link

Support for data only patches #2

Closed elfmaster closed 1 year ago

elfmaster commented 1 year ago

Shiva fails to load a module if it has a 0 byte text segment. This means that the following patch will fail to load.

int bss_buffer[64];

Unless you include a body of code with it, even if the code isn't used.

int bss_buffer[64];

void empty(void)
{
}

Fix this so that we can submit data-only patches, as we are intended to be able to.

elfmaster commented 1 year ago

Now fixed with the following patch at the end of calculate_text_size in the event that the patch contains no .text data, we still create an empty text image of 4096 bytes and set the linker->flags value of SHIVA_MODULE_F_DUMMY_TEXT to indicate that it doesn't contain anything.

+       if (linker->text_size == 0) {
+               linker->flags |= SHIVA_MODULE_F_DUMMY_TEXT;
+               linker->text_size = 4096;
+       }
elfmaster commented 1 year ago

Closing.