mirror of
https://github.com/adulau/aha.git
synced 2024-12-28 03:36:19 +00:00
Commented out my code from arch/um/kernel/exec aiming migration to aha.c
This commit is contained in:
parent
9fe3d93db2
commit
e10bc5fe3d
1 changed files with 122 additions and 121 deletions
|
@ -16,7 +16,7 @@
|
||||||
#include "skas.h"
|
#include "skas.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "internal.h"
|
#include "internal.h"
|
||||||
#include "aha.h"
|
#include "shared/aha.h"
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "linux/delay.h"
|
#include "linux/delay.h"
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ void flush_thread(void)
|
||||||
{
|
{
|
||||||
void *data = NULL;
|
void *data = NULL;
|
||||||
int ret;
|
int ret;
|
||||||
|
aha_test();
|
||||||
arch_flush_thread(¤t->thread.arch);
|
arch_flush_thread(¤t->thread.arch);
|
||||||
|
|
||||||
ret = unmap(¤t->mm->context.id, 0, STUB_START, 0, &data);
|
ret = unmap(¤t->mm->context.id, 0, STUB_START, 0, &data);
|
||||||
|
@ -82,15 +82,15 @@ long um_execve(char *file, char __user *__user *argv, char __user *__user *env)
|
||||||
* The filename is returned through parameters and the length of the string
|
* The filename is returned through parameters and the length of the string
|
||||||
* is returned. On error negative value is returned. See snprintf
|
* is returned. On error negative value is returned. See snprintf
|
||||||
*/
|
*/
|
||||||
int create_filename(char *fn, int size){
|
//int create_filename(char *fn, int size){
|
||||||
int a,b;
|
// int a,b;
|
||||||
long ncycles;
|
// long ncycles;
|
||||||
/* Query the processor cycles and concatenate it with a prefix */
|
/* Query the processor cycles and concatenate it with a prefix */
|
||||||
asm volatile("rdtsc" : "=a" (a), "=d" (b));
|
// asm volatile("rdtsc" : "=a" (a), "=d" (b));
|
||||||
ncycles = ((long long )a|(long long)b<<32);
|
// ncycles = ((long long )a|(long long)b<<32);
|
||||||
/* Return the length of the string, negative value on failure */
|
/* Return the length of the string, negative value on failure */
|
||||||
return snprintf(fn,size,"AHA_%lx.dat",ncycles);
|
// return snprintf(fn,size,"AHA_%lx.dat",ncycles);
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -102,82 +102,82 @@ int create_filename(char *fn, int size){
|
||||||
* TODO clone system calls should be monitored true aiming to avoid disrupted
|
* TODO clone system calls should be monitored true aiming to avoid disrupted
|
||||||
* trees
|
* trees
|
||||||
*/
|
*/
|
||||||
char* dump_execve(char __user *file, char __user *__user *argv,
|
//char* dump_execve(char __user *file, char __user *__user *argv,
|
||||||
char __user *__user *env)
|
// char __user *__user *env)
|
||||||
{
|
//{
|
||||||
char *p, *a, *q, *r;
|
// char *p, *a, *q, *r;
|
||||||
struct openflags flg;
|
// struct openflags flg;
|
||||||
int mode = 0644;
|
// int mode = 0644;
|
||||||
int fd,cnt;
|
// int fd,cnt;
|
||||||
struct task_struct *tsk;
|
// struct task_struct *tsk;
|
||||||
flg.w = 1;
|
// flg.w = 1;
|
||||||
flg.c = 1;
|
// flg.c = 1;
|
||||||
cnt = 0;
|
// cnt = 0;
|
||||||
r = NULL;
|
// r = NULL;
|
||||||
p = kmalloc(MAX_DUMP_BUF,GFP_KERNEL);
|
// p = kmalloc(MAX_DUMP_BUF,GFP_KERNEL);
|
||||||
q = kmalloc(MAX_DUMP_BUF, GFP_KERNEL);
|
// q = kmalloc(MAX_DUMP_BUF, GFP_KERNEL);
|
||||||
r = kmalloc(MAX_DUMP_BUF,GFP_KERNEL);
|
// r = kmalloc(MAX_DUMP_BUF,GFP_KERNEL);
|
||||||
if (p && q && r) {
|
// if (p && q && r) {
|
||||||
if (create_filename(r,MAX_DUMP_BUF)<0)
|
// if (create_filename(r,MAX_DUMP_BUF)<0)
|
||||||
return NULL;
|
// return NULL;
|
||||||
/* Go into output queue */
|
// /* Go into output queue */
|
||||||
cnt=snprintf(p,MAX_DUMP_BUF,"out/%s",r);
|
// cnt=snprintf(p,MAX_DUMP_BUF,"out/%s",r);
|
||||||
if ((cnt<0) | (cnt>MAX_DUMP_BUF))
|
// if ((cnt<0) | (cnt>MAX_DUMP_BUF))
|
||||||
return NULL;
|
// return NULL;
|
||||||
if ((fd = os_open_file(p,flg,mode))<0)
|
// if ((fd = os_open_file(p,flg,mode))<0)
|
||||||
return NULL;
|
// return NULL;
|
||||||
|
|
||||||
/* Dump the file from execve */
|
/* Dump the file from execve */
|
||||||
if (strncpy_from_user(p,file,MAX_DUMP_BUF) > 0){
|
// if (strncpy_from_user(p,file,MAX_DUMP_BUF) > 0){
|
||||||
cnt = snprintf((char*)q,MAX_DUMP_BUF,"file=%s\n",p);
|
// cnt = snprintf((char*)q,MAX_DUMP_BUF,"file=%s\n",p);
|
||||||
if ((cnt>0) & (cnt < MAX_DUMP_BUF))
|
// if ((cnt>0) & (cnt < MAX_DUMP_BUF))
|
||||||
os_write_file(fd,q,cnt);
|
// os_write_file(fd,q,cnt);
|
||||||
|
|
||||||
}
|
// }
|
||||||
/* Dump the arguments */
|
/* Dump the arguments */
|
||||||
for (;;) {
|
// for (;;) {
|
||||||
if (get_user(a,argv))
|
// if (get_user(a,argv))
|
||||||
break;
|
// break;
|
||||||
if (!a)
|
// if (!a)
|
||||||
break;
|
// break;
|
||||||
if (strncpy_from_user(p,a, MAX_DUMP_BUF) > 0) {
|
// if (strncpy_from_user(p,a, MAX_DUMP_BUF) > 0) {
|
||||||
cnt=snprintf(q,MAX_DUMP_BUF,"argument=%s\n",p);
|
// cnt=snprintf(q,MAX_DUMP_BUF,"argument=%s\n",p);
|
||||||
if ((cnt>0) & (cnt<MAX_DUMP_BUF))
|
// if ((cnt>0) & (cnt<MAX_DUMP_BUF))
|
||||||
os_write_file(fd,q,cnt);
|
// os_write_file(fd,q,cnt);
|
||||||
|
|
||||||
}
|
// }
|
||||||
argv++;
|
// argv++;
|
||||||
}
|
// }
|
||||||
/* Log PIDs and PPID */
|
/* Log PIDs and PPID */
|
||||||
tsk = current;
|
// tsk = current;
|
||||||
cnt = snprintf(q,MAX_DUMP_BUF,"pid=%d\n",tsk->pid);
|
// cnt = snprintf(q,MAX_DUMP_BUF,"pid=%d\n",tsk->pid);
|
||||||
if ((cnt>0) & (cnt<MAX_DUMP_BUF))
|
// if ((cnt>0) & (cnt<MAX_DUMP_BUF))
|
||||||
os_write_file(fd,q,cnt);
|
// os_write_file(fd,q,cnt);
|
||||||
cnt = snprintf(q,MAX_DUMP_BUF,"ppid=%d\n",tsk->parent->pid);
|
// cnt = snprintf(q,MAX_DUMP_BUF,"ppid=%d\n",tsk->parent->pid);
|
||||||
if ((cnt>0) & (cnt<MAX_DUMP_BUF))
|
// if ((cnt>0) & (cnt<MAX_DUMP_BUF))
|
||||||
os_write_file(fd,q,cnt);
|
// os_write_file(fd,q,cnt);
|
||||||
cnt = snprintf(q,MAX_DUMP_BUF,"rppid=%d\n",tsk->real_parent->pid);
|
// cnt = snprintf(q,MAX_DUMP_BUF,"rppid=%d\n",tsk->real_parent->pid);
|
||||||
if ((cnt>0) & (cnt<MAX_DUMP_BUF))
|
// if ((cnt>0) & (cnt<MAX_DUMP_BUF))
|
||||||
os_write_file(fd,q,cnt);
|
// os_write_file(fd,q,cnt);
|
||||||
|
|
||||||
|
|
||||||
/* FIXME the MAGIC word is not escaped it could emerge as argument */
|
/* FIXME the MAGIC word is not escaped it could emerge as argument */
|
||||||
cnt = snprintf(q,cnt,"DONE=1\n");
|
// cnt = snprintf(q,cnt,"DONE=1\n");
|
||||||
if ((cnt >0) & (cnt < MAX_DUMP_BUF))
|
// if ((cnt >0) & (cnt < MAX_DUMP_BUF))
|
||||||
os_write_file(fd,q,cnt);
|
// os_write_file(fd,q,cnt);
|
||||||
os_close_file(fd);
|
// os_close_file(fd);
|
||||||
kfree(p);
|
// kfree(p);
|
||||||
kfree(q);
|
// kfree(q);
|
||||||
}
|
// }
|
||||||
return r;
|
// return r;
|
||||||
}
|
//}
|
||||||
|
|
||||||
void handle_insult_messages(struct ReplyMessage *msg, char __user* file,
|
//void handle_insult_messages(struct ReplyMessage *msg, char __user* file,
|
||||||
char __user* __user* argv)
|
// char __user* __user* argv)
|
||||||
{
|
//{
|
||||||
char buf[16];
|
// char buf[16];
|
||||||
char* addr;
|
// char* addr;
|
||||||
int cnt;
|
// int cnt;
|
||||||
/* Simply swap the commands. Insult is a program in user - space that takes
|
/* Simply swap the commands. Insult is a program in user - space that takes
|
||||||
* as argv[0] an integer as argument which serves as index on a static
|
* as argv[0] an integer as argument which serves as index on a static
|
||||||
* list of insults. argv[0] is overwritten to ensure that we do not smash
|
* list of insults. argv[0] is overwritten to ensure that we do not smash
|
||||||
|
@ -188,66 +188,67 @@ void handle_insult_messages(struct ReplyMessage *msg, char __user* file,
|
||||||
* crashes
|
* crashes
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(!copy_to_user(file,"/sbin/insult",13)){
|
// if(!copy_to_user(file,"/sbin/insult",13)){
|
||||||
cnt = snprintf((char*)&buf,16,"%d",msg->insult);
|
// cnt = snprintf((char*)&buf,16,"%d",msg->insult);
|
||||||
if ((cnt > 0) && (cnt<16))
|
// if ((cnt > 0) && (cnt<16))
|
||||||
if (!get_user(addr,argv))
|
// if (!get_user(addr,argv))
|
||||||
copy_to_user(addr,buf,cnt+1); /* Copy 0 byte too */
|
// copy_to_user(addr,buf,cnt+1); /* Copy 0 byte too */
|
||||||
}
|
// }
|
||||||
/* The argument list should be already terminated by the other program */
|
/* The argument list should be already terminated by the other program */
|
||||||
}
|
//}
|
||||||
|
|
||||||
void get_reply_message(char* key, struct ReplyMessage *msg)
|
//void get_reply_message(char* key, struct ReplyMessage *msg)
|
||||||
{
|
//{
|
||||||
int fd,size;
|
// int fd,size;
|
||||||
char filename[128];
|
// char filename[128];
|
||||||
filename[0]=0;
|
// filename[0]=0;
|
||||||
snprintf((char*)filename,128,"in/%s",key);
|
// snprintf((char*)filename,128,"in/%s",key);
|
||||||
|
|
||||||
/* Give AHA the time to write the reply */
|
/* Give AHA the time to write the reply */
|
||||||
msleep_interruptible(50);
|
// msleep_interruptible(50);
|
||||||
fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
|
// fd = os_open_file(filename, of_read(OPENFLAGS()), 0);
|
||||||
if (fd <0){
|
// if (fd <0){
|
||||||
printk("Could not open reply file: %s\n",filename);
|
// printk("Could not open reply file: %s\n",filename);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
size = os_read_file(fd,msg,sizeof(struct ReplyMessage));
|
// size = os_read_file(fd,msg,sizeof(struct ReplyMessage));
|
||||||
/* Make sure that we got a complete message */
|
/* Make sure that we got a complete message */
|
||||||
if (size == sizeof(struct ReplyMessage)){
|
// if (size == sizeof(struct ReplyMessage)){
|
||||||
printk("AHA (%s) told me to ...\n",key);
|
// printk("AHA (%s) told me to ...\n",key);
|
||||||
printk("block %d\n",msg->block);
|
// printk("block %d\n",msg->block);
|
||||||
printk("exitcode: %d\n",msg->exitcode);
|
// printk("exitcode: %d\n",msg->exitcode);
|
||||||
printk("substitue: %d\n",msg->substitue);
|
// printk("substitue: %d\n",msg->substitue);
|
||||||
printk("insult:%d\n",msg->insult);
|
// printk("insult:%d\n",msg->insult);
|
||||||
}else
|
// }else
|
||||||
printk("The message %s is corrupted. Got only %d bytes\n",filename,
|
// printk("The message %s is corrupted. Got only %d bytes\n",filename,
|
||||||
size);
|
// size);
|
||||||
|
|
||||||
os_close_file(fd);
|
// os_close_file(fd);
|
||||||
}
|
//}
|
||||||
|
|
||||||
long sys_execve(char __user *file, char __user *__user *argv,
|
long sys_execve(char __user *file, char __user *__user *argv,
|
||||||
char __user *__user *env)
|
char __user *__user *env)
|
||||||
{
|
{
|
||||||
long error;
|
long error;
|
||||||
char *filename;
|
char *filename;
|
||||||
struct ReplyMessage msg;
|
aha_test2(argv);
|
||||||
filename = dump_execve(file,argv,env);
|
//struct ReplyMessage msg;
|
||||||
if (filename){
|
//filename = dump_execve(file,argv,env);
|
||||||
get_reply_message(filename,&msg);
|
//if (filename){
|
||||||
kfree(filename);
|
// get_reply_message(filename,&msg);
|
||||||
|
// kfree(filename);
|
||||||
/* Implement decisions taken by AHA */
|
/* Implement decisions taken by AHA */
|
||||||
if (msg.block) {
|
// if (msg.block) {
|
||||||
error = msg.exitcode;
|
// error = msg.exitcode;
|
||||||
goto out;
|
// goto out;
|
||||||
}
|
// }
|
||||||
if (msg.insult) {
|
// if (msg.insult) {
|
||||||
printk("I should insult, yeah\n");
|
// printk("I should insult, yeah\n");
|
||||||
handle_insult_messages(&msg,file,argv);
|
// handle_insult_messages(&msg,file,argv);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
}
|
//}
|
||||||
lock_kernel();
|
lock_kernel();
|
||||||
filename = getname(file);
|
filename = getname(file);
|
||||||
error = PTR_ERR(filename);
|
error = PTR_ERR(filename);
|
||||||
|
|
Loading…
Reference in a new issue