diff options
author | dcashman <dcashman@google.com> | 2016-03-07 10:32:05 -0800 |
---|---|---|
committer | dcashman <dcashman@google.com> | 2016-03-09 16:39:14 -0800 |
commit | d661642651a6689c76d3f575b4b5dbf04e6b75bd (patch) | |
tree | f52dde11935ced3208c4071e5b9af0fbc8e961a7 /tests/kernel.config/aslr_test.h | |
parent | 0a34d462046a77c7649a40226b06c2232a547635 (diff) | |
download | extras-d661642651a6689c76d3f575b4b5dbf04e6b75bd.tar.gz |
Migrate aslr test to gtest.
Create tests which test the values of mmap_rnd_bits, and
mmap_rnd_compat_bits, if applicable, and verify that the address space
is randomized as expected given the provided values.
Also add a pair of tests to CTS that enforce that the observed entropy
is at least as high as a designated value. That value will start as our
default value, which also corresponds to the maximum value of some
configurations.
Packaging of executables along with a nativetest suite is not supported,
so add a dummy nativetest suite, scrape_mmap_addr, which ensure that the
executables are present along with the given tests at predictable
locations.
Bug: 26512380
Change-Id: Ib1202984f9b98c503b8d3bc2c2248a9d06940845
Diffstat (limited to 'tests/kernel.config/aslr_test.h')
-rw-r--r-- | tests/kernel.config/aslr_test.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/kernel.config/aslr_test.h b/tests/kernel.config/aslr_test.h new file mode 100644 index 00000000..355a62a5 --- /dev/null +++ b/tests/kernel.config/aslr_test.h @@ -0,0 +1,77 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ASLR_TEST_H +#define ASLR_TEST_H + +#include <cmath> +#include <errno.h> +#include <fstream> +#include <iostream> +#include <stdint.h> +#include <string> +#include <sys/wait.h> +#include <unistd.h> +#include <unordered_set> + +#include <gtest/gtest.h> + +#define MAX_ADDR_LEN 256 + +#define PROCFS_PATH "/proc/sys/vm/mmap_rnd_bits" +#define PROCFS_COMPAT_PATH "/proc/sys/vm/mmap_rnd_compat_bits" + +#define SCRAPE_PATH_64 "/data/nativetest64/scrape_mmap_addr/scrape_mmap_addr" +#define SCRAPE_PATH_32 "/data/nativetest/scrape_mmap_addr/scrape_mmap_addr" +#define SCRAPE_LIB_64 "/system/bin/linker64" +#define SCRAPE_LIB_32 "/system/bin/linker" + +class AslrMmapTest : public ::testing::Test { + protected: + static void SetUpTestCase(); + static const char *path; + static const char *lib; + static unsigned int def, min, max; + static bool compat, user32; + static unsigned int def_cmpt, min_cmpt, max_cmpt; + + void TearDown(); +}; + +/* + * gets the current mmap_rnd_bits value. requires root. + */ +unsigned int get_mmap_rnd_bits(bool compat); + +/* + * sets the corresponding mmap_rnd_bits variable, returns false if couldn't + * change. requires root. + */ +bool set_mmap_rnd_bits(unsigned int new_val, bool compat); + +/* + * scrape_addr - get the raw starting address from /proc/child_pid/mmaps + */ +std::string scrape_addr(const char *exec_name, const char *lib_match); + +/* + * forks off sample_size processes and records the starting address of the + * indicated library as reported by exec_name. Reports entropy observed among + * recorded samples. + */ +unsigned int calc_mmap_entropy(const char *exec_name, const char *lib_match, size_t samp_sz); + +#endif //ASLR_TEST_H |