Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

system-vold: Commit

system/vold


Commit MetaInfo

Revision0e76545ed8321abbbc6197a86e0894ec44cf3f49 (tree)
Time2014-04-28 19:32:51
AuthorNick Kralevich <nnk@goog...>
CommiterChih-Wei Huang

Log Message

Validate asec names.

Make sure asec names only contain alphanumeric, underscores,
dots, or dashes. Don't allow double dots.

Bug: 12504045
Change-Id: I3dd0350c79327dc91a5a10d5724d85d99814e769

Change Summary

Incremental Difference

--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -216,6 +216,12 @@ int VolumeManager::getObbMountPath(const char *sourceFile, char *mountPath, int
216216 int VolumeManager::getAsecMountPath(const char *id, char *buffer, int maxlen) {
217217 char asecFileName[255];
218218
219+ if (!isLegalAsecId(id)) {
220+ SLOGE("getAsecMountPath: Invalid asec id \"%s\"", id);
221+ errno = EINVAL;
222+ return -1;
223+ }
224+
219225 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
220226 SLOGE("Couldn't find ASEC %s", id);
221227 return -1;
@@ -240,6 +246,12 @@ int VolumeManager::getAsecMountPath(const char *id, char *buffer, int maxlen) {
240246 int VolumeManager::getAsecFilesystemPath(const char *id, char *buffer, int maxlen) {
241247 char asecFileName[255];
242248
249+ if (!isLegalAsecId(id)) {
250+ SLOGE("getAsecFilesystemPath: Invalid asec id \"%s\"", id);
251+ errno = EINVAL;
252+ return -1;
253+ }
254+
243255 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
244256 SLOGE("Couldn't find ASEC %s", id);
245257 return -1;
@@ -265,6 +277,12 @@ int VolumeManager::createAsec(const char *id, unsigned int numSectors, const cha
265277 struct asec_superblock sb;
266278 memset(&sb, 0, sizeof(sb));
267279
280+ if (!isLegalAsecId(id)) {
281+ SLOGE("createAsec: Invalid asec id \"%s\"", id);
282+ errno = EINVAL;
283+ return -1;
284+ }
285+
268286 const bool wantFilesystem = strcmp(fstype, "none");
269287 bool usingExt4 = false;
270288 if (wantFilesystem) {
@@ -488,6 +506,12 @@ int VolumeManager::finalizeAsec(const char *id) {
488506 char loopDevice[255];
489507 char mountPoint[255];
490508
509+ if (!isLegalAsecId(id)) {
510+ SLOGE("finalizeAsec: Invalid asec id \"%s\"", id);
511+ errno = EINVAL;
512+ return -1;
513+ }
514+
491515 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
492516 SLOGE("Couldn't find ASEC %s", id);
493517 return -1;
@@ -545,6 +569,12 @@ int VolumeManager::fixupAsecPermissions(const char *id, gid_t gid, const char* f
545569 return -1;
546570 }
547571
572+ if (!isLegalAsecId(id)) {
573+ SLOGE("fixupAsecPermissions: Invalid asec id \"%s\"", id);
574+ errno = EINVAL;
575+ return -1;
576+ }
577+
548578 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
549579 SLOGE("Couldn't find ASEC %s", id);
550580 return -1;
@@ -666,6 +696,18 @@ int VolumeManager::renameAsec(const char *id1, const char *id2) {
666696
667697 const char *dir;
668698
699+ if (!isLegalAsecId(id1)) {
700+ SLOGE("renameAsec: Invalid asec id1 \"%s\"", id1);
701+ errno = EINVAL;
702+ return -1;
703+ }
704+
705+ if (!isLegalAsecId(id2)) {
706+ SLOGE("renameAsec: Invalid asec id2 \"%s\"", id2);
707+ errno = EINVAL;
708+ return -1;
709+ }
710+
669711 if (findAsec(id1, asecFilename1, sizeof(asecFilename1), &dir)) {
670712 SLOGE("Couldn't find ASEC %s", id1);
671713 return -1;
@@ -722,6 +764,12 @@ int VolumeManager::unmountAsec(const char *id, bool force) {
722764 char asecFileName[255];
723765 char mountPoint[255];
724766
767+ if (!isLegalAsecId(id)) {
768+ SLOGE("unmountAsec: Invalid asec id \"%s\"", id);
769+ errno = EINVAL;
770+ return -1;
771+ }
772+
725773 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
726774 SLOGE("Couldn't find ASEC %s", id);
727775 return -1;
@@ -846,6 +894,12 @@ int VolumeManager::destroyAsec(const char *id, bool force) {
846894 char asecFileName[255];
847895 char mountPoint[255];
848896
897+ if (!isLegalAsecId(id)) {
898+ SLOGE("destroyAsec: Invalid asec id \"%s\"", id);
899+ errno = EINVAL;
900+ return -1;
901+ }
902+
849903 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
850904 SLOGE("Couldn't find ASEC %s", id);
851905 return -1;
@@ -878,6 +932,38 @@ int VolumeManager::destroyAsec(const char *id, bool force) {
878932 return 0;
879933 }
880934
935+/*
936+ * Legal ASEC ids consist of alphanumeric characters, '-',
937+ * '_', or '.'. ".." is not allowed. The first or last character
938+ * of the ASEC id cannot be '.' (dot).
939+ */
940+bool VolumeManager::isLegalAsecId(const char *id) const {
941+ size_t i;
942+ size_t len = strlen(id);
943+
944+ if (len == 0) {
945+ return false;
946+ }
947+ if ((id[0] == '.') || (id[len - 1] == '.')) {
948+ return false;
949+ }
950+
951+ for (i = 0; i < len; i++) {
952+ if (id[i] == '.') {
953+ // i=0 is guaranteed never to have a dot. See above.
954+ if (id[i-1] == '.') return false;
955+ continue;
956+ }
957+ if (id[i] == '_' || id[i] == '-') continue;
958+ if (id[i] >= 'a' && id[i] <= 'z') continue;
959+ if (id[i] >= 'A' && id[i] <= 'Z') continue;
960+ if (id[i] >= '0' && id[i] <= '9') continue;
961+ return false;
962+ }
963+
964+ return true;
965+}
966+
881967 bool VolumeManager::isAsecInDirectory(const char *dir, const char *asecName) const {
882968 int dirfd = open(dir, O_DIRECTORY);
883969 if (dirfd < 0) {
@@ -900,6 +986,12 @@ int VolumeManager::findAsec(const char *id, char *asecPath, size_t asecPathLen,
900986 const char **directory) const {
901987 char *asecName;
902988
989+ if (!isLegalAsecId(id)) {
990+ SLOGE("findAsec: Invalid asec id \"%s\"", id);
991+ errno = EINVAL;
992+ return -1;
993+ }
994+
903995 if (asprintf(&asecName, "%s.asec", id) < 0) {
904996 SLOGE("Couldn't allocate string to write ASEC name");
905997 return -1;
@@ -936,6 +1028,12 @@ int VolumeManager::mountAsec(const char *id, const char *key, int ownerUid) {
9361028 char asecFileName[255];
9371029 char mountPoint[255];
9381030
1031+ if (!isLegalAsecId(id)) {
1032+ SLOGE("mountAsec: Invalid asec id \"%s\"", id);
1033+ errno = EINVAL;
1034+ return -1;
1035+ }
1036+
9391037 if (findAsec(id, asecFileName, sizeof(asecFileName))) {
9401038 SLOGE("Couldn't find ASEC %s", id);
9411039 return -1;
--- a/VolumeManager.h
+++ b/VolumeManager.h
@@ -154,6 +154,7 @@ private:
154154 void readInitialState();
155155 bool isMountpointMounted(const char *mp);
156156 bool isAsecInDirectory(const char *dir, const char *asec) const;
157+ bool isLegalAsecId(const char *id) const;
157158 int openLun(int number);
158159 };
159160
Show on old repository browser