[Nelug] ioctl() problem

Eddy Younger eddy at shofar.uklinux.net
Mon Feb 24 00:00:01 UTC 2003


peter.holmes at fopet-esl.com writes:
 > 
 > main() {
 >   int fd, data, retval;
 >   ulong ularg;
 >   fd = open( "foo", O_RDWR);
 >   if( fd < 0)  .. error handling.
 >   retval = ioctl( fd, FOO_IO, ularg);

I think this maybe  should be

	retval = ioctl( fd, FOO_IO, &ularg);

as the put_user() in your ioctl is going to use this as a pointer to
a user-space buffer into which it will copy out the "dat" value from
kernel space.

 >   printf("Data %d %lx\n", retval, ularg);
 >  ...... etc..
 > }
 > 
 > What I see on the terminal screen is:
 > 
 > Data 0 804977c 
 > -OR-
 > Data 0 bffff928
 > 
 > The first is when 'ularg' is allocated before "int fd, data, retval;"
 > and the second when it's allocated afterwards.
 > To me this looks very like a pointer being written into 'ularg'.
 > 
 > The '0' (zero) after "Data" indicates that the call has succeeded.
 > 
 > Part of foo_ioctl() code:
 > 
 > int foo_ioctl( struct inode *inode,  
 >                struct file *filep, 
 >                unsigned int cmd, 
 >                unsigned long arg)
 > {
 >    int dat, rval;
 >   <... test here for correct command 'cmd' ...>
 >  spin_lock( &foo_lock);
 >  switch (cmd)
 >     {
 >   case: FOO_IO:
 >      dat = _foo_pull( );
 >    spin_unlock( &foo_lock);
 >       rval = put_user( dat, (unsigned long *) arg);
 > #ifdef DEBUG
 >   printk( KERN_INFO "foo: read %d %x", rval, dat);
 > #endif
 >       return rval;
 >       break;
 >       .............  other case(s)
 > }
 > OK. The 'return()' isn't tidy but for debugging....
 > The printk() does what I expect and shows me correct data and zero return 
 > value,
 > i.e. the _foo_pull() works OK and put_user() doesn't find an error in my 
 > passed 'ulong'.
 > 
 > So where is it going wrong??
 > 
 > Linux 2.4.18, gcc 3, MDK8.2
 > 
 > If anyone can see my mistake I'd be SEVERELY obliged.
 > Call me 'stupid' if it's obvious, Peter otherwise.
 > 
 > _______________________________________________
 > Nelug mailing list
 > Nelug at mailman.lug.org.uk
 > http://mailman.lug.org.uk/mailman/listinfo/nelug

-- 
"We have always been quite clear that Win95 and Win98 are not the systems to
 use if you are in a hostile security environment." 
   Paul Leach <paulle at microsoft.com>

"We absolutely do recognize that the Internet is a hostile environment." 
   Paul Leach <paulle at microsoft.com> 




More information about the Nelug mailing list