trampoline: Add new pre/post encrypt hooks, fake system properties library
These are needed on Snapdragon 810 where an extra daemon (qseecomd) must be started prior to decryption, and where the decryption library polls a system property to make sure that daemon is running Also fix missing fonts log spam in trampoline_encmnt by symlinking the one available font
This commit is contained in:
5
hooks.h
5
hooks.h
@@ -41,6 +41,11 @@ void mrom_hook_fixup_bootimg_cmdline(char *bootimg_cmdline, size_t bootimg_cmdli
|
||||
int mrom_hook_has_kexec(void);
|
||||
#endif
|
||||
|
||||
#if MR_DEVICE_HOOKS >= 6
|
||||
void tramp_hook_encryption_setup(void);
|
||||
void tramp_hook_encryption_cleanup(void);
|
||||
#endif
|
||||
|
||||
#endif /* MR_DEVICE_HOOKS */
|
||||
|
||||
#endif /* MR_DEVICE_HOOKS_H */
|
||||
|
||||
@@ -14,7 +14,7 @@ endif
|
||||
|
||||
multirom_extra_dep :=
|
||||
ifeq ($(MR_ENCRYPTION),true)
|
||||
multirom_extra_dep += trampoline_encmnt linker
|
||||
multirom_extra_dep += trampoline_encmnt linker libmultirom_fake_properties
|
||||
else
|
||||
MR_ENCRYPTION := false
|
||||
endif
|
||||
@@ -59,6 +59,7 @@ $(MULTIROM_ZIP_TARGET): multirom trampoline signapk bbootimg mrom_kexec_static m
|
||||
cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libm.so $(MULTIROM_INST_DIR)/multirom/enc/; \
|
||||
cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libstdc++.so $(MULTIROM_INST_DIR)/multirom/enc/; \
|
||||
cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libc++.so $(MULTIROM_INST_DIR)/multirom/enc/; \
|
||||
cp -a $(TARGET_OUT_SHARED_LIBRARIES)/libmultirom_fake_properties.so $(MULTIROM_INST_DIR)/multirom/enc/; \
|
||||
if [ -n "$(MR_ENCRYPTION_SETUP_SCRIPT)" ]; then sh "$(ANDROID_BUILD_TOP)/$(MR_ENCRYPTION_SETUP_SCRIPT)" "$(ANDROID_BUILD_TOP)" "$(MULTIROM_INST_DIR)/multirom/enc"; fi; \
|
||||
fi
|
||||
|
||||
|
||||
@@ -40,4 +40,8 @@ ifeq ($(MR_ENCRYPTION),true)
|
||||
LOCAL_SRC_FILES += encryption.c
|
||||
endif
|
||||
|
||||
ifeq ($(MR_ENCRYPTION_FAKE_PROPERTIES),true)
|
||||
LOCAL_CFLAGS += -DMR_ENCRYPTION_FAKE_PROPERTIES
|
||||
endif
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
@@ -30,12 +30,23 @@
|
||||
#include "../lib/log.h"
|
||||
#include "encryption.h"
|
||||
#include "../trampoline_encmnt/encmnt_defines.h"
|
||||
#include "../hooks.h"
|
||||
|
||||
static char encmnt_cmd_arg[64] = { 0 };
|
||||
static char *const encmnt_cmd[] = { "/mrom_enc/trampoline_encmnt", encmnt_cmd_arg, NULL };
|
||||
#ifdef MR_ENCRYPTION_FAKE_PROPERTIES
|
||||
static char *const encmnt_envp[] = { "LD_LIBRARY_PATH=/mrom_enc/", "LD_PRELOAD=/mrom_enc/libmultirom_fake_properties.so", NULL };
|
||||
#else
|
||||
static char *const encmnt_envp[] = { "LD_LIBRARY_PATH=/mrom_enc/", NULL };
|
||||
#endif
|
||||
static int g_decrypted = 0;
|
||||
|
||||
#ifdef __LP64__
|
||||
#define LINKER_PATH "/system/bin/linker64"
|
||||
#else
|
||||
#define LINKER_PATH "/system/bin/linker"
|
||||
#endif
|
||||
|
||||
int encryption_before_mount(struct fstab *fstab)
|
||||
{
|
||||
int exit_code = -1;
|
||||
@@ -43,10 +54,13 @@ int encryption_before_mount(struct fstab *fstab)
|
||||
int res = ENC_RES_ERR;
|
||||
|
||||
mkdir_recursive("/system/bin", 0755);
|
||||
remove("/system/bin/linker");
|
||||
symlink("/mrom_enc/linker", "/system/bin/linker");
|
||||
remove(LINKER_PATH);
|
||||
symlink("/mrom_enc/linker", LINKER_PATH);
|
||||
chmod("/mrom_enc/linker", 0775);
|
||||
chmod("/mrom_enc/trampoline_encmnt", 0775);
|
||||
// some fonts not in ramdisk to save space, so use regular instead
|
||||
symlink("/mrom_enc/res/Roboto-Regular.ttf", "/mrom_enc/res/Roboto-Italic.ttf");
|
||||
symlink("/mrom_enc/res/Roboto-Regular.ttf", "/mrom_enc/res/Roboto-Medium.ttf");
|
||||
|
||||
remove("/vendor");
|
||||
symlink("/mrom_enc/vendor", "/vendor");
|
||||
@@ -59,6 +73,10 @@ int encryption_before_mount(struct fstab *fstab)
|
||||
ERROR("Mounting /firmware for encryption failed with %s\n", strerror(errno));
|
||||
}
|
||||
|
||||
#if MR_DEVICE_HOOKS >= 6
|
||||
tramp_hook_encryption_setup();
|
||||
#endif
|
||||
|
||||
INFO("Running trampoline_encmnt\n");
|
||||
|
||||
strcpy(encmnt_cmd_arg, "decrypt");
|
||||
@@ -122,12 +140,15 @@ void encryption_destroy(void)
|
||||
}
|
||||
|
||||
// Make sure we're removing our symlink and not ROM's linker
|
||||
if(lstat("/system/bin/linker", &info) >= 0 && S_ISLNK(info.st_mode))
|
||||
remove("/system/bin/linker");
|
||||
if(lstat(LINKER_PATH, &info) >= 0 && S_ISLNK(info.st_mode))
|
||||
remove(LINKER_PATH);
|
||||
}
|
||||
|
||||
int encryption_cleanup(void)
|
||||
{
|
||||
#if MR_DEVICE_HOOKS >= 6
|
||||
tramp_hook_encryption_cleanup();
|
||||
#endif
|
||||
remove("/vendor");
|
||||
|
||||
if(access("/firmware", R_OK) >= 0 && umount("/firmware") < 0)
|
||||
|
||||
@@ -27,3 +27,14 @@ LOCAL_SRC_FILES := \
|
||||
include $(multirom_local_path)/device_defines.mk
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := libmultirom_fake_properties
|
||||
LOCAL_MODULE_TAGS := eng
|
||||
LOCAL_C_INCLUDES += $(multirom_local_path)
|
||||
|
||||
LOCAL_SRC_FILES := fake_properties.c
|
||||
|
||||
include $(multirom_local_path)/device_defines.mk
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
33
trampoline_encmnt/fake_properties.c
Normal file
33
trampoline_encmnt/fake_properties.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* This file is part of MultiROM.
|
||||
*
|
||||
* MultiROM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* MultiROM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with MultiROM. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/system_properties.h>
|
||||
|
||||
/* MultiROM doesn't initialize the property service,
|
||||
* but decryption on Nexus 6P waits for one property to become true
|
||||
* so we hardcode it here
|
||||
*/
|
||||
|
||||
int property_get(const char *key, char *value, const char *default_value)
|
||||
{
|
||||
if (!strcmp(key, "sys.listeners.registered"))
|
||||
default_value = "true";
|
||||
if (default_value)
|
||||
strncpy(value, default_value, PROP_VALUE_MAX);
|
||||
return strlen(value);
|
||||
}
|
||||
Reference in New Issue
Block a user