Squashed commit of the following:
commit 3007df0d153ade6d328321dad8f88d63869159c8
Merge: 7557851 cd14d68
Author: Carl Pearson <pearson@illinois.edu>
Date: Wed Sep 25 09:59:54 2019 -0500
Merge branch 'master' into feature/aslr
commit 7557851508f0e1c2d75244267c5f78fb3d1ca303
Author: Carl Pearson <pearson@illinois.edu>
Date: Tue Sep 24 07:50:15 2019 -0500
wish list
commit 0bbbac31f354c16ae1942dbfe4683a66ec260498
Author: Carl Pearson <pearson@illinois.edu>
Date: Tue Sep 24 07:49:36 2019 -0500
ASLR documentation
commit f1ae37e057792696a739e30ecdbd09e071b8a7d4
Author: Carl Pearson <pearson@illinois.edu>
Date: Tue Sep 24 07:45:54 2019 -0500
add ASLR interface
This commit is contained in:
40
include/perfect/aslr.hpp
Normal file
40
include/perfect/aslr.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include <cerrno>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef __linux__
|
||||
#include "detail/os/linux.hpp"
|
||||
#endif
|
||||
#include "init.hpp"
|
||||
#include "result.hpp"
|
||||
|
||||
namespace perfect {
|
||||
|
||||
struct AslrState {
|
||||
#ifdef __linux__
|
||||
unsigned long persona;
|
||||
#else
|
||||
#error "unsupported platform"
|
||||
#endif
|
||||
};
|
||||
|
||||
Result get_aslr(AslrState &state) {
|
||||
int persona;
|
||||
PERFECT_SUCCESS_OR_RETURN(detail::get_personality(persona));
|
||||
state.persona = persona;
|
||||
return Result::SUCCESS;
|
||||
}
|
||||
|
||||
Result set_aslr(const AslrState &state) {
|
||||
return detail::set_personality(state.persona);
|
||||
}
|
||||
|
||||
Result disable_aslr() {
|
||||
int persona;
|
||||
PERFECT_SUCCESS_OR_RETURN(detail::get_personality(persona));
|
||||
persona |= ADDR_NO_RANDOMIZE;
|
||||
return detail::set_personality(persona);
|
||||
}
|
||||
|
||||
} // namespace perfect
|
@@ -12,6 +12,7 @@
|
||||
#include <sched.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/personality.h>
|
||||
|
||||
#include "perfect/result.hpp"
|
||||
|
||||
@@ -88,4 +89,24 @@ size_t cache_linesize() {
|
||||
#endif
|
||||
}
|
||||
|
||||
namespace detail {
|
||||
Result get_personality(int &persona) {
|
||||
int ret = personality(0xffffffff);
|
||||
if (-1 == ret) {
|
||||
return Result::UNKNOWN;
|
||||
} else {
|
||||
persona = ret;
|
||||
}
|
||||
return Result::SUCCESS;
|
||||
}
|
||||
|
||||
Result set_personality(const int persona) {
|
||||
int ret = personality(persona);
|
||||
if (-1 == ret) {
|
||||
return Result::UNKNOWN;
|
||||
}
|
||||
return Result::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace perfect
|
Reference in New Issue
Block a user