diff options
author | Florian Fainelli <f.fainelli@gmail.com> | 2017-06-30 16:34:22 -0700 |
---|---|---|
committer | Florian Fainelli <f.fainelli@gmail.com> | 2017-07-02 12:25:21 -0700 |
commit | 2cff779140b7b10256d722c9267f8a38c9fba088 (patch) | |
tree | d69de79adfdea662a29eec7f7792178b5ebe68de /kmodloader.c | |
parent | d54f38a2e2da5a29b00d19b490a87cc5ff910f33 (diff) | |
download | ubox-2cff779140b7b10256d722c9267f8a38c9fba088.tar.gz |
kmodloader: Check module endian before loading
If we manage to accidentally get a module installed that does not match
the system endianess (there is currently nothing preventing that in
OpenWrt/LEDE) we will hit a segmentation fault when doing this:
sh = (Elf32_Shdr *) (map + e->e_shoff);
because e->e_shoff will be wrongly encoded and this most likely will
result in an invalid offset to de-reference from.
Update elf_find_section() to check that the build time endianess of
kmodloader matches that of the module, otherwise nothing would work
really.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Diffstat (limited to 'kmodloader.c')
-rw-r--r-- | kmodloader.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/kmodloader.c b/kmodloader.c index 1a63c98..a6aa795 100644 --- a/kmodloader.c +++ b/kmodloader.c @@ -214,6 +214,19 @@ static int elf32_find_section(char *map, const char *section, unsigned int *offs static int elf_find_section(char *map, const char *section, unsigned int *offset, unsigned int *size) { int clazz = map[EI_CLASS]; + int endian = map[EI_DATA]; + +#if defined(__LITTLE_ENDIAN) + if (endian != ELFDATA2LSB) +#elif defined(__BIG_ENDIAN) + if (endian != ELFDATA2MSB) +#else +#error "unsupported endian" +#endif + { + ULOG_ERR("invalid endianess: %d\n", endian); + return -1; + } if (clazz == ELFCLASS32) return elf32_find_section(map, section, offset, size); |