summaryrefslogtreecommitdiffstats
path: root/cmds
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2012-10-22 14:24:23 -0700
committerKenny Root <kroot@google.com>2012-10-22 18:48:24 -0700
commit4525f5b69cb44a9a0c92f9c525fc47541f456621 (patch)
tree69472f1e1603516577ef1485f39dfc8fc0d40354 /cmds
parent2278898126c1cea4bd345bb96313d381b4ad3993 (diff)
downloadframeworks_base-4525f5b69cb44a9a0c92f9c525fc47541f456621.zip
frameworks_base-4525f5b69cb44a9a0c92f9c525fc47541f456621.tar.gz
frameworks_base-4525f5b69cb44a9a0c92f9c525fc47541f456621.tar.bz2
Check non-primary user dirs during package scan
During package scan, only the primary user data directories were checked. If the secondary user didn't have an application directory, it would happily ignore it. The app would then crash upon startup. Bug: 7391882 Change-Id: I1fa92aa27386104d4ac6bc5dc92bfbf2e7dfac9f
Diffstat (limited to 'cmds')
-rw-r--r--cmds/installd/commands.c33
1 files changed, 24 insertions, 9 deletions
diff --git a/cmds/installd/commands.c b/cmds/installd/commands.c
index 8e4d7ed..e3acad9 100644
--- a/cmds/installd/commands.c
+++ b/cmds/installd/commands.c
@@ -141,39 +141,54 @@ int renamepkg(const char *oldpkgname, const char *newpkgname)
return 0;
}
-int fix_uid(const char *pkgname, uid_t uid, gid_t gid)
+int fix_uid(const char *pkgname, uid_t uid, uid_t userId)
{
char pkgdir[PKG_PATH_MAX];
struct stat s;
int rc = 0;
- if ((uid < AID_SYSTEM) || (gid < AID_SYSTEM)) {
- ALOGE("invalid uid/gid: %d %d\n", uid, gid);
+ if (uid < AID_SYSTEM) {
+ ALOGE("invalid uid: %d\n", uid);
return -1;
}
- if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, 0)) {
+ if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, userId)) {
ALOGE("cannot create package path\n");
return -1;
}
if (stat(pkgdir, &s) < 0) return -1;
- if (s.st_uid != 0 || s.st_gid != 0) {
- ALOGE("fixing uid of non-root pkg: %s %lu %lu\n", pkgdir, s.st_uid, s.st_gid);
+ if (((s.st_uid != 0) && (s.st_uid != AID_INSTALL))
+ || ((s.st_gid != 0) && (s.st_gid != AID_INSTALL))) {
+ ALOGE("fixing uid of pkg not owned by install or root: %s %lu %lu\n", pkgdir, s.st_uid,
+ s.st_gid);
+ return -1;
+ }
+
+ if (chown(pkgdir, AID_INSTALL, AID_INSTALL) < 0) {
+ ALOGE("cannot chown dir '%s': %s\n", pkgdir, strerror(errno));
+ unlink(pkgdir);
return -1;
}
if (chmod(pkgdir, 0751) < 0) {
ALOGE("cannot chmod dir '%s': %s\n", pkgdir, strerror(errno));
unlink(pkgdir);
- return -errno;
+ return -1;
}
- if (chown(pkgdir, uid, gid) < 0) {
+ if (chown(pkgdir, uid, uid) < 0) {
ALOGE("cannot chown dir '%s': %s\n", pkgdir, strerror(errno));
unlink(pkgdir);
- return -errno;
+ return -1;
}
+#ifdef HAVE_SELINUX
+ if (selinux_android_setfilecon(pkgdir, pkgname, uid) < 0) {
+ ALOGE("cannot setfilecon dir '%s': %s\n", pkgdir, strerror(errno));
+ unlink(pkgdir);
+ return -1;
+ }
+#endif
return 0;
}