summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrand SIMONNET <bsimonnet@google.com>2015-09-18 14:12:07 -0700
committerBertrand SIMONNET <bsimonnet@google.com>2015-09-21 13:03:40 -0700
commit4a2bdd8006a5ddf166bcc8973c135799da453e09 (patch)
treef3fc0cf8dc6090da370fd9c1311b2c443db4a765
parent70c3349d3c1dad47ded90d8da38811c1a8c3fef3 (diff)
downloadrootdev-4a2bdd8006a5ddf166bcc8973c135799da453e09.tar.gz
rootdev: Don't try to access /dev/block.
When the device used to back a path is found in /sys/block, rootdev will double check that /dev/block/<device name> exists and that the dev_t matches the one in /sys/block/. On Android, the manufacturer can add an SELinux context for that device node which will prevent core daemons from accessing it, failing the call to rootdev. To avoid this, rootdev should return the device node path without trying to access it. BUG: 24143423 BUG: 24267261 TEST: metricsd starts and find the main disk without any SELinux denial. Change-Id: I4c0fb2800ac84ff451974990c6228ee10528c0f0
-rw-r--r--rootdev.c9
-rw-r--r--rootdev.h10
2 files changed, 8 insertions, 11 deletions
diff --git a/rootdev.c b/rootdev.c
index f0de1ff..82e423f 100644
--- a/rootdev.c
+++ b/rootdev.c
@@ -357,11 +357,10 @@ int rootdev_get_path(char *path, size_t size, const char *device,
if (path_len != strlen(dev_path) + 1 + strlen(device))
return -1;
- if (stat(path, &dev_statbuf) != 0)
- return 1;
-
- if (dev && dev != dev_statbuf.st_rdev)
- return 2;
+ // TODO(bsimonnet): We should check that |path| exists and is the right
+ // device. We don't do this currently as OEMs can add custom SELinux rules
+ // which may prevent us from accessing this.
+ // See b/24267261.
return 0;
}
diff --git a/rootdev.h b/rootdev.h
index 74a48da..05c3da1 100644
--- a/rootdev.h
+++ b/rootdev.h
@@ -79,14 +79,12 @@ void rootdev_get_device_slave(char *slave, size_t size, dev_t *dev,
* @path is populated for all return codes.
* Returns 0 on success and non-zero on error:
* -1 on unexpected errors (@path may be invalid)
- * 1 on no existing @path
- * 2 @path exists but the dev_t value is mismatched.
*
* Nb, this function does NOT search /dev for a match. It performs a normal
- * string concatenation and probes for the existence. If udev has moved,
- * or otherwise renamed, the device, a positive value is returned.
- * The caller may then use the dev_t and @path to create the node with
- * mknod(2).
+ * string concatenation.
+ * We can't check if the device actually exists as vendors may create an
+ * SELinux context we don't know about for it (in which case, this function
+ * would always fail).
*/
int rootdev_get_path(char *path, size_t size, const char *device, dev_t dev,
const char *dev_path);