Added test to verify run-as command has valid attributes.

This test verifies that the /system/bin/run-as command has the following
properties:

1. It is readable and executable by the file owner and group
2. It is owned by the root user and the group is shell
3. The file has extended attributes for setuid and setgid

This test catches the failure condition that showed up in this bug:
https://code.google.com/p/android/issues/detail?id=58373

Under some conditions, /system/bin/run-as would not have the setuid or
setgid extended attributes set. If that happened, the device would
prevent developers from running the gdb debugger against executables on
the device, rendering native development ineffective. Currently it is
confirmed that doing a system image update over the air (OTA) to Android
4.3 build JWR66Y on Nexus devices will cause this CTS test to fail as
the extended attributes are not applied by the update. As of this
writing, the work-around is to flash the system image over the USB cable
rather than using an OTA update.

This test is designed to catch and prevent this issue from surfacing
again in future releases.

To implement this test, two new native methods were exported from the
java android.permission.cts.FileUtils class:

* public native static boolean hasSetUidCapability(String path)
* public native static boolean hasSetGidCapability(String path)

These methods return true if the filename indicated by path has extended
attributes and has the setuid or setgid permission set, respectively.

A new test has been added to android.permission.cts.FileSystemPermissionTest:
testRunAsHasCorrectCapabilities(). This test implements the test
described at the top of this comment.

It is strongly recommended that vendors run the CTS test suite against
updates applied by OTA mechanisms in addition to over-the-wire system
flashes.

Bug: 10183961
Change-Id: I268fb68d8754bf89f7316892ff8dfbc6d7c31b98
3 files changed