Don't trip up when deleting strict iptables rules.
Currently, when applying a cleartext policy to a UID,
StrictController will attempt to delete all possible policies
that might previously have applied to this UID. Because only
two of these rules can exist at any given time, at least one
of these deletes is guaranteed to fail, causing the whole
operation to fail.
Instead of adding a log or reject rule for every UID, add a
rule that sends that UID to its own chain which then contains
the log or reject rule. That way, deleting the previous policy
only requires deleting the chain, which is something we know
exists.
(cherry picked from commit 81e02f21424ebda9a314c7b9fbc31cfe2a99444f)
Bug: 64988066
Test: netd_{unit,integration}_test pass
Test: android.os.cts.StrictModeTest passes
Change-Id: Ic9d66220a65f2ce9510c4194e7b874d3d5dca5d7
diff --git a/server/StrictControllerTest.cpp b/server/StrictControllerTest.cpp
index 82d0cda..9770352 100644
--- a/server/StrictControllerTest.cpp
+++ b/server/StrictControllerTest.cpp
@@ -126,20 +126,25 @@
std::vector<std::string> acceptCommands = {
"*filter\n"
"-D st_OUTPUT -m owner --uid-owner 12345 -j st_clear_detect\n"
- "-D st_clear_caught -m owner --uid-owner 12345 -j st_penalty_log\n"
- "-D st_clear_caught -m owner --uid-owner 12345 -j st_penalty_reject\n"
+ "-D st_clear_caught -m owner --uid-owner 12345 -j st_clear_caught_12345\n"
+ "-F st_clear_caught_12345\n"
+ "-X st_clear_caught_12345\n"
"COMMIT\n"
};
std::vector<std::string> logCommands = {
"*filter\n"
+ ":st_clear_caught_12345 -\n"
"-I st_OUTPUT -m owner --uid-owner 12345 -j st_clear_detect\n"
- "-I st_clear_caught -m owner --uid-owner 12345 -j st_penalty_log\n"
+ "-I st_clear_caught -m owner --uid-owner 12345 -j st_clear_caught_12345\n"
+ "-A st_clear_caught_12345 -j st_penalty_log\n"
"COMMIT\n"
};
std::vector<std::string> rejectCommands = {
"*filter\n"
+ ":st_clear_caught_12345 -\n"
"-I st_OUTPUT -m owner --uid-owner 12345 -j st_clear_detect\n"
- "-I st_clear_caught -m owner --uid-owner 12345 -j st_penalty_reject\n"
+ "-I st_clear_caught -m owner --uid-owner 12345 -j st_clear_caught_12345\n"
+ "-A st_clear_caught_12345 -j st_penalty_reject\n"
"COMMIT\n"
};