From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1RBfFL-00009K-Rc for garchives@archives.gentoo.org; Thu, 06 Oct 2011 04:07:48 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8725321C052; Thu, 6 Oct 2011 04:07:40 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 484CC21C052 for ; Thu, 6 Oct 2011 04:07:40 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id C05C61B4043 for ; Thu, 6 Oct 2011 04:07:39 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 0A87A80042 for ; Thu, 6 Oct 2011 04:07:39 +0000 (UTC) From: "Anthony G. Basile" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Anthony G. Basile" Message-ID: <91cb263f60d7caf8298aee02e45dcb7bc8fe280a.blueness@gentoo> Subject: [gentoo-commits] proj/elfix:master commit in: scripts/ X-VCS-Repository: proj/elfix X-VCS-Files: scripts/paxmodule.c scripts/setup.py X-VCS-Directories: scripts/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: 91cb263f60d7caf8298aee02e45dcb7bc8fe280a Date: Thu, 6 Oct 2011 04:07:39 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 9db500147580dc1fffd4c02a77afb4af commit: 91cb263f60d7caf8298aee02e45dcb7bc8fe280a Author: Anthony G. Basile gentoo org> AuthorDate: Thu Oct 6 04:07:33 2011 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Thu Oct 6 04:07:33 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/elfix.git;a=3D= commit;h=3D91cb263f scripts/paxmodule.c: add code to read pax flags --- scripts/paxmodule.c | 127 +++++++++++++++++++++++++++++++++++++++++++++= +++--- scripts/setup.py | 3 +- 2 files changed, 122 insertions(+), 8 deletions(-) diff --git a/scripts/paxmodule.c b/scripts/paxmodule.c index 03ba794..1b3e1eb 100644 --- a/scripts/paxmodule.c +++ b/scripts/paxmodule.c @@ -1,5 +1,28 @@ #include =20 +#include //remove when you remove printf +#include + +#include + +#include +#include +#include +#include + + +#define HF_PAX_PAGEEXEC 1 +#define HF_PAX_EMUTRAMP 2 +#define HF_PAX_MPROTECT 4 +#define HF_PAX_RANDMMAP 8 +#define HF_PAX_RANDEXEC 16 +#define HF_PAX_SEGMEXEC 32 + +#define EI_PAX 14 // Index to read the PaX flags into ELF header e_ide= nt[] array + +#define BUF_SIZE 7 //Buffer for holding human readable flags + + static PyObject * pax_getflags(PyObject *, PyObject *); =20 static PyMethodDef PaxMethods[] =3D { @@ -27,21 +50,111 @@ initpax(void) static PyObject * pax_getflags(PyObject *self, PyObject *args) { - const char *value; - int sts; + const char *f_name; + int fd, sts; + Elf *elf; + + GElf_Ehdr ehdr; + char ei_buf[BUF_SIZE]; + uint16_t ei_flags; + + GElf_Phdr phdr; + char pt_buf[BUF_SIZE]; + char found_pt_pax; + size_t i, phnum; + + memset(ei_buf, 0, BUF_SIZE); + memset(pt_buf, 0, BUF_SIZE); =20 - if (!PyArg_ParseTuple(args, "s", &value)) + if (!PyArg_ParseTuple(args, "s", &f_name)) + { + PyErr_SetString(PaxError, "pax_getflags: PyArg_ParseTuple failed"); return NULL; + } =20 - printf("%s\n", value); + if(elf_version(EV_CURRENT) =3D=3D EV_NONE) + { + PyErr_SetString(PaxError, "pax_getflags: library out of date"); + return NULL; + } =20 - sts =3D 1; + if((fd =3D open(f_name, O_RDONLY)) < 0) + { + PyErr_SetString(PaxError, "pax_getflags: open() failed"); + return NULL; + } =20 - if (sts < 0) + if((elf =3D elf_begin(fd, ELF_C_READ_MMAP, NULL)) =3D=3D NULL) { - PyErr_SetString(PaxError, "pax_getflags failed"); + PyErr_SetString(PaxError, "pax_getflags: elf_begin() failed"); return NULL; } =20 + if(elf_kind(elf) !=3D ELF_K_ELF) + { + PyErr_SetString(PaxError, "pax_getflags: elf_kind() failed: this is no= t an elf file."); + return NULL; + } + + + found_pt_pax =3D 0; + elf_getphdrnum(elf, &phnum); + for(i=3D0; i