Skip to content

Commit cd62059

Browse files
nickkralAndroid (Google) Code Review
authored andcommitted
Merge "installd: fix forward locking symlink" into jb-mr1-dev
2 parents 1275abd + 7de350a commit cd62059

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

cmds/installd/commands.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ int protect(char *pkgname, gid_t gid)
420420
return -1;
421421
}
422422
if (chmod(pkgpath, S_IRUSR|S_IWUSR|S_IRGRP) < 0) {
423-
ALOGE("failed to chmod '%s': %s\n", pkgpath, strerror(errno));
423+
ALOGE("protect(): failed to chmod '%s': %s\n", pkgpath, strerror(errno));
424424
return -1;
425425
}
426426

@@ -1014,13 +1014,13 @@ int linklib(const char* dataDir, const char* asecLibDir)
10141014

10151015
if (stat(dataDir, &s) < 0) return -1;
10161016

1017-
if (chown(dataDir, 0, 0) < 0) {
1017+
if (chown(dataDir, AID_INSTALL, AID_INSTALL) < 0) {
10181018
ALOGE("failed to chown '%s': %s\n", dataDir, strerror(errno));
10191019
return -1;
10201020
}
10211021

10221022
if (chmod(dataDir, 0700) < 0) {
1023-
ALOGE("failed to chmod '%s': %s\n", dataDir, strerror(errno));
1023+
ALOGE("linklib() 1: failed to chmod '%s': %s\n", dataDir, strerror(errno));
10241024
rc = -1;
10251025
goto out;
10261026
}
@@ -1058,7 +1058,7 @@ int linklib(const char* dataDir, const char* asecLibDir)
10581058

10591059
out:
10601060
if (chmod(dataDir, s.st_mode) < 0) {
1061-
ALOGE("failed to chmod '%s': %s\n", dataDir, strerror(errno));
1061+
ALOGE("linklib() 2: failed to chmod '%s': %s\n", dataDir, strerror(errno));
10621062
rc = -errno;
10631063
}
10641064

@@ -1091,13 +1091,13 @@ int unlinklib(const char* dataDir)
10911091
return -1;
10921092
}
10931093

1094-
if (chown(dataDir, 0, 0) < 0) {
1094+
if (chown(dataDir, AID_INSTALL, AID_INSTALL) < 0) {
10951095
ALOGE("failed to chown '%s': %s\n", dataDir, strerror(errno));
10961096
return -1;
10971097
}
10981098

10991099
if (chmod(dataDir, 0700) < 0) {
1100-
ALOGE("failed to chmod '%s': %s\n", dataDir, strerror(errno));
1100+
ALOGE("unlinklib() 1: failed to chmod '%s': %s\n", dataDir, strerror(errno));
11011101
rc = -1;
11021102
goto out;
11031103
}
@@ -1140,7 +1140,7 @@ int unlinklib(const char* dataDir)
11401140

11411141
out:
11421142
if (chmod(dataDir, s.st_mode) < 0) {
1143-
ALOGE("failed to chmod '%s': %s\n", dataDir, strerror(errno));
1143+
ALOGE("unlinklib() 2: failed to chmod '%s': %s\n", dataDir, strerror(errno));
11441144
rc = -1;
11451145
}
11461146

core/tests/coretests/src/android/content/pm/PackageManagerTests.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,14 @@ private void assertInstall(PackageParser.Package pkg, int flags, int expInstallL
395395
assertTrue("The native library path (" + info.nativeLibraryDir
396396
+ ") should start with " + SECURE_CONTAINERS_PREFIX,
397397
info.nativeLibraryDir.startsWith(SECURE_CONTAINERS_PREFIX));
398+
try {
399+
String compatLib = new File(info.dataDir + "/lib").getCanonicalPath();
400+
assertEquals("The compatibility lib directory should be a symbolic link to "
401+
+ info.nativeLibraryDir,
402+
info.nativeLibraryDir, compatLib);
403+
} catch (IOException e) {
404+
fail("compat check: Can't read " + info.dataDir + "/lib");
405+
}
398406
} else {
399407
assertFalse((info.flags & ApplicationInfo.FLAG_FORWARD_LOCK) != 0);
400408
assertEquals(srcPath, appInstallPath);

services/java/com/android/server/pm/PackageManagerService.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4110,8 +4110,13 @@ private PackageParser.Package scanPackageLI(PackageParser.Package pkg,
41104110
NativeLibraryHelper.copyNativeBinariesIfNeededLI(scanFile, nativeLibraryDir);
41114111
} else {
41124112
Slog.i(TAG, "Linking native library dir for " + path);
4113-
mInstaller.linkNativeLibraryDirectory(dataPathString,
4113+
int ret = mInstaller.linkNativeLibraryDirectory(dataPathString,
41144114
pkg.applicationInfo.nativeLibraryDir);
4115+
if (ret < 0) {
4116+
Slog.w(TAG, "Failed linking native library dir for " + path);
4117+
mLastScanError = PackageManager.MOVE_FAILED_INSUFFICIENT_STORAGE;
4118+
return null;
4119+
}
41154120
}
41164121
} catch (IOException ioe) {
41174122
Log.e(TAG, "Unable to get canonical file " + ioe.toString());

0 commit comments

Comments
 (0)