Skip to content

Commit

Permalink
Updated proot to use PROOT_TMPDIR env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
pelya committed Mar 22, 2015
1 parent 005468b commit 8893a5e
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 214 deletions.
2 changes: 1 addition & 1 deletion android-shmem
Submodule android-shmem updated 2 files
+3 −1 Android.mk
+20 −7 README.md
2 changes: 1 addition & 1 deletion build.sh
Expand Up @@ -56,7 +56,7 @@ cd ..
} || fail

[ -e libtalloc.a ] || {
[ -e talloc-2.1.0 ] || curl http://www.samba.org/ftp/talloc/talloc-2.1.0.tar.gz | tar xvz || fail
[ -e talloc-2.1.0 ] || curl -L http://www.samba.org/ftp/talloc/talloc-2.1.0.tar.gz | tar xvz || fail
cd talloc-2.1.0
make clean
env CC=arm-linux-gnueabihf-gcc CFLAGS="-flto -fpic" LD=arm-linux-gnueabihf-gcc LDFLAGS="-flto" ./configure build --cross-compile --cross-execute='qemu-arm-static /usr/arm-linux-gnueabihf/lib/ld-linux.so.3 --library-path /usr/arm-linux-gnueabihf/lib' || fail
Expand Down
Binary file modified dist-x86/proot
Binary file not shown.
Binary file modified dist/proot
Binary file not shown.
1 change: 1 addition & 0 deletions dist/proot.sh
Expand Up @@ -22,4 +22,5 @@ JAVA_PATH=/usr/lib/jvm/default-java/jre/bin:/usr/lib/jvm/default-java/bin
ls usr/lib/jvm/java-7-openjdk-*/bin > /dev/null 2>&1 && JAVA_PATH=/`echo usr/lib/jvm/java-7-openjdk-*/jre/bin`:/`echo usr/lib/jvm/java-7-openjdk-*/bin`
export PATH=/usr/local/sbin:/usr/local/bin:$JAVA_PATH:/usr/sbin:/usr/bin:/sbin:/bin
export "LD_PRELOAD=/libdisableselinux.so /libandroid-shmem.so"
export PROOT_TMPDIR=`pwd`/tmp
./proot -r `pwd` -w / -b /dev -b /proc -b /sys -b /system $STORAGE "$@"
4 changes: 2 additions & 2 deletions img/img-gimp-jessie-armhf.sh
Expand Up @@ -7,7 +7,7 @@ APT_CACHER=
[ -e /etc/init.d/apt-cacher ] && APT_CACHER=/localhost:3142
sudo qemu-debootstrap --arch=armhf --verbose \
--components=main,contrib,non-free \
--include=python-minimal,`cat img-gimp-wheezy.pkg` \
jessie $DIR http:/$APT_CACHER/ftp.ua.debian.org/debian/ \
--include=`cat img-gimp-wheezy.pkg` \
jessie $DIR http:/$APT_CACHER/ftp.de.debian.org/debian/ \
&& cat sources-jessie.list | sudo tee $DIR/etc/apt/sources.list > /dev/null \
&& sudo ./prepare-img-proot.sh --update-packages $DIR
217 changes: 8 additions & 209 deletions proot-android.patch
@@ -1,214 +1,13 @@
diff --git a/src/cli/care.c b/src/cli/care.c
index 8ece4bc..85a2bb6 100644
--- a/src/cli/care.c
+++ b/src/cli/care.c
@@ -175,9 +175,9 @@ static Binding *new_concealing_binding(Tracee *tracee, const char *path, bool mu
}

if (S_ISDIR(statl.st_mode))
- temp = create_temp_directory(NULL, tracee->tool_name);
+ temp = create_temp_directory(NULL, get_root(tracee), tracee->tool_name);
else
- temp = create_temp_file(NULL, tracee->tool_name);
+ temp = create_temp_file(NULL, get_root(tracee), tracee->tool_name);
if (temp == NULL) {
note(tracee, WARNING, INTERNAL, "can't conceal %s", path);
return NULL;
diff --git a/src/execve/enter.c b/src/execve/enter.c
index d5a9685..56227fa 100644
--- a/src/execve/enter.c
+++ b/src/execve/enter.c
@@ -39,6 +39,7 @@
#include "execve/elf.h"
#include "path/path.h"
#include "path/temp.h"
+#include "path/binding.h"
#include "tracee/tracee.h"
#include "syscall/syscall.h"
#include "syscall/sysnum.h"
@@ -475,7 +476,7 @@ static char *extract_loader(const Tracee *tracee, bool want_32bit_version)
char *loader_path = NULL;
FILE *file = NULL;

- file = open_temp_file(NULL, "prooted");
+ file = open_temp_file(NULL, get_root(tracee), "prooted");
if (file == NULL)
goto end;
fd = fileno(file);
diff --git a/src/execve/exit.c b/src/execve/exit.c
index 19cdbd9..7dff252 100644
--- a/src/execve/exit.c
+++ b/src/execve/exit.c
@@ -117,7 +117,7 @@ static int bind_proc_pid_auxv(const Tracee *ptracee)
TALLOC_FREE(binding);
}

- host_path = create_temp_file(ptracee->ctx, "auxv");
+ host_path = create_temp_file(ptracee->ctx, get_root(ptracee), "auxv");
if (host_path == NULL)
return -1;

diff --git a/src/extension/care/final.c b/src/extension/care/final.c
index 0a5f9fd..8f42225 100644
--- a/src/extension/care/final.c
+++ b/src/extension/care/final.c
@@ -37,6 +37,7 @@
#include "execve/ldso.h"
#include "path/path.h"
#include "path/temp.h"
+#include "path/binding.h"
#include "cli/note.h"

/**
@@ -160,7 +161,7 @@ static int archive_re_execute_sh(Care *care)
int status;
int i;

- file = open_temp_file(NULL, "care");
+ file = open_temp_file(NULL, get_root(tracee), "care");
if (file == NULL) {
note(NULL, ERROR, INTERNAL, "can't create temporary file for 're-execute.sh'");
return -1;
@@ -292,7 +293,7 @@ static int archive_concealed_accesses_txt(const Care *care)
if (care->concealed_accesses == NULL)
return 0;

- file = open_temp_file(NULL, "care");
+ file = open_temp_file(NULL, get_root(tracee), "care");
if (file == NULL) {
note(NULL, WARNING, INTERNAL,
"can't create temporary file for 'concealed-accesses.txt'");
@@ -314,7 +315,7 @@ static int archive_readme_txt(const Care *care)
{
FILE *file;

- file = open_temp_file(NULL, "care");
+ file = open_temp_file(NULL, get_root(tracee), "care");
if (file == NULL) {
note(NULL, WARNING, INTERNAL, "can't create temporary file for 'README.txt'");
return -1;
diff --git a/src/path/glue.c b/src/path/glue.c
index a21c548..c2a4f2b 100644
--- a/src/path/glue.c
+++ b/src/path/glue.c
@@ -118,7 +118,7 @@ mode_t build_glue(Tracee *tracee, const char *guest_path, char host_path[PATH_MA
/* Create the temporary directory where the "glue" rootfs will
* lie. */
if (tracee->glue == NULL) {
- tracee->glue = create_temp_directory(NULL, tracee->tool_name);
+ tracee->glue = create_temp_directory(NULL, get_root(tracee), tracee->tool_name);
if (tracee->glue == NULL) {
note(tracee, ERROR, INTERNAL, "can't create glue rootfs");
return 0;
diff --git a/src/path/temp.c b/src/path/temp.c
index bbcfb5f..5b4c42d 100644
index bbcfb5f..583a3a7 100644
--- a/src/path/temp.c
+++ b/src/path/temp.c
@@ -35,12 +35,14 @@ static int clean_temp_cwd()
note(NULL, WARNING, SYSTEM, "can't readlink '/proc/self/cwd'");
return ++nb_errors;
}
+#if 0
if (strncmp(prefix, P_tmpdir, length_tmpdir) != 0) {
note(NULL, ERROR, INTERNAL,
"trying to remove a directory outside of '%s', "
"please report this error.\n", P_tmpdir);
return ++nb_errors;
}
+#endif

dir = opendir(".");
if (dir == NULL) {
@@ -202,14 +204,14 @@ static int remove_temp_file(char *path)
* auto-freed if @context is NULL. This function returns NULL if an
* error occurred.
*/
-char *create_temp_name(TALLOC_CTX *context, const char *prefix)
+char *create_temp_name(TALLOC_CTX *context, const char *rootdir, const char *prefix)
{
char *name;

if (context == NULL)
context = talloc_autofree_context();
@@ -10,6 +10,8 @@

- name = talloc_asprintf(context, "%s/%s-%d-XXXXXX", P_tmpdir, prefix, getpid());
+ name = talloc_asprintf(context, "%s/tmp/%s-%d-XXXXXX", rootdir, prefix, getpid());
if (name == NULL) {
note(NULL, ERROR, INTERNAL, "can't allocate memory");
return NULL;
@@ -225,11 +227,11 @@ char *create_temp_name(TALLOC_CTX *context, const char *prefix)
* error, otherwise the absolute path name to the created directory
* (@prefix-ed).
*/
-const char *create_temp_directory(TALLOC_CTX *context, const char *prefix)
+const char *create_temp_directory(TALLOC_CTX *context, const char *rootdir, const char *prefix)
{
char *name;

- name = create_temp_name(context, prefix);
+ name = create_temp_name(context, rootdir, prefix);
if (name == NULL)
return NULL;

@@ -250,12 +252,12 @@ const char *create_temp_directory(TALLOC_CTX *context, const char *prefix)
* @context) is freed. This function returns NULL on error,
* otherwise the absolute path name to the created file (@prefix-ed).
*/
-const char *create_temp_file(TALLOC_CTX *context, const char *prefix)
+const char *create_temp_file(TALLOC_CTX *context, const char *rootdir, const char *prefix)
{
char *name;
int fd;

- name = create_temp_name(context, prefix);
+ name = create_temp_name(context, rootdir, prefix);
if (name == NULL)
return NULL;

@@ -275,13 +277,13 @@ const char *create_temp_file(TALLOC_CTX *context, const char *prefix)
* Like create_temp_file() but returns an open file stream to the
* created file. It's up to the caller to close returned stream.
*/
-FILE* open_temp_file(TALLOC_CTX *context, const char *prefix)
+FILE* open_temp_file(TALLOC_CTX *context, const char *rootdir, const char *prefix)
{
char *name;
FILE *file;
int fd;

- name = create_temp_name(context, prefix);
+ name = create_temp_name(context, rootdir, prefix);
if (name == NULL)
return NULL;

diff --git a/src/path/temp.h b/src/path/temp.h
index faa9341..ed7ca73 100644
--- a/src/path/temp.h
+++ b/src/path/temp.h
@@ -25,9 +25,9 @@

#include <talloc.h>

-extern char *create_temp_name(TALLOC_CTX *context, const char *prefix);
-extern const char *create_temp_directory(TALLOC_CTX *context, const char *prefix);
-extern const char *create_temp_file(TALLOC_CTX *context, const char *prefix);
-extern FILE* open_temp_file(TALLOC_CTX *context, const char *prefix);
+extern char *create_temp_name(TALLOC_CTX *context, const char *rootdir, const char *prefix);
+extern const char *create_temp_directory(TALLOC_CTX *context, const char *rootdir, const char *prefix);
+extern const char *create_temp_file(TALLOC_CTX *context, const char *rootdir, const char *prefix);
+extern FILE* open_temp_file(TALLOC_CTX *context, const char *rootdir, const char *prefix);

#endif /* TEMP_H */
diff --git a/src/syscall/socket.c b/src/syscall/socket.c
index 381ae64..ed765d2 100644
--- a/src/syscall/socket.c
+++ b/src/syscall/socket.c
@@ -116,7 +116,7 @@ int translate_socketcall_enter(Tracee *tracee, word_t *address, int size)

/* The translated path is too long to fit the sun_path
* array, so let's bind it to a shorter path. */
- shorter_host_path = create_temp_name(tracee->ctx, "proot");
+ shorter_host_path = create_temp_name(tracee->ctx, get_root(tracee), "proot");
if (shorter_host_path == NULL || strlen(shorter_host_path) > sizeof_path)
return -EINVAL;
#include "cli/note.h"

+#define P_tmpdir (getenv("PROOT_TMPDIR") != NULL ? getenv("PROOT_TMPDIR") : "/data/local/tmp")
+
/**
* Remove recursively the content of the current working directory.
* This latter has to lie in P_tmpdir (ie. "/tmp" on most systems).
2 changes: 1 addition & 1 deletion proot-src

0 comments on commit 8893a5e

Please sign in to comment.