server: check interface names in RPC arguments for validity
This patch introduces a method isIfaceName that checks interface
names from various RPCs for validity before e.g. using them as
part of iptables arguments or in filenames.
All of these RPC calls can only be called from applications
with at least the CONNECTIVITY_INTERNAL permission in recent
Android versions, so the impact of the missing checks luckily
isn't very high.
Orig-Author: Jann Horn <jann@thejh.net>
Change-Id: I80df8d745a3de99ad02d6649f0d10562c81f6b98
Signed-off-by: JP Abgrall <jpa@google.com>
diff --git a/server/SecondaryTableController.cpp b/server/SecondaryTableController.cpp
index 2ffb54d..398edd1 100644
--- a/server/SecondaryTableController.cpp
+++ b/server/SecondaryTableController.cpp
@@ -229,6 +229,11 @@
}
int SecondaryTableController::setFwmarkRule(const char *iface, bool add) {
+ if (!isIfaceName(iface)) {
+ errno = ENOENT;
+ return -1;
+ }
+
unsigned netId = mNetCtrl->getNetworkId(iface);
// Fail fast if any rules already exist for this interface
@@ -386,6 +391,11 @@
int SecondaryTableController::setFwmarkRoute(const char* iface, const char *dest, int prefix,
bool add) {
+ if (!isIfaceName(iface)) {
+ errno = ENOENT;
+ return -1;
+ }
+
unsigned netId = mNetCtrl->getNetworkId(iface);
char mark_str[11] = {0};
char dest_str[44]; // enough to store an IPv6 address + 3 character bitmask