stack protector: use AT_RANDOM
Populate the stack canaries from the kernel supplied AT_RANDOM value, which doesn't involve any system calls. This is slightly faster (6 fewer syscalls) and avoids unnecessarily reading /dev/urandom, which depletes entropy. Bug: 7959813 Change-Id: If2b43100a2a9929666df3de56b6139fed969e0f1
This commit is contained in:
@@ -56,13 +56,7 @@ struct stack_protector_checker {
|
||||
|
||||
// Duplicate tid. gettid(2) bug? Seeing this would be very upsetting.
|
||||
ASSERT_TRUE(tids.find(tid) == tids.end());
|
||||
#ifdef __GLIBC__
|
||||
// glibc uses the same guard for every thread. bionic uses a different guard for each one.
|
||||
#else
|
||||
// Duplicate guard. Our bug. Note this is potentially flaky; we _could_ get the
|
||||
// same guard for two threads, but it should be vanishingly unlikely.
|
||||
ASSERT_TRUE(guards.find(guard) == guards.end());
|
||||
#endif
|
||||
|
||||
// Uninitialized guard. Our bug. Note this is potentially flaky; we _could_ get
|
||||
// four random zero bytes, but it should be vanishingly unlikely.
|
||||
ASSERT_NE(guard, 0U);
|
||||
@@ -78,7 +72,7 @@ static void* ThreadGuardHelper(void* arg) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TEST(stack_protector, guard_per_thread) {
|
||||
TEST(stack_protector, same_guard_per_thread) {
|
||||
stack_protector_checker checker;
|
||||
size_t thread_count = 10;
|
||||
for (size_t i = 0; i < thread_count; ++i) {
|
||||
@@ -90,12 +84,8 @@ TEST(stack_protector, guard_per_thread) {
|
||||
}
|
||||
ASSERT_EQ(thread_count, checker.tids.size());
|
||||
|
||||
// glibc uses the same guard for every thread. bionic uses a different guard for each one.
|
||||
#ifdef __BIONIC__
|
||||
ASSERT_EQ(thread_count, checker.guards.size());
|
||||
#else
|
||||
// bionic x86 and glibc uses the same guard for every thread.
|
||||
ASSERT_EQ(1U, checker.guards.size());
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user