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
This commit is contained in:
Bram Bonné 2020-01-23 17:05:42 +01:00
parent d54ad07f50
commit d3df35e026

View file

@ -29,6 +29,7 @@
#include <ifaddrs.h>
#include <async_safe/log.h>
#include <cutils/misc.h> // FIRST_APPLICATION_UID
#include <errno.h>
#include <linux/if_packet.h>
#include <net/if.h>
@ -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);