Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f5c84a0 authored by Nick Kralevich's avatar Nick Kralevich
Browse files

App home directories are now 0700 for targetSdkVersion > 17

Have installd set an app's home directory permissions to
0700 if the app has targetSdkVersion > 17.

Bug: 7208882
Change-Id: Iaa4fc42fec69bc1abdfae53704d6264dd6fa965f
parent 1aa65280
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -11,9 +11,8 @@ include $(CLEAR_VARS)

LOCAL_SRC_FILES := \
    $(common_src_files)

LOCAL_CFLAGS := -std=gnu99
LOCAL_MODULE := libinstalld

LOCAL_MODULE_TAGS := eng tests

include $(BUILD_STATIC_LIBRARY)
@@ -36,7 +35,7 @@ LOCAL_STATIC_LIBRARIES := \
    libdiskusage

LOCAL_MODULE := installd

LOCAL_CFLAGS := -std=gnu99
LOCAL_MODULE_TAGS := optional

include $(BUILD_EXECUTABLE)
+10 −6
Original line number Diff line number Diff line
@@ -28,13 +28,15 @@ dir_rec_t android_app_lib_dir;
dir_rec_t android_media_dir;
dir_rec_array_t android_system_dirs;

int install(const char *pkgname, uid_t uid, gid_t gid)
int install(const char *pkgname, uid_t uid, gid_t gid, bool restrictHomeDir)
{
    char pkgdir[PKG_PATH_MAX];
    char libsymlink[PKG_PATH_MAX];
    char applibdir[PKG_PATH_MAX];
    struct stat libStat;

    mode_t defaultMode = restrictHomeDir ? 0700 : 0751;

    if ((uid < AID_SYSTEM) || (gid < AID_SYSTEM)) {
        ALOGE("invalid uid/gid: %d %d\n", uid, gid);
        return -1;
@@ -55,11 +57,11 @@ int install(const char *pkgname, uid_t uid, gid_t gid)
        return -1;
    }

    if (mkdir(pkgdir, 0751) < 0) {
    if (mkdir(pkgdir, defaultMode) < 0) {
        ALOGE("cannot create dir '%s': %s\n", pkgdir, strerror(errno));
        return -1;
    }
    if (chmod(pkgdir, 0751) < 0) {
    if (chmod(pkgdir, defaultMode) < 0) {
        ALOGE("cannot chmod dir '%s': %s\n", pkgdir, strerror(errno));
        unlink(pkgdir);
        return -1;
@@ -184,13 +186,15 @@ int delete_user_data(const char *pkgname, uid_t persona)
    return delete_dir_contents(pkgdir, 0, "lib");
}

int make_user_data(const char *pkgname, uid_t uid, uid_t persona)
int make_user_data(const char *pkgname, uid_t uid, uid_t persona, bool restrictHomeDir)
{
    char pkgdir[PKG_PATH_MAX];
    char applibdir[PKG_PATH_MAX];
    char libsymlink[PKG_PATH_MAX];
    struct stat libStat;

    mode_t defaultMode = restrictHomeDir ? 0700 : 0751;

    // Create the data dir for the package
    if (create_pkg_path(pkgdir, pkgname, PKG_DIR_POSTFIX, persona)) {
        return -1;
@@ -204,11 +208,11 @@ int make_user_data(const char *pkgname, uid_t uid, uid_t persona)
        return -1;
    }

    if (mkdir(pkgdir, 0751) < 0) {
    if (mkdir(pkgdir, defaultMode) < 0) {
        ALOGE("cannot create dir '%s': %s\n", pkgdir, strerror(errno));
        return -errno;
    }
    if (chmod(pkgdir, 0751) < 0) {
    if (chmod(pkgdir, defaultMode) < 0) {
        ALOGE("cannot chmod dir '%s': %s\n", pkgdir, strerror(errno));
        unlink(pkgdir);
        return -errno;
+12 −4
Original line number Diff line number Diff line
@@ -31,7 +31,11 @@ static int do_ping(char **arg, char reply[REPLY_MAX])

static int do_install(char **arg, char reply[REPLY_MAX])
{
    return install(arg[0], atoi(arg[1]), atoi(arg[2])); /* pkgname, uid, gid */
    bool restrictHomeDir = (strncmp(arg[3], "false", 6) != 0);
    return install(arg[0],           /* pkgname */
                   atoi(arg[1]),     /* uid */
                   atoi(arg[2]),     /* gid */
                   restrictHomeDir); /* restrictHomeDir */
}

static int do_dexopt(char **arg, char reply[REPLY_MAX])
@@ -103,7 +107,11 @@ static int do_rm_user_data(char **arg, char reply[REPLY_MAX])

static int do_mk_user_data(char **arg, char reply[REPLY_MAX])
{
    return make_user_data(arg[0], atoi(arg[1]), atoi(arg[2])); /* pkgname, uid, userid */
    bool restrictHomeDir = (strncmp(arg[3], "false", 6) != 0);
    return make_user_data(arg[0],           /* pkgname */
                          atoi(arg[1]),     /* uid */
                          atoi(arg[2]),     /* userid */
                          restrictHomeDir); /* restrictHomeDir */
}

static int do_rm_user(char **arg, char reply[REPLY_MAX])
@@ -129,7 +137,7 @@ struct cmdinfo {

struct cmdinfo cmds[] = {
    { "ping",                 0, do_ping },
    { "install",              3, do_install },
    { "install",              4, do_install },
    { "dexopt",               3, do_dexopt },
    { "movedex",              2, do_move_dex },
    { "rmdex",                1, do_rm_dex },
@@ -142,7 +150,7 @@ struct cmdinfo cmds[] = {
    { "rmuserdata",           2, do_rm_user_data },
    { "movefiles",            0, do_movefiles },
    { "linklib",              3, do_linklib },
    { "mkuserdata",           3, do_mk_user_data },
    { "mkuserdata",           4, do_mk_user_data },
    { "rmuser",               1, do_rm_user },
};

+5 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <inttypes.h>
#include <sys/stat.h>
#include <dirent.h>
@@ -192,12 +193,14 @@ int ensure_media_user_dirs(userid_t userid);

/* commands.c */

int install(const char *pkgname, uid_t uid, gid_t gid);
int install(const char *pkgname, uid_t uid, gid_t gid,
            bool restrictHomeDirectory);
int uninstall(const char *pkgname, uid_t persona);
int renamepkg(const char *oldpkgname, const char *newpkgname);
int fix_uid(const char *pkgname, uid_t uid, gid_t gid);
int delete_user_data(const char *pkgname, uid_t persona);
int make_user_data(const char *pkgname, uid_t uid, uid_t persona);
int make_user_data(const char *pkgname, uid_t uid, uid_t persona,
                   bool restrictHomeDirectory);
int delete_persona(uid_t persona);
int delete_cache(const char *pkgname, uid_t persona);
int move_dex(const char *src, const char *dst);