RE: IP address in the kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




hi jeremy,

i'm not sure if this will fix your problem, but the iname array is declared
to hold only 4 chars and the strcpy will copy 5 chars into it, potentially 
overwriting something important.  the 5th char is the null byte.

  >
  > strcpy(iname, "eth0");
  >

peace,

dan

> -----Original Message-----
> From: Jeremy Andrus [mailto:jandru39@calvin.edu]
> Sent: Friday, August 02, 2002 4:50 PM
> To: Kernelnewbies
> Cc: clug@calvin.edu
> Subject: IP address in the kernel
> 
> 
> OK. I've written some code based on Trevor Hamm's suggestions, but it 
> segfaults. Here's what I have:
> 
> ----- BEGIN CODE -----
>   struct in_device *in_dev;
>   struct in_ifaddr **ifap = NULL;
>   struct in_ifaddr *ifa = NULL;
>   struct net_device *dev;
>   struct in_addr in;
>   unsigned long pci_ip_dword;
>   char iname[4];
> 
>   strcpy(iname, "eth0");
>   if ( (dev = dev_get_by_name(iname)) == NULL ) {
>     printk("  |--> Couldn't find a network interface.\n");
>     printk("       You need at least one interface (eth0) for this 
> netfilter hook to work.\n");
>     return 0;
>   }
>   printk("Looking for 'eth0' . . .\n");
>   if ( (in_dev = in_dev_get(dev)) != NULL ) {
>     if (ifa == NULL) {
>       for (ifap=&in_dev->ifa_list; (ifa=*ifap) != NULL; 
> ifap=&ifa->ifa_next)
>         if (strcmp(iname, ifa->ifa_label) == 0)
>            break;
>     }
>   }
> 
>   printk("making dword . . .\n");
>   in.s_addr = ifa->ifa_local;
>   pci_ip_dword = (unsigned long)in.s_addr;
>   pci_ip_dword = (pci_ip_dword << 15);
>   pci_ip_dword = (pci_ip_dword & 0x7F800000);
>   printk("My IP address dword is: %lx\n", (unsigned 
> long)pci_ip_dword);
> 
> ----- END CODE -----
> 
> When I modprobe my netfilter target, dmesg has this in it:
> 
> ----- BEGIN DMESG DUMP -----
> Looking for 'eth0' . . .
> making dword . . .
> My IP address dword is: 54000000
> making a note of it . . .
> Unable to handle kernel NULL pointer dereference at virtual address 
> 00000011
>  printing eip:
> e0840a02
> *pde = 00000000
> Oops: 0002
> CPU:    0
> EIP:    0010:[<e0840a02>]    Not tainted
> EFLAGS: 00010286
> eax: 00000001   ebx: e08480b0   ecx: 30687465   edx: 00000001
> esi: 00000070   edi: e0848040   ebp: 00000000   esp: def73d74
> ds: 0018   es: 0018   ss: 0018
> Process iptables (pid: 102, stackpage=def73000)
> Stack: def73e08 e0848040 e08480d0 00000000 00000002 00000000 00000163 
> e084a040 
>        00000000 def73dc0 e084b000 c0126c4f def73dc0 00000000 e084833c 
> e0848040 
>        00000000 0004b000 00000000 00000000 e0841149 def73e08 0000000e 
> e0848000 
> Call Trace: [<c0126c4f>] [<e0841149>] [<e084161b>] [<e0842880>] 
> [<c01bf540>] 
>    [<c01bf5a2>] [<c01cabef>] [<c010ff03>] [<c01e0318>] [<c01e5c7a>] 
> [<c01b42f1>] 
>    [<c01b4996>] [<c0106c5b>] 
> 
> Code: ff 40 10 8b 42 34 80 48 14 18 89 53 04 b9 80 27 84 e0 ff 05 
> 
> ----- END DMESG DUMP -----
> 
> The pci_ip_dword isn't correct either. Grrrr. Kernel hacking. Grrrr.
> 
> 	-Jeremy 
> 
> 
> -- 
> ----------------------------
> Jeremy C. Andrus
> http://www.jeremya.com/
> ----------------------------
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 
> 
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux