summaryrefslogtreecommitdiffstats
path: root/logd
diff options
context:
space:
mode:
authorMark Salyzyn <salyzyn@google.com>2017-01-09 12:43:44 -0800
committerMark Salyzyn <salyzyn@google.com>2017-01-20 09:42:02 -0800
commitc3c06294e56d89a6308d358ecc6e403f8dd8c5b3 (patch)
tree49e858ad74c9fd42b04be00829f0754967357956 /logd
parent8dbab358f01ed0957ff4d5b1c505981dfe93d5de (diff)
downloadsystem_core-c3c06294e56d89a6308d358ecc6e403f8dd8c5b3.tar.gz
system_core-c3c06294e56d89a6308d358ecc6e403f8dd8c5b3.tar.bz2
system_core-c3c06294e56d89a6308d358ecc6e403f8dd8c5b3.zip
logd: test: switch to /data/backup/ for sepolicy avc injection
Resolve issues seen on continuous testing frame: - statistics test, info instead of fail on missing radio log data. - sepolicy switch from /data/misc/logd/ to /data/backup/ as the directory we access(2) to inject sepolicy violations. The key here is we are still root, but we are in u:r:shell:s0, and the directory does not provide us DAC access (0700 system system) so we trigger the pair dac_override and dac_read_search on every try to get past the message de-duper. /data/misc/logd is not always there, until logpersist is enabled, but /data/backup is always there. - a stricter signature of '): avc: denied' - put in a looser threshold for sepolicy_rate_limiter_spam test. Test: gTest logd-unit-tests --gtest_filter=logd.sepolicy* Bug: 34454758 Change-Id: I28ce4fdb51dc4869944e3253b593ce222d16ec98
Diffstat (limited to 'logd')
-rw-r--r--logd/tests/logd_test.cpp28
1 files changed, 17 insertions, 11 deletions
diff --git a/logd/tests/logd_test.cpp b/logd/tests/logd_test.cpp
index 703c0fb9d..13a792286 100644
--- a/logd/tests/logd_test.cpp
+++ b/logd/tests/logd_test.cpp
@@ -196,7 +196,9 @@ TEST(logd, statistics) {
EXPECT_TRUE(NULL != main_logs);
char *radio_logs = strstr(cp, "\nChattiest UIDs in radio ");
- EXPECT_TRUE(NULL != radio_logs);
+ if (!radio_logs) GTEST_LOG_(INFO) << "Value of: NULL != radio_logs\n"
+ "Actual: false\n"
+ "Expected: false\n";
char *system_logs = strstr(cp, "\nChattiest UIDs in system ");
EXPECT_TRUE(NULL != system_logs);
@@ -942,8 +944,16 @@ static pid_t sepolicy_rate(unsigned rate, unsigned num) {
return 0;
}
- // Requests dac_read_search, falls back to request dac_override
- rate /= 2;
+ // The key here is we are root, but we are in u:r:shell:s0,
+ // and the directory does not provide us DAC access
+ // (eg: 0700 system system) so we trigger the pair dac_override
+ // and dac_read_search on every try to get past the message
+ // de-duper. We will also rotate the file name in the directory
+ // as another measure.
+ static const char file[] = "/data/backup/cannot_access_directory_%u";
+ static const unsigned avc_requests_per_access = 2;
+
+ rate /= avc_requests_per_access;
useconds_t usec;
if (rate == 0) {
rate = 1;
@@ -951,15 +961,12 @@ static pid_t sepolicy_rate(unsigned rate, unsigned num) {
} else {
usec = (1000000 + (rate / 2)) / rate;
}
- num = (num + 1) / 2;
+ num = (num + (avc_requests_per_access / 2)) / avc_requests_per_access;
if (usec < 2) usec = 2;
while (num > 0) {
- if (access(android::base::StringPrintf(
- "/data/misc/logd/cannot_access_directory_%u",
- num).c_str(),
- F_OK) == 0) {
+ if (access(android::base::StringPrintf(file, num).c_str(), F_OK) == 0) {
_exit(-1);
// NOTREACHED
return 0;
@@ -1002,7 +1009,7 @@ static int count_avc(pid_t pid) {
// int len = get4LE(eventData + 4 + 1);
log_msg.buf[LOGGER_ENTRY_MAX_LEN] = '\0';
- const char *cp = strstr(eventData + 4 + 1 + 4, "): avc: ");
+ const char *cp = strstr(eventData + 4 + 1 + 4, "): avc: denied");
if (!cp) continue;
++count;
@@ -1055,8 +1062,7 @@ TEST(logd, sepolicy_rate_limiter_spam) {
// give logd another 3 seconds to react to the burst before checking
sepolicy_rate(rate, rate * 3);
// maximum period at double the maximum burst rate (spam filter kicked in)
- EXPECT_GE(((AUDIT_RATE_LIMIT_MAX * AUDIT_RATE_LIMIT_BURST_DURATION) * 130) /
- 100, // +30% margin
+ EXPECT_GE(threshold * 2,
count_avc(sepolicy_rate(rate,
rate * AUDIT_RATE_LIMIT_BURST_DURATION)));
// cool down, and check unspammy rate still works