mirror of
https://github.com/drasko/codezero.git
synced 2026-02-27 17:23:13 +01:00
Elf file checking - Added the test that data and text are at least a page apart.
This commit is contained in:
@@ -71,7 +71,7 @@ int pager_open_bypath(struct tcb *pager, char *pathname)
|
|||||||
struct vnode *v;
|
struct vnode *v;
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
//printf("%s/%s\n", __TASKNAME__, __FUNCTION__);
|
||||||
if (pager->tid != PAGER_TID)
|
if (pager->tid != PAGER_TID)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,10 @@ int elf_mark_segments(struct elf_section_header *sect_header, int nsections,
|
|||||||
"bss segment in ELF file.\n", __FUNCTION__);
|
"bss segment in ELF file.\n", __FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Data and text are less than page apart and unaligned */
|
/* Data and text are on the same page and not on a page boundary */
|
||||||
|
if (!((is_page_aligned(task->data_start) &&
|
||||||
|
task->data_start == task->text_end) ||
|
||||||
|
(page_align(task->data_start) > page_align(task->text_end))))
|
||||||
if ((task->data_start - task->text_end) < PAGE_SIZE &&
|
if ((task->data_start - task->text_end) < PAGE_SIZE &&
|
||||||
!is_page_aligned(task->text_end)) {
|
!is_page_aligned(task->text_end)) {
|
||||||
printf("%s: Error: Distance between data and text"
|
printf("%s: Error: Distance between data and text"
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ int exectest(void)
|
|||||||
char filename[128];
|
char filename[128];
|
||||||
|
|
||||||
memset(filename, 0, 128);
|
memset(filename, 0, 128);
|
||||||
sprintf(filename, "/home/bahadir/execfile%d.txt", getpid());
|
sprintf(filename, "/home/bahadir/execfile%d", getpid());
|
||||||
|
|
||||||
/* First create a new file and write the executable data to that file */
|
/* First create a new file and write the executable data to that file */
|
||||||
if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
|
if ((fd = open(filename, O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
|
||||||
@@ -33,7 +33,7 @@ int exectest(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
left = size;
|
left = size;
|
||||||
printf("Writing %d bytes to %s\n", left, filename);
|
test_printf("Writing %d bytes to %s\n", left, filename);
|
||||||
while (left != 0) {
|
while (left != 0) {
|
||||||
if ((cnt = write(fd, exec_start, left)) < 0)
|
if ((cnt = write(fd, exec_start, left)) < 0)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
@@ -51,7 +51,7 @@ int exectest(void)
|
|||||||
argv[4] = 0;
|
argv[4] = 0;
|
||||||
|
|
||||||
/* Execute the file */
|
/* Execute the file */
|
||||||
execve("/home/bahadir/test1.axf", argv, 0);
|
execve(filename, argv, 0);
|
||||||
|
|
||||||
out_err:
|
out_err:
|
||||||
printf("EXECVE TEST -- FAILED --\n");
|
printf("EXECVE TEST -- FAILED --\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user