Create a hook for inspecting program headers during library load
Roland McGrath
roland@hack.frob.com
Fri Oct 3 18:32:00 GMT 2014
> * elf/dl-load.c (dl-load-phdr.h): Include.
The (...) is only for citing where you are touching. There is no function,
variable, or macro called dl-load-phdr.h, so this is not right. I'm also
not crazy about the name, since it sounds more generic than it really is.
dl-machine-reject-phdr.h would be the most specific name.
> (open_verify): Add hook for phdr check.
This should be more clear about what the change is.
> * sysdeps/generic/dl-load-phdr.h: New file.
The new file can go into elf/ instead of sysdeps/generic/, because it is
only used by code that is compiled only in the elf/ subdirectory. The
sysdeps/generic/ directory is used for files that need to be found from
builds in multiple subdirectories.
If I'd written it, the whole log entry would look like:
* elf/dl-machine-reject-phdr.h: New file.
* elf/dl-load.c: #include that.
(open_verify): Call elf_machine_reject_phdr_p and ignore the file
if that returned false.
> + if (__glibc_unlikely (
> + elf_machine_reject_phdr_p (phdr, ehdr->e_phnum, fbp->buf, fbp->len,
> + fd, loader)))
The indentation for this should look like:
if (__glibc_unlikely (elf_machine_reject_phdr_p
(phdr, ehdr->e_phnum, fbp->buf, fbp->len,
fd, loader)))
> +/* Machine-dependent ELF loader functions.
This description is too generic for what's really here.
> +#ifndef _DL_LOAD_PHDR_H
> +#define _DL_LOAD_PHDR_H
We always define these to 1 rather than empty.
You should #include <stdbool.h> here before using bool.
> +/* Return true iff ELF program headers are incompatible with the running
> + host. */
> +static inline bool
> +elf_machine_reject_phdr_p (const ElfW(Phdr) *phdr, uint_fast16_t phnum,
> + const char *buf, size_t len, int fd,
> + struct link_map *map)
It would be better to swap the order of the last two arguments, so you
don't have to integer types next to each other where transposing them
accidentally would not produce a type error.
Thanks,
Roland
More information about the Libc-alpha
mailing list