mirror of
https://github.com/adulau/aha.git
synced 2024-12-27 03:06:10 +00:00
Tried to split up the code
This commit is contained in:
parent
2f50e920ff
commit
f8929ed150
2 changed files with 66 additions and 51 deletions
|
@ -1,5 +1,7 @@
|
|||
#ifndef AHA
|
||||
#define AHA
|
||||
|
||||
#define AHA_DEBUG
|
||||
#include "linux/kernel.h" /* printk is declared there */
|
||||
//#include "linux/gfp.h" /* GFP_KERNEL */
|
||||
|
||||
|
@ -25,7 +27,11 @@ struct ReplyMessage{
|
|||
int substitue;
|
||||
int insult;
|
||||
};
|
||||
|
||||
#ifdef AHA_DEBUG
|
||||
#define AHA_PRINTK(args...) printk(args)
|
||||
#else
|
||||
#define AHA_PRINTK(...)
|
||||
#endif
|
||||
int aha_create_filename(char *fn, int size);
|
||||
char* aha_dump_execve(char __user *file, char __user *__user *argv,\
|
||||
char __user *__user *env);
|
||||
|
|
|
@ -19,8 +19,35 @@ int aha_create_filename(char *fn, int size)
|
|||
return snprintf(fn,size,"AHA_%lx.dat",ncycles);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tansfers the file names and arguments to the host OS
|
||||
inline void __aha_os_write_file_ck(int fd, char* buf, int cnt)
|
||||
{
|
||||
if ((cnt > 0) & (cnt < MAX_DUMP_BUF)){
|
||||
os_write_file(fd,buf,cnt);
|
||||
}
|
||||
}
|
||||
|
||||
/* Log PIDs and PPID */
|
||||
inline void __aha_dump_pid_ppids(int fd,char* buf,int cnt)
|
||||
{
|
||||
struct task_struct *tsk;
|
||||
tsk = current;
|
||||
cnt = snprintf(buf,MAX_DUMP_BUF,"pid=%d\n",tsk->pid);
|
||||
__aha_os_write_file_ck(fd,buf,cnt);
|
||||
cnt = snprintf(buf,MAX_DUMP_BUF,"ppid=%d\n",tsk->parent->pid);
|
||||
__aha_os_write_file_ck(fd,buf,cnt);
|
||||
cnt = snprintf(buf,MAX_DUMP_BUF,"rppid=%d\n",tsk->real_parent->pid);
|
||||
__aha_os_write_file_ck(fd,buf,cnt);
|
||||
}
|
||||
|
||||
inline void __aha_set_done_tag(int fd, char* buf,int cnt)
|
||||
{
|
||||
/* FIXME the MAGIC word is not escaped it could emerge as argument */
|
||||
cnt = snprintf(buf,cnt,"DONE=1\n");
|
||||
__aha_os_write_file_ck(fd,buf,cnt);
|
||||
|
||||
}
|
||||
|
||||
/* Tansfers the file names and arguments to the host OS
|
||||
* The transfer via files is an good awfull solution.
|
||||
* The dumping is done in a best effort manner. If it succeds
|
||||
* to write all the data the tag / line DONE is at the end of the
|
||||
|
@ -32,70 +59,52 @@ char* aha_dump_execve(char __user *file, char __user *__user *argv,
|
|||
char __user *__user *env)
|
||||
{
|
||||
char *p, *a, *q, *r;
|
||||
struct openflags flg;
|
||||
int mode = 0644;
|
||||
int fd,cnt;
|
||||
struct task_struct *tsk;
|
||||
struct openflags flg;
|
||||
r = NULL;
|
||||
flg.w = 1;
|
||||
flg.c = 1;
|
||||
cnt = 0;
|
||||
r = NULL;
|
||||
|
||||
/* Allocate memory once to win time */
|
||||
p = kmalloc(MAX_DUMP_BUF,GFP_KERNEL);
|
||||
q = kmalloc(MAX_DUMP_BUF, GFP_KERNEL);
|
||||
r = kmalloc(MAX_DUMP_BUF,GFP_KERNEL);
|
||||
if (p && q && r) {
|
||||
if (aha_create_filename(r,MAX_DUMP_BUF)<0)
|
||||
return NULL;
|
||||
if (!(p && q && r))
|
||||
return NULL;
|
||||
if (aha_create_filename(r,MAX_DUMP_BUF)<0)
|
||||
return NULL;
|
||||
/* Go into output queue */
|
||||
cnt=snprintf(p,MAX_DUMP_BUF,"out/%s",r);
|
||||
if ((cnt<0) | (cnt>MAX_DUMP_BUF))
|
||||
return NULL;
|
||||
if ((fd = os_open_file(p,flg,mode))<0)
|
||||
return NULL;
|
||||
cnt=snprintf(p,MAX_DUMP_BUF,"out/%s",r);
|
||||
if ((cnt<0) | (cnt>MAX_DUMP_BUF))
|
||||
return NULL;
|
||||
if ((fd = os_open_file(p,flg,mode))<0)
|
||||
return NULL;
|
||||
|
||||
/* Dump the file from execve */
|
||||
if (strncpy_from_user(p,file,MAX_DUMP_BUF) > 0){
|
||||
cnt = snprintf((char*)q,MAX_DUMP_BUF,"file=%s\n",p);
|
||||
if ((cnt>0) & (cnt < MAX_DUMP_BUF))
|
||||
os_write_file(fd,q,cnt);
|
||||
|
||||
}
|
||||
/* Dump the arguments */
|
||||
for (;;) {
|
||||
if (get_user(a,argv))
|
||||
break;
|
||||
/* Dump the file from execve */
|
||||
if (strncpy_from_user(p,file,MAX_DUMP_BUF) > 0){
|
||||
cnt = snprintf((char*)q,MAX_DUMP_BUF,"file=%s\n",p);
|
||||
__aha_os_write_file_ck(fd,q,cnt);
|
||||
}
|
||||
/* Dump the arguments */
|
||||
for (;;) {
|
||||
if (get_user(a,argv))
|
||||
break;
|
||||
if (!a)
|
||||
break;
|
||||
if (strncpy_from_user(p,a, MAX_DUMP_BUF) > 0) {
|
||||
cnt=snprintf(q,MAX_DUMP_BUF,"argument=%s\n",p);
|
||||
if ((cnt>0) & (cnt<MAX_DUMP_BUF))
|
||||
os_write_file(fd,q,cnt);
|
||||
|
||||
__aha_os_write_file_ck(fd,q,cnt);
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
/* Log PIDs and PPID */
|
||||
tsk = current;
|
||||
cnt = snprintf(q,MAX_DUMP_BUF,"pid=%d\n",tsk->pid);
|
||||
if ((cnt>0) & (cnt<MAX_DUMP_BUF))
|
||||
os_write_file(fd,q,cnt);
|
||||
cnt = snprintf(q,MAX_DUMP_BUF,"ppid=%d\n",tsk->parent->pid);
|
||||
if ((cnt>0) & (cnt<MAX_DUMP_BUF))
|
||||
os_write_file(fd,q,cnt);
|
||||
cnt = snprintf(q,MAX_DUMP_BUF,"rppid=%d\n",tsk->real_parent->pid);
|
||||
if ((cnt>0) & (cnt<MAX_DUMP_BUF))
|
||||
os_write_file(fd,q,cnt);
|
||||
|
||||
|
||||
/* FIXME the MAGIC word is not escaped it could emerge as argument */
|
||||
cnt = snprintf(q,cnt,"DONE=1\n");
|
||||
if ((cnt >0) & (cnt < MAX_DUMP_BUF))
|
||||
os_write_file(fd,q,cnt);
|
||||
os_close_file(fd);
|
||||
kfree(p);
|
||||
kfree(q);
|
||||
}
|
||||
return r;
|
||||
__aha_dump_pid_ppids(fd,q,cnt);
|
||||
__aha_set_done_tag(fd,q,cnt);
|
||||
os_close_file(fd);
|
||||
kfree(p);
|
||||
kfree(q);
|
||||
|
||||
return r; /* Return the filename that was created */
|
||||
}
|
||||
|
||||
void aha_handle_insult_messages(struct ReplyMessage *msg, char __user* file,
|
||||
|
|
Loading…
Reference in a new issue