From d3df35e026e37985754e8766da0afcfcb9531290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bram=20Bonn=C3=A9?= Date: Thu, 23 Jan 2020 17:05:42 +0100 Subject: [PATCH] Soft-enables MAC address restrictions. Updates getifaddrs() to behave as if RTM_GETLINK requests are not allowed for non-system apps that have their target SDK set to R. This change will be reverted when kernel changes enforcing this behavior are merged, and is purely meant to check for potential appcompat issues beforehand. Bug: 141455849 Test: atest bionic-unit-tests-static Test: atest NetworkInterfaceTest Test: Connect to Wi-Fi network Test: Set up hotspot Test: Cast from device Test: Pair Bluetooth device Test: Call getifaddrs() directly from within an app. Test: Call NetworkInterface#getNetworkInterfaces() from within an app. Test: Repeat above tests with an app that targets Android R. Change-Id: I472891d3e8a18c86ae478be1bab1048636aa95b4 --- libc/bionic/ifaddrs.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/libc/bionic/ifaddrs.cpp b/libc/bionic/ifaddrs.cpp index 954d43ba9..e21ec4023 100644 --- a/libc/bionic/ifaddrs.cpp +++ b/libc/bionic/ifaddrs.cpp @@ -29,6 +29,7 @@ #include #include +#include // FIRST_APPLICATION_UID #include #include #include @@ -272,8 +273,16 @@ int getifaddrs(ifaddrs** out) { // Open the netlink socket and ask for all the links and addresses. NetlinkConnection nc; - bool getlink_success = - nc.SendRequest(RTM_GETLINK) && nc.ReadResponses(__getifaddrs_callback, out); + // Simulate kernel behavior on R and above: RTM_GETLINK messages can only be + // sent by: + // - System apps + // - Apps with a target SDK version lower than R + // TODO(b/141455849): Remove this check when kernel changes are merged. + bool getlink_success = false; + if (getuid() < FIRST_APPLICATION_UID || + android_get_application_target_sdk_version() < __ANDROID_API_R__) { + getlink_success = nc.SendRequest(RTM_GETLINK) && nc.ReadResponses(__getifaddrs_callback, out); + } bool getaddr_success = nc.SendRequest(RTM_GETADDR) && nc.ReadResponses(__getifaddrs_callback, out);