Four minor changes:

1. return the right error code when trying to execute an unknown format
   binary.

2. remove intermediate objects on "make clean"

3. struct array should be local to array.c

4. fix portability issues in the test-suite

Change-Id: Ifa1fac2895ee6d835b5fd27549cee0c37231b35c
This commit is contained in:
Cédric VINCENT 2012-08-16 15:01:41 +02:00
parent f81e5db66f
commit 5bd655e25a
8 changed files with 77 additions and 23 deletions

View File

@ -60,7 +60,8 @@ CHECK_VERSION = VERSION=$$($(GIT) describe --tags --dirty --abbrev=8 --always 2>
then /bin/echo -e "\#undef VERSION\n\#define VERSION \"$${VERSION}\""; \
fi;
.SILENT .IGNORE .INTERMEDIATE: .check_readlinkat .check_readlinkat.o .check_process_vm .check_process_vm.o
CHECK_OBJECTS = .check_readlinkat .check_readlinkat.o .check_process_vm .check_process_vm.o
.SILENT .IGNORE .INTERMEDIATE: $(CHECK_OBJECTS)
.check_readlinkat.o: .check_readlinkat.c
$(COMPILE:echo=false) $(silently) || true
@ -124,7 +125,7 @@ DESTDIR = $(PREFIX)/bin
.PHONY: clean distclean install uninstall
clean distclean:
-$(RM) -f $(OBJECTS) proot $(DEPS) build.h
-$(RM) -f $(CHECK_OBJECTS) $(OBJECTS) proot $(DEPS) build.h
install: proot
$($(quiet)INSTALL) -D $< $(DESTDIR)/$<

View File

@ -55,14 +55,10 @@ int open_elf(const char *t_path, union elf_header *elf_header)
if (fd < 0)
return -errno;
status = read(fd, elf_header, sizeof(union elf_header));
if (status != sizeof(union elf_header)) {
status = -EACCES;
goto end;
}
/* Check if it is an ELF file. */
if ( ELF_IDENT(*elf_header, 0) != 0x7f
status = read(fd, elf_header, sizeof(union elf_header));
if (status < sizeof(union elf_header)
|| ELF_IDENT(*elf_header, 0) != 0x7f
|| ELF_IDENT(*elf_header, 1) != 'E'
|| ELF_IDENT(*elf_header, 2) != 'L'
|| ELF_IDENT(*elf_header, 3) != 'F') {

View File

@ -30,10 +30,19 @@
#include <stdarg.h> /* va_*, */
#include <stdint.h> /* uint32_t, */
#define ARRAY_INTERNALS
#include "tracee/array.h"
#undef ARRAY_INTERNALS
#include "arch.h"
struct _entry {
/* Pointer (tracee's address space) to the current value, if
* local == NULL. */
word_t remote;
/* Pointer (tracer's address space) to the current value, if
* local != NULL. */
void *local;
};
#include "tracee/array.h"
#include "tracee/mem.h"
#include "tracee/abi.h"
#include "build.h"

View File

@ -29,22 +29,13 @@
#include "tracee/reg.h"
#include "arch.h"
/* XXX shouldn't be instantiated. */
#if defined(ARRAY_INTERNALS)
struct _entry {
word_t remote; /* XXX if @local != NULL. */
void *local; /* XXX. */
};
#else
struct _entry;
#endif
struct array;
typedef int (*read_item_t)(struct array *array, size_t index, void **value);
typedef int (*write_item_t)(struct array *array, size_t index, const void *value);
typedef int (*compare_item_t)(struct array *array, size_t index, const void *reference);
typedef int (*sizeof_item_t)(struct array *array, size_t index);
struct _entry;
struct array {
struct _entry *_cache;
size_t length;

View File

@ -22,6 +22,8 @@ if $(echo ${PROOT} | grep -q valgrind); then
EXTRA='-E LD_PRELOAD=.*'
fi
unset LD_LIBRARY_PATH
env PROOT_FORCE_FOREIGN_BINARY=1 PATH=/tmp:/bin:/usr/bin ${PROOT} -r ${ROOTFS} -q echo ${TMP} | grep "^-U LD_LIBRARY_PATH ${EXTRA}-0 /bin/argv0 /bin/argv0 ${TMP_ABS}$"
env PROOT_FORCE_FOREIGN_BINARY=1 ${PROOT} -r ${ROOTFS} -q echo ${TMP_ABS} | grep "^-U LD_LIBRARY_PATH ${EXTRA}-0 /bin/argv0 /bin/argv0 ${TMP_ABS}$"

View File

@ -30,6 +30,7 @@ ${PROOT} -v -1 -r ${ROOTFS} -b ${TMP1}:${TMP2}/${TMP3}/${TMP4} -b /etc/fstab:${T
${PROOT} -v -1 -r ${ROOTFS} -b ${TMP1}:${TMP2}/${TMP3}/${TMP4}/motd -b /etc/fstab:${TMP2}/${TMP3}/motd cat ${TMP2}/${TMP3}/${TMP4}/motd | grep "^content of ${TMP1}$"
${PROOT} -v -1 -r ${ROOTFS} -b /etc/fstab:${TMP2}/${TMP3}/motd -b ${TMP1}:${TMP2}/${TMP3}/${TMP4}/motd cat ${TMP2}/${TMP3}/${TMP4}/motd | grep "^content of ${TMP1}$"
! chmod +rw ${ROOTFS}/${TMP2}
rm -fr ${ROOTFS}/${TMP2}
mkdir -p ${TMP2}
@ -54,4 +55,5 @@ ${PROOT} -b /bin:/this1/does/not/exist -b /tmp:/this2/does/not/exist ${ROOTFS}/b
${PROOT} -b /tmp:/this1/does/not/exist -b /bin:/this2/does/not/exist ${ROOTFS}/bin/readdir /this1/
${PROOT} -b /tmp:/this1/does/not/exist -b /bin:/this2/does/not/exist ${ROOTFS}/bin/readdir /this2/
! chmod +rw ${TMP1} ${TMP2}
rm -fr ${TMP1} ${TMP2}

View File

@ -6,6 +6,7 @@
#include <sys/time.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
int main()
{
@ -26,6 +27,6 @@ int main()
exit(EXIT_FAILURE);
status = lutimes(tmp, times);
exit(status < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
exit(status < 0 && errno != ENOSYS ? EXIT_FAILURE : EXIT_SUCCESS);
}

52
tests/test-xxxxxxxx.c Normal file
View File

@ -0,0 +1,52 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/stat.h>
extern char *environ[];
#define CONTENT "this isn't an executable"
int main(void)
{
char * const argv[] = { "argv0", "argv1", "argv2", NULL };
char tmp_name[] = "/tmp/proot-XXXXXX";
int status;
int fd;
status = execve("/tmp", argv, environ);
if (errno != EISDIR && errno != EACCES) { /* Actually the kernel returns -EACCES */
perror("execcve (1)");
exit(EXIT_FAILURE);
}
fd = mkstemp(tmp_name);
if (fd < 0) {
perror("mkstemp");
exit(EXIT_FAILURE);
}
status = write(fd, CONTENT, sizeof(CONTENT));
if (status != sizeof(CONTENT)) {
perror("write");
exit(EXIT_FAILURE);
}
close(fd);
status = chmod(tmp_name, 0700);
if (status < 0) {
perror("chmod");
exit(EXIT_FAILURE);
}
status = execve(tmp_name, argv, environ);
if (errno != ENOEXEC) {
perror("execve (2)");
exit(EXIT_FAILURE);
}
printf("Check the stack integrity: %F + %F\n", (double) status, (double) errno);
exit(EXIT_SUCCESS);
}