Skip to content
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.

Commit

Permalink
Fix the initialization of bindings that point to "/proc/self".
Browse files Browse the repository at this point in the history
The problem was due to the new module that emulates symlinks in
"/proc": it is used to initialize bindings that point to "/proc/self",
when no tracee can be associated to "self".  In this case "self" must
be PRoot.

Reported-by: Alkino (proot-me/proot#3)
  • Loading branch information
cedric-vincent committed Jun 25, 2012
1 parent 2c38729 commit 8cac178
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/execve/execve.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ int translate_execve(struct tracee_info *tracee)
int size = 0;
int status;

assert(tracee != NULL);

status = get_sysarg_path(tracee, u_path, SYSARG_1);
if (status < 0)
return status;
Expand Down
11 changes: 7 additions & 4 deletions src/path/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <stdlib.h> /* atoi(3), strtol(3), */
#include <errno.h> /* E*, */
#include <assert.h> /* assert(3), */
#include <unistd.h> /* getpid(2), */

#include "path/proc.h"
#include "tracee/info.h"
Expand All @@ -39,25 +40,27 @@
* Unlike readlink(), this function includes the nul terminating byte
* to @result.
*/
enum action readlink_proc(struct tracee_info *tracee, char result[PATH_MAX],
enum action readlink_proc(const struct tracee_info *tracee, char result[PATH_MAX],
const char base[PATH_MAX], const char component[NAME_MAX],
enum path_comparison comparison)
{
struct tracee_info *known_tracee;
const struct tracee_info *known_tracee;
char proc_path[64]; /* 64 > sizeof("/proc//fd/") + 2 * sizeof(#ULONG_MAX) */
int status;
pid_t pid;

assert(comparison == compare_paths("/proc", base));

pid = (tracee != NULL ? tracee->pid : getpid());

/* Remember: comparison = compare_paths("/proc", base) */
switch (comparison) {
case PATHS_ARE_EQUAL:
/* Substitute "/proc/self" with "/proc/<PID>". */
if (strcmp(component, "self") != 0)
return DEFAULT;

status = snprintf(result, PATH_MAX, "/proc/%d", tracee->pid);
status = snprintf(result, PATH_MAX, "/proc/%d", pid);
if (status < 0 || status >= PATH_MAX)
return -EPERM;

Expand Down Expand Up @@ -163,7 +166,7 @@ enum action readlink_proc(struct tracee_info *tracee, char result[PATH_MAX],
* Unlike readlink(), this function includes the nul terminating byte
* to @result (but this byte is not counted in the returned value).
*/
size_t readlink_proc2(struct tracee_info *tracee, char result[PATH_MAX], const char referer[PATH_MAX])
size_t readlink_proc2(const struct tracee_info *tracee, char result[PATH_MAX], const char referer[PATH_MAX])
{
enum action action;
char base[PATH_MAX];
Expand Down
4 changes: 2 additions & 2 deletions src/path/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ enum action {
};


extern enum action readlink_proc(struct tracee_info *tracee, char result[PATH_MAX],
extern enum action readlink_proc(const struct tracee_info *tracee, char result[PATH_MAX],
const char path[PATH_MAX], const char component[NAME_MAX],
enum path_comparison comparison);

extern size_t readlink_proc2(struct tracee_info *tracee, char result[PATH_MAX], const char path[PATH_MAX]);
extern size_t readlink_proc2(const struct tracee_info *tracee, char result[PATH_MAX], const char path[PATH_MAX]);

#endif /* PROC_H */
2 changes: 2 additions & 0 deletions src/tracee/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ static struct pool *first_pool = NULL;
*/
void delete_tracee(struct tracee_info *tracee)
{
assert(tracee != NULL);

if (tracee->exe != NULL)
free(tracee->exe);

Expand Down
9 changes: 9 additions & 0 deletions tests/test-305ae31d.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
if [ -z `which mcookie` ] || [ -z `which ln` ] || [ -z `which true` ] || [ -z `which rm` ]; then
exit 125;
fi

TMP=$(mcookie)
ln -s /proc/self/mounts ${TMP}
${PROOT} -b ${TMP} true
rm ${TMP}

0 comments on commit 8cac178

Please sign in to comment.