Article View: es.comp.os.linux.programacion
Article #12358Patch de syscall write()
From: tuxisuau
Date: Fri, 03 Aug 2001 04:20
Date: Fri, 03 Aug 2001 04:20
118 lines
3869 bytes
3869 bytes
This is a multi-part message in MIME format.
--------------090408030804040009040206
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
He escrito este LKM. Es un patch para la syscall write, que pretende
usar esta syscall para comunicarse con el kernel... pero a veces provoca
Oops y desconozco por qu�. Incluyo el source a continuacion por si
alguien ve el error o simplemente tiene curiosidad :).
----------
tuxisuau, tuxisuau@7a69ezine.org
http://tuxisuau.7a69ezine.org
--------------090408030804040009040206
Content-Type: text/plain;
name="tuxwrite.c"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="tuxwrite.c"
#define __KERNEL__
#define MODULE
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/version.h>
#include <linux/mm.h>
#include <linux/ctype.h>
#include <asm/unistd.h>
#define MAGIC_MSG "magic \0"
extern void *sys_call_table[];
int (*o_write)(int, char *, int);
int tux_write(int fd, char *buf, int count) {
int argc=0,c,quotes=0,arg,ptrarg;
char **argv=NULL;
char *buf_kernel=NULL;
if ((buf_kernel=(char *)kmalloc(count,GFP_KERNEL))) {
__generic_copy_from_user(buf_kernel, buf, count);
if (!strncmp(buf_kernel, MAGIC_MSG, strlen(MAGIC_MSG))) {
for (c=strlen(MAGIC_MSG)+1;c<=count;c++){
if (buf_kernel[c]=='\n'){
argc++;
break;
}
if (quotes==0){
if(buf_kernel[c]==34)
quotes=1;
if(buf_kernel[c]==' ')
argc++;
}
else {
if(buf_kernel[c]==34)
quotes=0;
}
}
if(quotes==1)
argc=0;
printk("detected %d arguments\n",argc);
if (argc>0) {
if ((argv=(char **)kmalloc(4*argc))) {
printk("parsing arguments\n");
c=strlen(MAGIC_MSG)-1;
quotes=0;
for(arg=0;arg<argc;arg++) {
c++;
if (quotes==1)
c++;
if (buf_kernel[c]==34){
c++;
quotes=1;
}
else
quotes=0;
ptrarg=c;
if (quotes==0)
while(!((buf_kernel[c]==' ')||(buf_kernel[c]=='\n')))
c++;
else
while(!((buf_kernel[c]==34)||(buf_kernel[c]=='\n')))
c++;
printk("Allocating RAM for ARG\n");
argv[arg]=(char *)kmalloc(c+1-ptrarg,GFP_KERNEL);
memset(argv[arg],0,c+1-ptrarg);
printk("Copying ARG\n");
strncpy(argv[arg],(buf_kernel+ptrarg),c-ptrarg);
}
}
printk("\n");
for(arg=0;arg<argc;arg++)
printk("Arg: %d Data: %s\n",arg,argv[arg]);
printk("Freeing RAM\n");
for(arg=0;arg<argc;arg++)
kfree(argv[arg]);
kfree(argv);
}
}
}
kfree(buf_kernel);
return (*o_write)(fd,buf,count);
}
int init_module() {
o_write=sys_call_table[__NR_write];
sys_call_table[__NR_write]=tux_write;
printk("Tux Write() patch installed!\n");
return 0;
}
void cleanup_module() {
sys_call_table[__NR_write]=o_write;
printk("Tux Write() patch removed!\n");
}
--------------090408030804040009040206--
Technical Details
Message-ID:
<3B6A2692.7020504@7a69ezine.org>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!skynet.be!fu-berlin.de!newsfeed.bcn.ttd.net!news.bcn.ttd.net!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: f86c8,91fdf2f1b09c505e,start X-Google-Attributes: gidf86c8,public X-Google-ArrivalTime: 2001-08-02 21:28:38 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!skynet.be!fu-berlin.de!newsfeed.bcn.ttd.net!news.bcn.ttd.net!not-for-mail From: tuxisuau <tuxisuau@7a69ezine.org> Newsgroups: es.comp.os.linux.programacion Subject: Patch de syscall write() Date: Fri, 03 Aug 2001 06:20:34 +0200 Organization: http://tuxisuau.7a69ezine.org Lines: 119 Message-ID: <3B6A2692.7020504@7a69ezine.org> NNTP-Posting-Host: 217.126.33.148 Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------090408030804040009040206" User-Agent: Mozilla/5.0 (X11; U; Linux 2.4.7 i686; en-US; rv:0.9.1) Gecko/20010620 X-Accept-Language: ca, es, en