Does arbitrary data write to the ELF file violate the ELF specification?

I would like to add some information to the ELF file, but ideally this should be done so that the program can easily read this information without understanding ELF or using tools outside the usual standard language library. I thought of simply adding this data to the end of the ELF file (with some kind of sentinel signal to indicate the beginning of the data so that the reader could just look back to the sentinel part), but I wanted to make sure that it wasn’t, t violate the ELF specification first . I don't care if any particular bootloader works with such added data; I want to know if the ELF specification itself guarantees anything so that I can know that the various ELF compatible forklifts will be happy with it.

I see that such questions were asked earlier, but either assuming that this addition is in order, or without direct answers:

As far as I can tell, the ELF specification is here:

I could not determine with a few searches whether the property that I want is uniquely resolved by this specification.

+6
source share
2 answers

The specification actually says nothing about this, so it can be argued that "this undefined behavior has finite data." On the other hand, the ELF specification speaks quite clearly about its expectations: "sections and segments do not have a specific order. Only the ELF header has a fixed position in the file." This gives enough room for embedding data anyway, using a section or doing without it [this is data without links!].

This "data freedom" has been used since at least the late 1980s; consider "self-extracting archives" where the common code separator for unpacking is freed up on the final piece of data.

In fact, you can find such an implicit function even in non-executable data formats such as RIFF and PNG. Of course, not all formats allow this; in particular those where the data is defined to run before EOF, and not for a fixed length stored in some header. (Consider ZIP: adding data is not possible, but adding is what causes EXE-ZIP to be read by both (unmodified) decompression programs and operating systems.)

There is only one drawback of using such data without a link: when reading and saving a file, you may lose this data.

+7
source

You can add additional data to ELF files (since you can add new segments and new sections to ELF), but you must (or improve) the tools to work with your "improved" ELFs, and this can be a significant burden. And don't forget to document well (if possible, in a freely accessible document) what you are doing.

0
source

Source: https://habr.com/ru/post/912933/


All Articles