Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 470882 - dev-libs/libelf: ELF_C_RDWR doesn't allow you to change ELF Program headers.
Summary: dev-libs/libelf: ELF_C_RDWR doesn't allow you to change ELF Program headers.
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Library (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: No maintainer - Look at https://wiki.gentoo.org/wiki/Project:Proxy_Maintainers if you want to take care of it
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-05-21 14:42 UTC by Anthony Basile
Modified: 2023-01-28 20:08 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Basile gentoo-dev 2013-05-21 14:42:12 UTC
This bug is a result of an analysis of bug #465238.  There sys-apps/elfix doesn't compile against dev-libs/libelf because the latter lacks ELF_C_RDWR_MMAP.  This is a problem on uclibc systems where one cannot build dev-libs/elfutils due to numerous glibc-isms (some easily avoidable, others not).

libelf does provide ELF_C_RDWR, but it doesn't work.  (Interestingly enough, it also does not work with elfutils, although there ELF_C_RDWR_MMAP does.)

Here's a little poc to demonstrate the problem --- its reduced code with no sanity checks.  It simply toggles the SEGMEXEC flag on any program header marked PT_PAX_FLAGS.  Replace ELF_C_RDWR_MMAP with ELF_C_RDWR as needed to demonstrate the above.


#include <stdio.h>
#include <stdlib.h>
#include <gelf.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define PF_SEGMEXEC (1 << 6)

int main (int argc, char *argv[])
{
  Elf *elf;
  GElf_Phdr phdr;
  size_t i, phnum;
  int fd = open (argv[1], O_RDWR);

  elf_version(EV_CURRENT);
  elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL);

  elf_getphdrnum (elf, &phnum);

  for (i=0; i<phnum; i++)
    {
      gelf_getphdr (elf, i, &phdr);
      if (phdr.p_type == PT_PAX_FLAGS)
        {
          phdr.p_flags ^= PF_SEGMEXEC;
          gelf_update_phdr (elf, i, &phdr);
        }
  }

  elf_end (elf);
  close (fd);
}

Reproducible: Always
Comment 1 Anthony Basile gentoo-dev 2013-05-31 10:28:57 UTC
My attempt to get elfutils to build on uclibc are in bug #470884