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 1R2XpG-0001Fa-2Z for garchives@archives.gentoo.org; Sun, 11 Sep 2011 00:23:10 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4744121C045; Sun, 11 Sep 2011 00:23:02 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id E32A221C045 for ; Sun, 11 Sep 2011 00:23:01 +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 2508A1B4004 for ; Sun, 11 Sep 2011 00:23:01 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 51EBE80042 for ; Sun, 11 Sep 2011 00:23:00 +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: <24a916492fd0d5641f69ade39ae2f9ae2b838303.blueness@gentoo> Subject: [gentoo-commits] proj/elfix:master commit in: src/ X-VCS-Repository: proj/elfix X-VCS-Files: src/paxctl-ng.c X-VCS-Directories: src/ X-VCS-Committer: blueness X-VCS-Committer-Name: Anthony G. Basile X-VCS-Revision: 24a916492fd0d5641f69ade39ae2f9ae2b838303 Date: Sun, 11 Sep 2011 00:23:00 +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: 0f49d5d8b75fbed1c65f9e673fe12640 commit: 24a916492fd0d5641f69ade39ae2f9ae2b838303 Author: Anthony G. Basile gentoo org> AuthorDate: Sun Sep 11 00:22:51 2011 +0000 Commit: Anthony G. Basile gentoo org> CommitDate: Sun Sep 11 00:22:51 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/elfix.git;a=3D= commit;h=3D24a91649 src/paxctl-ng.c: added read EI/PT_PAX flags --- src/paxctl-ng.c | 156 ++++++++++++++++++++++++-------------------------= ----- 1 files changed, 69 insertions(+), 87 deletions(-) diff --git a/src/paxctl-ng.c b/src/paxctl-ng.c index 5f33ebe..d7c58a5 100644 --- a/src/paxctl-ng.c +++ b/src/paxctl-ng.c @@ -17,6 +17,7 @@ */ =20 #include +#include #include #include #include @@ -31,10 +32,14 @@ =20 #include =20 -#define EI_PAX 14 // Index in e_ident[] where to read flags - from chpax= .h +#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 =20 -#define PRINT(E,F,I) printf("%s:\t%s\n", #E, E & F ? ( I ? "enabled" : "= disabled" ) : ( I ? "disabled" : "enabled" ) ); -#define CASE(N,P) case P: printf("%d: %s\n", (int)N, #P); break +#define EI_PAX 14 // Index to read the PaX flags into ELF header e_i= dent[] array =20 =20 void @@ -65,7 +70,7 @@ print_help(char *v) =20 =20 char * -parse_cmd_args( int c, char *v[], int *pax_flags ) +parse_cmd_args(int c, char *v[], int *pax_flags, int *view_flags) { int i, oc; =20 @@ -73,6 +78,7 @@ parse_cmd_args( int c, char *v[], int *pax_flags ) error(EXIT_FAILURE, 0, "Usage: %s {[-pPeEmMrRxXsSzZv] ELFfile | [-h]}"= , v[0]); =20 *pax_flags =3D 0; + *view_flags =3D 0; while((oc =3D getopt(c, v,":pPeEmMrRxXsSzZvh")) !=3D -1) switch(oc) { @@ -105,7 +111,7 @@ parse_cmd_args( int c, char *v[], int *pax_flags ) case 'Z': break; case 'v': - *pax_flags =3D -1; // Invalid flag signal read flags, not set + *view_flags =3D 1; break; case 'h': print_help(v[0]); @@ -119,24 +125,69 @@ parse_cmd_args( int c, char *v[], int *pax_flags ) } =20 =20 -/* - * return 1 if PAX_FLAGS program header exists, 0 otherwise - */ -int -pt_pax_flags(Elf *e) +#define BUF_SIZE 7 +void +print_flags(Elf *e, GElf_Ehdr *eh) { + char ei_buf[BUF_SIZE]; + char pt_buf[BUF_SIZE]; + uint16_t ei_flags; + + char found_pt_pax; size_t i, phnum; GElf_Phdr phdr; =20 + memset(ei_buf, 0, BUF_SIZE); + memset(pt_buf, 0, BUF_SIZE); + + ei_flags =3D eh->e_ident[EI_PAX] + (eh->e_ident[EI_PAX + 1] << 8); + + ei_buf[0] =3D ei_flags & HF_PAX_PAGEEXEC ? 'p' : 'P'; + ei_buf[1] =3D ei_flags & HF_PAX_SEGMEXEC ? 's' : 'S'; + ei_buf[2] =3D ei_flags & HF_PAX_MPROTECT ? 'm' : 'M'; + ei_buf[3] =3D ei_flags & HF_PAX_EMUTRAMP ? 'E' : 'e'; + ei_buf[4] =3D ei_flags & HF_PAX_RANDMMAP ? 'r' : 'R'; + ei_buf[5] =3D ei_flags & HF_PAX_RANDEXEC ? 'X' : 'x'; + + printf("EI_PAX: %s\n", ei_buf); + + found_pt_pax =3D 0; elf_getphdrnum(e, &phnum); for(i=3D0; i PT_NULL\n\n");