aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnthony G. Basile <blueness@gentoo.org>2011-11-03 07:13:44 -0400
committerAnthony G. Basile <blueness@gentoo.org>2011-11-03 07:13:44 -0400
commit4c796b141f0c1f246371d54a3de83931b603f82b (patch)
treeaaa81c8799ab09012c77b14e7a6c7c06f0196752 /src
parentTODO: updated (diff)
downloadelfix-4c796b141f0c1f246371d54a3de83931b603f82b.tar.gz
elfix-4c796b141f0c1f246371d54a3de83931b603f82b.tar.bz2
elfix-4c796b141f0c1f246371d54a3de83931b603f82b.zip
src/paxctl-ng.c: if open(O_RDWR) fails, PT_PAX is readonly
Diffstat (limited to 'src')
-rw-r--r--src/paxctl-ng.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/paxctl-ng.c b/src/paxctl-ng.c
index 2b0946a..d3ddb2f 100644
--- a/src/paxctl-ng.c
+++ b/src/paxctl-ng.c
@@ -451,15 +451,18 @@ set_xt_flags(int fd, uint16_t xt_flags)
void
-set_flags(int fd, uint16_t *pax_flags)
+set_flags(int fd, uint16_t *pax_flags, int rdwr_pt_pax)
{
uint16_t flags;
- flags = get_pt_flags(fd);
- if( flags == UINT16_MAX )
- flags = PF_NOEMUTRAMP | PF_NORANDEXEC;
- flags = update_flags( flags, *pax_flags);
- set_pt_flags(fd, flags);
+ if(rdwr_pt_pax)
+ {
+ flags = get_pt_flags(fd);
+ if( flags == UINT16_MAX )
+ flags = PF_NOEMUTRAMP | PF_NORANDEXEC;
+ flags = update_flags( flags, *pax_flags);
+ set_pt_flags(fd, flags);
+ }
flags = get_xt_flags(fd);
if( flags == UINT16_MAX )
@@ -470,7 +473,7 @@ set_flags(int fd, uint16_t *pax_flags)
void
-create_xt_flag(fd, cp_flags)
+create_xt_flags(fd, cp_flags)
{
uint16_t xt_flags;
@@ -485,7 +488,7 @@ create_xt_flag(fd, cp_flags)
void
-copy_xt_flag(fd, cp_flags)
+copy_xt_flags(fd, cp_flags)
{
uint16_t flags;
if(cp_flags == 3)
@@ -508,20 +511,26 @@ main( int argc, char *argv[])
int fd;
uint16_t flags;
int view_flags, cp_flags;
+ int rdwr_pt_pax = 1;
f_name = parse_cmd_args(argc, argv, &flags, &view_flags, &cp_flags);
if((fd = open(f_name, O_RDWR)) < 0)
- error(EXIT_FAILURE, 0, "open() fail.");
+ {
+ rdwr_pt_pax = 0;
+ printf("open(O_RDWR) failed: cannot change PT_PAX flags\n");
+ if((fd = open(f_name, O_RDONLY)) < 0)
+ error(EXIT_FAILURE, 0, "open() failed");
+ }
if(cp_flags == 1 || cp_flags == 2)
- create_xt_flag(fd, cp_flags);
+ create_xt_flags(fd, cp_flags);
- if(cp_flags == 3 || cp_flags == 4)
- copy_xt_flag(fd, cp_flags);
+ if(cp_flags == 3 || (cp_flags == 4 && rdwr_pt_pax))
+ copy_xt_flags(fd, cp_flags);
if(flags != 1)
- set_flags(fd, &flags);
+ set_flags(fd, &flags, rdwr_pt_pax);
if(view_flags == 1)
print_flags(fd);