Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete ELF support #64

Open
d-e-s-o opened this issue Mar 8, 2023 · 3 comments
Open

Incomplete ELF support #64

d-e-s-o opened this issue Mar 8, 2023 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@d-e-s-o
Copy link
Collaborator

d-e-s-o commented Mar 8, 2023

It appears as if the ELF parser does not handle all possible values of e_shstrndx correctly:

https://github.com/libbpf/blazesym/blob/master/src/elf/parser.rs#L192-L207

ELF(5) states:

       e_shstrndx
              This  member  holds the section header table index of the entry associ‐
              ated with the section name string table.  If the file  has  no  section
              name string table, this member holds the value SHN_UNDEF.

              If  the  index  of  section name string table section is larger than or
              equal to SHN_LORESERVE (0xff00), this member holds SHN_XINDEX  (0xffff)
              and  the real index of the section name string table section is held in
              the sh_link member of the initial entry in section header table.   Oth‐
              erwise, the sh_link member of the initial entry in section header table
              contains the value zero.

So we may have to special case SHN_XINDEX.

@danielocfb danielocfb changed the title Incomplete handling of e_shstrndx in ELF parser Incomplete ELF support May 31, 2023
@danielocfb
Copy link
Collaborator

Our string lookup logic is also questionable. See #190 (comment)

@danielocfb danielocfb added the bug Something isn't working label Jun 7, 2023
@danielocfb danielocfb added the help wanted Extra attention is needed label Jun 23, 2023
danielocfb pushed a commit to danielocfb/blazesym that referenced this issue Oct 30, 2023
TODO: NEEDS TEST!

Our ELF support is incomplete. One issue we have is that we cannot
handle more than 0xff00 section headers, because ELF special cases
anything above this value.
This change fixes this very shortcoming, by using the correct sequence
of steps for inferring the number of section headers.

Refs: libbpf#64

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit to d-e-s-o/blazesym that referenced this issue Oct 31, 2023
Our ELF support is incomplete. One issue we have is that we cannot
handle more than 0xff00 section headers, because ELF special cases
anything above this value.
This change fixes this very shortcoming, by using the correct sequence
of steps for inferring the number of section headers.

Refs: libbpf#64

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit to d-e-s-o/blazesym that referenced this issue Oct 31, 2023
Our ELF support is incomplete. One issue we have is that we cannot
handle more than 0xff00 section headers, because ELF special cases
anything above this value.
This change fixes this very shortcoming, by using the correct sequence
of steps for inferring the number of section headers.

Refs: libbpf#64

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit to d-e-s-o/blazesym that referenced this issue Oct 31, 2023
Our ELF support is incomplete. One issue we have is that we cannot
handle more than 0xff00 section headers, because ELF special cases
anything above this value.
This change fixes this very shortcoming, by using the correct sequence
of steps for inferring the number of section headers.

Refs: libbpf#64

Signed-off-by: Daniel Müller <[email protected]>
@danielocfb
Copy link
Collaborator

For reference, over in #384 (review) the following case was also mentioned:

For extended program header table numbering the scheme is similar, with
the e_phnum field of the executable header holding the value PN_XNUM
(0xFFFF) and the sh_link field of the zeroth section header table holding
the actual number of program header table entries.

danielocfb pushed a commit that referenced this issue Nov 1, 2023
Our ELF support is incomplete. One issue we have is that we cannot
handle more than 0xff00 section headers, because ELF special cases
anything above this value.
This change fixes this very shortcoming, by using the correct sequence
of steps for inferring the number of section headers.

Refs: #64

Signed-off-by: Daniel Müller <[email protected]>
@danielocfb
Copy link
Collaborator

We should also check what happens when there are more than 0xffff sections and we try to access one via the Elf64_Sym.st_shndx member (which is 16 bits in size). See #389 (comment)

d-e-s-o added a commit to d-e-s-o/blazesym that referenced this issue Nov 2, 2023
Our ELF support is incomplete. One issue we have is that we cannot
handle a e_shstrndx value greater than 0xff00, because ELF special cases
anything above this value.
This change fixes this very shortcoming, by using the correct sequence
of steps for retrieving the actual value.

Refs: libbpf#64

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit that referenced this issue Nov 2, 2023
Our ELF support is incomplete. One issue we have is that we cannot
handle a e_shstrndx value greater than 0xff00, because ELF special cases
anything above this value.
This change fixes this very shortcoming, by using the correct sequence
of steps for retrieving the actual value.

Refs: #64

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit to d-e-s-o/blazesym that referenced this issue Nov 2, 2023
Our ELF support is incomplete. One issue we have is that we cannot
handle more than 0xffff program headers, because ELF special cases
anything above this value.
This change fixes this very shortcoming, by using the correct sequence
of steps for retrieving the actual value.

Refs: libbpf#64

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit to d-e-s-o/blazesym that referenced this issue Nov 2, 2023
Our ELF support is incomplete. One issue we have is that we cannot
handle more than 0xffff program headers, because ELF special cases
anything above this value.
This change fixes this very shortcoming, by using the correct sequence
of steps for retrieving the actual value.

Refs: libbpf#64

Signed-off-by: Daniel Müller <[email protected]>
d-e-s-o added a commit that referenced this issue Nov 2, 2023
Our ELF support is incomplete. One issue we have is that we cannot
handle more than 0xffff program headers, because ELF special cases
anything above this value.
This change fixes this very shortcoming, by using the correct sequence
of steps for retrieving the actual value.

Refs: #64

Signed-off-by: Daniel Müller <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants