* RE: Simple LKM & copy_from_user question (followup)
@ 2001-07-20 20:26 David CM Weber
2001-07-20 20:38 ` Richard B. Johnson
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: David CM Weber @ 2001-07-20 20:26 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 1685 bytes --]
Attached is the file I"m having problems with. I'm compiling it w/
gcc -O3 -c main.c
Thanks in advance,
Dave Weber
Backbone Security, Inc.
570-422-7900
> -----Original Message-----
> From: David CM Weber
> Sent: Friday, July 20, 2001 12:45 PM
> To: linux-kernel@vger.kernel.org
> Subject: Simple LKM & copy_from_user question
>
>
> Hello all. I've been lurking for a while, and I have a quick
> question.
> I'm in the process of writing my first LKM to mess with the
> sys_socketcall function. I'm looking at the original one for
> guidance,
> and it makes a call to copy_from_user() to get some
> socket-related data.
>
> So, to use copy_from_user(), I've gathered that I need to #include
> <asm/uaccess.h>, so I do so.
>
> After including this file, I'm getting the following errors:
>
>
> .../linux/timer.h:21: field 'vec' has incomplete type
>
> .../asm/uaccess.h::63: dereferencing pointer to incomplete type
>
>
> (This is not a full list of the error message that it's reporting)
>
> Am I not setting a define correctly?
>
> I'm using Redhat 7.1, on an Intel P3 system. It's the latest stable
> release (2.4.x ??) of the kernel.
>
>
>
> If you need more information, please let me know. This has been
> troubling me for several days now..
>
>
> Thanks,
>
>
> Dave Weber
> Backbone Security, Inc.
> 570-422-7900
> -
> To unsubscribe from this list: send the line "unsubscribe
> linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
[-- Attachment #2: main.c --]
[-- Type: application/octet-stream, Size: 1904 bytes --]
#define MODULE // this is a LKM
#include <linux/module.h> // for Module access
//#include <linux/kernel.h> // For kernel access
#include <sys/syscall.h> // for the SYS_socketcall value
#include <linux/net.h> // For the various sys_socketcall parameters
//#include <asm/unistd.h>
#include <asm/errno.h> // For the error return values
#include <asm/uaccess.h> // for copy_from_user
// Define a debug print statement
#define BBPRINT(a) printk("%s(%i): %s\n", __FILE__, __LINE__, a)
// Type define a byte -> unsigned char
typedef unsigned char byte;
// Our friendly neighborhood system call table
extern void* sys_call_table[];
// Taken from socket.c
// Argument list sizes for sys_socketcall
#define AL(x) ((x) * sizeof(unsigned long))
static unsigned char nargs[18]={AL(0),AL(3),AL(3),AL(3),AL(2),AL(3),
AL(3),AL(3),AL(4),AL(4),AL(4),AL(6),
AL(6),AL(2),AL(5),AL(5),AL(3),AL(3)};
// Create our orginal function pointer
int (*original_socketcall)(int call, unsigned long *args);
// Our function's advance declaration
int my_socketcall(int call, unsigned long *args);
int init_module(void)
{
BBPRINT("Loading Socket LKM");
// Save the original location
original_socketcall = sys_call_table[SYS_socketcall];
// Replace the table entry with our socketcall
sys_call_table[SYS_socketcall] = my_socketcall;
return 0;
}
// This is run when the module is unloaded
void cleanup_module(void)
{
//Go back to the orignal socketcall
sys_call_table[SYS_socketcall] = original_socketcall;
BBPRINT("Unloading Socket LKM");
}
int my_socketcall(int call, unsigned long *args)
{
unsigned long a[6];
unsigned long a0,a1;
int err;
if(call < 1 || call > SYS_RECVMSG)
return -EINVAL;
// copy_from_user should be SMP safe.
if (copy_from_user(a, args, nargs[call]))
return -EFAULT;
a0=a[0];
a1=a[1];
// Call the original function
return(original_socketcall(call, args));
}
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: Simple LKM & copy_from_user question (followup)
2001-07-20 20:26 Simple LKM & copy_from_user question (followup) David CM Weber
@ 2001-07-20 20:38 ` Richard B. Johnson
2001-07-20 20:38 ` Randy.Dunlap
2001-07-20 20:59 ` John Polyakov
2 siblings, 0 replies; 5+ messages in thread
From: Richard B. Johnson @ 2001-07-20 20:38 UTC (permalink / raw)
To: David CM Weber; +Cc: linux-kernel
On Fri, 20 Jul 2001, David CM Weber wrote:
> Attached is the file I"m having problems with. I'm compiling it w/
>
> gcc -O3 -c main.c
>
> Thanks in advance,
>
>
> Dave Weber
> Backbone Security, Inc.
> 570-422-7900
>
Top line:
#define __KERNEL__
... compiles without any errors, one warning about an unused variable.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).
I was going to compile a list of innovations that could be
attributed to Microsoft. Once I realized that Ctrl-Alt-Del
was handled in the BIOS, I found that there aren't any.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Simple LKM & copy_from_user question (followup)
2001-07-20 20:26 Simple LKM & copy_from_user question (followup) David CM Weber
2001-07-20 20:38 ` Richard B. Johnson
@ 2001-07-20 20:38 ` Randy.Dunlap
2001-07-20 20:59 ` John Polyakov
2 siblings, 0 replies; 5+ messages in thread
From: Randy.Dunlap @ 2001-07-20 20:38 UTC (permalink / raw)
To: David CM Weber; +Cc: linux-kernel
Hi-
I'll suggest a few things for you.
cd to your linux tree and 'make modules'
Look at the gcc compile string there.
Try to copy it closely.
I added -I/path/to/linux/include and -D__KERNEL__
and compiled your module with no problem.
If you had included the complete messages, we could have
seen that it was using /usr/include/linux for header files
instead of header files from linux/include/* .
(at least that's what it did on my system)
~Randy
David CM Weber wrote:
>
> Attached is the file I"m having problems with. I'm compiling it w/
>
> gcc -O3 -c main.c
>
> Thanks in advance,
>
> Dave Weber
> Backbone Security, Inc.
> 570-422-7900
>
> > -----Original Message-----
> > From: David CM Weber
> > Sent: Friday, July 20, 2001 12:45 PM
> > To: linux-kernel@vger.kernel.org
> > Subject: Simple LKM & copy_from_user question
> >
> >
> > Hello all. I've been lurking for a while, and I have a quick
> > question.
> > I'm in the process of writing my first LKM to mess with the
> > sys_socketcall function. I'm looking at the original one for
> > guidance,
> > and it makes a call to copy_from_user() to get some
> > socket-related data.
> >
> > So, to use copy_from_user(), I've gathered that I need to #include
> > <asm/uaccess.h>, so I do so.
> >
> > After including this file, I'm getting the following errors:
> >
> >
> > .../linux/timer.h:21: field 'vec' has incomplete type
> >
> > .../asm/uaccess.h::63: dereferencing pointer to incomplete type
> >
> >
> > (This is not a full list of the error message that it's reporting)
> >
> > Am I not setting a define correctly?
> >
> > I'm using Redhat 7.1, on an Intel P3 system. It's the latest stable
> > release (2.4.x ??) of the kernel.
> >
> > If you need more information, please let me know. This has been
> > troubling me for several days now..
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Simple LKM & copy_from_user question (followup)
2001-07-20 20:26 Simple LKM & copy_from_user question (followup) David CM Weber
2001-07-20 20:38 ` Richard B. Johnson
2001-07-20 20:38 ` Randy.Dunlap
@ 2001-07-20 20:59 ` John Polyakov
2 siblings, 0 replies; 5+ messages in thread
From: John Polyakov @ 2001-07-20 20:59 UTC (permalink / raw)
To: David CM Weber; +Cc: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 549 bytes --]
On Fri, 20 Jul 2001 16:26:43 -0400
"David CM Weber" <dweber@backbonesecurity.com> wrote:
DCW> Attached is the file I"m having problems with. I'm compiling it w/
DCW> gcc -O3 -c main.c
DCW> Thanks in advance,
There is a Makefile for you in attachment.
Here is lsmod output:
It's work :)
[root@Sombre lkm]# lsmod
Module Size Used by
main 836 0 (unused)
NVdriver 660144 15 (autoclean)
[root@Sombre lkm]#
DCW> Dave Weber
DCW> Backbone Security, Inc.
DCW> 570-422-7900
---
WBR. //s0mbre
[-- Attachment #2: Makefile --]
[-- Type: text/plain, Size: 257 bytes --]
CC=gcc
MODCFLAGS := -Wall -Wwrite-strings -Wredundant-decls -O2 -DMODULE -D__KERNEL__ -DLINUX -I/usr/src/linux/include
MODCFLAGS1:= -O1 -D__KERNEL__ -DMODULE -Wall -DLINUX -I/usr/src/linux/include
main.o: main.c
$(CC) $(MODCFLAGS1) -c main.c
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: Simple LKM & copy_from_user question (followup)
@ 2001-07-20 20:52 David CM Weber
0 siblings, 0 replies; 5+ messages in thread
From: David CM Weber @ 2001-07-20 20:52 UTC (permalink / raw)
Cc: linux-kernel
God(Allah, Ganesh, or whom/whatever) bless you all. Turns out I am a
dumba** and forgot to define __KERNEL__
Thanks to all for your help. It's a valuable lesson that I'm sure
newbies make lots of..
Thanks,
Dave Weber
(Feeling somewhat idiotic)
Backbone Security, Inc.
570-422-7900
> -----Original Message-----
> From: Randy.Dunlap [mailto:rddunlap@osdlab.org]
> Sent: Friday, July 20, 2001 4:39 PM
> To: David CM Weber
> Cc: linux-kernel@vger.kernel.org
> Subject: Re: Simple LKM & copy_from_user question (followup)
>
>
> Hi-
>
> I'll suggest a few things for you.
>
> cd to your linux tree and 'make modules'
> Look at the gcc compile string there.
> Try to copy it closely.
>
> I added -I/path/to/linux/include and -D__KERNEL__
> and compiled your module with no problem.
>
> If you had included the complete messages, we could have
> seen that it was using /usr/include/linux for header files
> instead of header files from linux/include/* .
> (at least that's what it did on my system)
>
> ~Randy
>
>
> David CM Weber wrote:
> >
> > Attached is the file I"m having problems with. I'm compiling it w/
> >
> > gcc -O3 -c main.c
> >
> > Thanks in advance,
> >
> > Dave Weber
> > Backbone Security, Inc.
> > 570-422-7900
> >
> > > -----Original Message-----
> > > From: David CM Weber
> > > Sent: Friday, July 20, 2001 12:45 PM
> > > To: linux-kernel@vger.kernel.org
> > > Subject: Simple LKM & copy_from_user question
> > >
> > >
> > > Hello all. I've been lurking for a while, and I have a quick
> > > question.
> > > I'm in the process of writing my first LKM to mess with the
> > > sys_socketcall function. I'm looking at the original one for
> > > guidance,
> > > and it makes a call to copy_from_user() to get some
> > > socket-related data.
> > >
> > > So, to use copy_from_user(), I've gathered that I need to #include
> > > <asm/uaccess.h>, so I do so.
> > >
> > > After including this file, I'm getting the following errors:
> > >
> > >
> > > .../linux/timer.h:21: field 'vec' has incomplete type
> > >
> > > .../asm/uaccess.h::63: dereferencing pointer to incomplete type
> > >
> > >
> > > (This is not a full list of the error message that it's reporting)
> > >
> > > Am I not setting a define correctly?
> > >
> > > I'm using Redhat 7.1, on an Intel P3 system. It's the
> latest stable
> > > release (2.4.x ??) of the kernel.
> > >
> > > If you need more information, please let me know. This has been
> > > troubling me for several days now..
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-07-20 20:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-20 20:26 Simple LKM & copy_from_user question (followup) David CM Weber
2001-07-20 20:38 ` Richard B. Johnson
2001-07-20 20:38 ` Randy.Dunlap
2001-07-20 20:59 ` John Polyakov
2001-07-20 20:52 David CM Weber
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®