[t19] Improve cleanup after decryption in trampoline

This commit is contained in:
Vojtech Bocek
2015-03-07 15:30:45 +01:00
parent 6b14068b8c
commit 222af62472
3 changed files with 22 additions and 17 deletions

View File

@@ -20,6 +20,8 @@
#include <ctype.h>
#include <stdio.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>
#include "../lib/fstab.h"
#include "../lib/util.h"
@@ -30,6 +32,7 @@
static char encmnt_cmd_arg[64] = { 0 };
static char *const encmnt_cmd[] = { "/mrom_enc/trampoline_encmnt", encmnt_cmd_arg, NULL };
static char *const encmnt_envp[] = { "LD_LIBRARY_PATH=/mrom_enc/", NULL };
static int g_decrypted = 0;
int encryption_before_mount(struct fstab *fstab)
{
@@ -81,6 +84,8 @@ int encryption_before_mount(struct fstab *fstab)
goto exit;
}
g_decrypted = 1;
struct fstab_part *datap = fstab_find_first_by_path(fstab, "/data");
if(!datap)
{
@@ -97,34 +102,34 @@ exit:
return res;
}
int encryption_destroy(void)
void encryption_destroy(void)
{
int res = -1;
int exit_code = -1;
char *output = NULL;
struct stat info;
strcpy(encmnt_cmd_arg, "remove");
output = run_get_stdout_with_exit_with_env(encmnt_cmd, &exit_code, encmnt_envp);
if(exit_code != 0)
if(g_decrypted)
{
ERROR("Failed to run trampoline_encmnt: %s", output);
goto exit;
strcpy(encmnt_cmd_arg, "remove");
output = run_get_stdout_with_exit_with_env(encmnt_cmd, &exit_code, encmnt_envp);
if(exit_code != 0)
ERROR("Failed to run trampoline_encmnt: %s\n", output);
g_decrypted = 0;
free(output);
}
remove("/system/bin/linker");
res = 0;
exit:
free(output);
return res;
// 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");
}
int encryption_cleanup(void)
{
remove("/vendor");
if(umount("/firmware") < 0)
ERROR("encryption_cleanup: failed to unmount /firmware: %s", strerror(errno));
if(access("/firmware", R_OK) >= 0 && umount("/firmware") < 0)
ERROR("encryption_cleanup: failed to unmount /firmware: %s\n", strerror(errno));
rmdir("/firmware");
return 0;

View File

@@ -24,11 +24,11 @@
#ifdef MR_ENCRYPTION
int encryption_before_mount(struct fstab *fstab);
int encryption_destroy(void);
void encryption_destroy(void);
int encryption_cleanup(void);
#else
int encryption_before_mount(struct fstab *fstab) { return ENC_RES_OK; }
int encryption_destroy(void) { return 0; }
void encryption_destroy(void) { }
int encryption_cleanup(void) { return 0; }
#endif

View File

@@ -18,7 +18,7 @@
#ifndef VERSION_H
#define VERSION_H
#define VERSION_MULTIROM 32
#define VERSION_TRAMPOLINE 18
#define VERSION_TRAMPOLINE 19
// For device-specific fixes. Use letters, the version will then be like "12a"
#define VERSION_DEV_FIX ""