LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-25-2004, 08:56 AM   #1
tkwsn
LQ Newbie
 
Registered: Jun 2004
Location: In my office
Distribution: RedHat/Fedora
Posts: 3

Rep: Reputation: 0
Kernel OOPS "Unable to handle kernel NULL pointer dereference"


OK... This one is quite unusual.

I wrote a simple mmap() routine so I could map some memory between the kernel and userland (I am doing some Netfilter hooks).

The module works fine. It compiles and loads great. Once it has been loaded, everything still works.

However, after I unload the module and run some other task (anything, ls, vi, gcc, doesn't matter), I get a nasty message "Unable to handle kernel NULL pointer dereference" and it locks up.

I ran memtest86 and it appears to be fine. If you want the source code for the module, I'll post it.
 
Old 06-25-2004, 09:26 AM   #2
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,108

Rep: Reputation: 311Reputation: 311Reputation: 311Reputation: 311
I don't think your module is fine if it's causing that problem. If this error occurs after the module is unloaded, you probably want to check your __exit routine to make sure that it's not screwing up any data structures in kernel space. Just out of curiousity, why can't you use the kernel routines copy_to_user and copy_from_user to pass data back and forth? Particularly if you don't have a lot of data to copy, that would probably be a lot safer.
 
Old 06-25-2004, 09:33 AM   #3
tkwsn
LQ Newbie
 
Registered: Jun 2004
Location: In my office
Distribution: RedHat/Fedora
Posts: 3

Original Poster
Rep: Reputation: 0
I heard that copy_from_user was slow. I'm looking at a structure every time a packet comes in to see if whoever sent it has logged into the system.

Here's the code, just in case I've forgotten to clean something up...
(It's really C, but I used php to give it the pretty colors)
PHP Code:
static int __init start(void)
  {
  
int i;
  
struct page *page;
  
struct net_device *brif;
  
brif dev_get_by_name("br0");
  
memmove(&mymac[0], &(brif[0].dev_addr[0]), 6);
  
myip inet_select_addr(brif0RT_SCOPE_LINK);
  if (
register_chrdev(34"filter", &mmapfilter_fops) < 0)
    {
    
printk("register_chrdev bombed!\n");
    return 
1;
    }
  
bc kmalloc(BC_BUF_SIZEGFP_KERNEL|GFP_DMA);
  if (
bc == (struct bridge_conn *)-1)
    return 
1;
  for (
i=0;i<MAX_BC;i++)
    {
    
bc[i].status=0;
    
bc[i].ipaddr=0;
    }
  for (
pagevirt_to_page(bc); page<virt_to_page(bc+BC_BUF_SIZE); page++)
    
set_bit(PG_reserved, &((page)->flags));
  
nfho.hook hook_func;
  
nfho.hooknum NF_IP_PRE_ROUTING;
  
nfho.pf PF_INET;
  
nfho.priority NF_IP_PRI_FIRST;
  
nf_register_hook(&nfho);
  
printk("Loaded netf, packet filter installed\n");
  return 
0;
  }
static 
void __exit end(void)
  {
  
spinlock_t exit_lock SPIN_LOCK_UNLOCKED;
  
unsigned long flags;
  
struct page *page;
  
spin_lock_irqsave(&exit_lockflags);
  
unregister_chrdev(34"filter");
  for (
pagevirt_to_page(bc); page<virt_to_page(bc+BC_BUF_SIZE); page++)
    
clear_bit(PG_reserved, &((page)->flags));
  
kfree(bc);
  
spin_unlock_irqrestore(&exit_lockflags);
  
nf_unregister_hook(&nfho);
  
printk("netf/packet filter removed\n");
  }
static 
int mmapfilter_open (struct inode *inodestruct file *filp)
  {
  
unsigned int dev MINOR(inode->i_rdev);
  if (
dev 1)
    return -
ENODEV;
  return 
0;
  }
static 
int mmapfilter_release (struct inode *inodestruct file *filp)
  {
  return 
0;
  }
static 
int mmapfilter_mmap (struct file *filpstruct vm_area_struct *vma)
  {
  
//unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
  
unsigned long pagepos = (unsigned long)bc;
  
unsigned long start vma->vm_startsize vma->vm_end-vma->vm_start;
  
vma->vm_flags |= (VM_IO VM_RESERVED VM_SHM);
  if (
size>BC_BUF_SIZE)
    return -
EINVAL;
  while (
size 0)
    {
    
page virt_to_phys((void *)pos);
    if (
remap_page_range(vmastartpagePAGE_SIZEvma->vm_page_prot))
      return -
EAGAIN;
    
start += PAGE_SIZE;
    
pos += PAGE_SIZE;
    
size -= PAGE_SIZE;
    }
  return 
0;
  } 
 
Old 06-30-2004, 08:38 AM   #4
tkwsn
LQ Newbie
 
Registered: Jun 2004
Location: In my office
Distribution: RedHat/Fedora
Posts: 3

Original Poster
Rep: Reputation: 0
Another thing I've found...

On kmalloc(), if I don't put in GFP_DMA, it gives me random Segmentation faults with a lot of registers & whatnot (I don't know what those are called...) but it doesn't crash. It also works normally when unloaded.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Oops: Unable to handle kernel NULL pointer dereference at virtual address with mysqld GoranTornqvist Fedora 2 12-09-2004 11:30 AM
Oops: Unable to handle kernel NULL pointer dereference at virtual address GoranTornqvist Linux - General 1 12-09-2004 10:58 AM
Strange kernel error: "Unable to handle kernel NULL pointer dereference..." EcceVery Debian 4 04-12-2004 06:34 AM
Unable to handle kernel NULL pointer dereference.... kadaver Slackware 2 12-19-2003 07:46 AM
Kernel Message:unable to handle kernel NULL pointer dereference at virtual address... dave_d Linux - General 0 02-14-2001 05:01 PM


All times are GMT -5. The time now is 03:22 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration