Queries about Net-Filter Hooks !!!
HI Friends, Trying to Play with Net-Filter Hooks and here are my Queries! 1] While adding a New UDP/IP Header over the received skbuffer from NetFilter Module;need to fill the UDP Check-sum. Please let me know ; if there is any Kernel Function which we can use to do this Job ??? OR Do I need to write our own Function to calculate the Check-sum ??? 2] Once after adding New Headers to the received skbuffer ; am trying to return NF_ACCEPT. My Understanding was that ; the newly expanded skbuffer with added Headers will be again taken my Net-Filter Hooks Module and will deliver back to the net device. rt? OR Was there some thing more that I should do ; to send the new skbuffer to the device ?? Looking forward for the reply !! -Thanks in Advance, VKS ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Filtering USB storage data in kernel module
On 11/18/2011 09:05 PM, Abhijit Pawar wrote: On 11/18/2011 08:16 PM, Greg KH wrote: On Fri, Nov 18, 2011 at 06:36:18PM +0530, Abhijit Pawar wrote: On 11/17/2011 08:19 PM, Greg KH wrote: On Thu, Nov 17, 2011 at 02:15:35PM +0530, Abhijit Pawar wrote: Hi All, I need to filter the data written/read to and from the USB storage disk. Why? I want to build a secure machine with data protection. I want to have a security around the machine where anyone can attach a usb disk and copy the data. but i want to make the copied data useless unless it has the trust relation with the host to which its connected. So if one has copied data from one secured machine and get that usb disk to other machine, he should see the encrypted garbage data. Interesting idea. What are you wanting to do at filter time? I want to encrypt the write data packets and decrypt the read data packets. Why just USB disks? What makes them special? They are the one which can be attached to the system easily. How are you going to determine if a disk is a USB device or not? You forgot to answer this question :) Yeah, I forgot that one. I am not very sure but if I can patch the USB core before it attaches the speficied class driver to the USB device. May be I can try and send some control request and get the class of the device. I think its not required as USB core itself will understand the class of the device and try to attach the proper driver. At this point of time, I will have some patch which will pass on the information to my module. I am not sure if there are any intercepting points or any functions / structures exported in the USB core stack. It seems that the Linux notification chain should give me information whenever a USB device is added. I need to register for a notification callback in my module. I have written a small module for this which uses the usb_register_notify() Here is the debug trace from kernel when I add my logitech mouse to the system. I get the device added notification. [30540.541134] usb 2-1.3: New USB device found, idVendor=046d, idProduct=c018 [30540.541143] usb 2-1.3: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [30540.541150] usb 2-1.3: Product: USB Optical Mouse [30540.541155] usb 2-1.3: Manufacturer: Logitech [30540.541162] device: '2-1.3': device_add [30540.541172] kobject: '2-1.3' (8800252b0898): kobject_add_internal: parent: '2-1', set: 'devices' [30540.549243] bus: 'usb': add device 2-1.3 [30540.549324] PM: Adding info for usb:2-1.3 [30540.549372] kobject: '2-1.3' (8800252b0898): kobject_uevent_env [30540.549384] kobject: '2-1.3' (8800252b0898): fill_kobj_path: path = '/devices/pci:00/:00:1d.0/usb2/2-1/2-1.3' [30540.549473] bus: 'usb': driver_probe_device: matched device 2-1.3 with driver usb [30540.549482] bus: 'usb': really_probe: probing driver usb with device 2-1.3 [30540.549512] usb 2-1.3: rpm_resume flags 0x4 [30540.549518] usb 2-1.3: rpm_resume returns 1 [30540.550214] device: '2-1.3:1.0': device_add [30540.550232] kobject: '2-1.3:1.0' (880100648040): kobject_add_internal: parent: '2-1.3', set: 'devices' [30540.550553] bus: 'usb': add device 2-1.3:1.0 [30540.550643] PM: Adding info for usb:2-1.3:1.0 [30540.550661] kobject: '2-1.3:1.0' (880100648040): kobject_uevent_env [30540.550678] kobject: '2-1.3:1.0' (880100648040): fill_kobj_path: path = '/devices/pci:00/:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0' [30540.550905] bus: 'usb': driver_probe_device: matched device 2-1.3:1.0 with driver usbserial_generic [30540.550923] bus: 'usb': really_probe: probing driver usbserial_generic with device 2-1.3:1.0 [30540.551178] usb 2-1.3: rpm_resume flags 0x4 [30540.551189] usb 2-1.3: rpm_resume returns 1 [30540.551458] bus: 'usb': driver_probe_device: matched device 2-1.3:1.0 with driver usbhid [30540.551473] bus: 'usb': really_probe: probing driver usbhid with device 2-1.3:1.0 [30540.551513] usb 2-1.3: rpm_resume flags 0x4 [30540.551523] usb 2-1.3: rpm_resume returns 1 [30540.552922] device: '0003:046D:C018.0002': device_add [30540.552939] kobject: '0003:046D:C018.0002' (88012b5b9898): kobject_add_internal: parent: '2-1.3:1.0', set: 'devices' [30540.552981] bus: 'hid': add device 0003:046D:C018.0002 [30540.553143] PM: Adding info for hid:0003:046D:C018.0002 [30540.553159] kobject: '0003:046D:C018.0002' (88012b5b9898): kobject_uevent_env [30540.553176] kobject: '0003:046D:C018.0002' (88012b5b9898): fill_kobj_path: path = '/devices/pci:00/:00:1d.0/usb2/2-1/2-1.3/2-1.3:1.0/0003:046D:C018.0002' [30540.553352] bus: 'hid': driver_probe_device: matched device 0003:046D:C018.0002 with driver generic-usb [30540.553369] bus: 'hid': really_probe: probing driver generic-usb with device 0003:046D:C018.0002 [30540.555608] device: 'input17': device_add [30540.555628] kobject: 'input' (8800619af5a0): kobject_add_internal: parent: '2-1.3:1.0', set: '(null)' [30540.555677] kobject: 'input17'
[no subject]
..Do you want to feel something new? Do you want to feel new unforgettable sensations? This is for you! http://un-ocean.fr/p.g.php?wellink_friend_id=14ox0 ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
LPC bus access howto
Hi all, We have a FPGA which will be connected to the LPC bus. This FPGA will provide some GPIO functionality, a rotary encoder, etc. Now i want to write a kernel driver to talk to this FPGA. I am unsure how to get access to the LPC bus in the first place. What kernel APIs should i use? How to get the memory mapping right, etc? I would appreciate any pointers to documentation or examples. cheers, Andre ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
serial: 8250: RX hang issue
Hi All, I am working on a mobile development platform and performing some stress warm boot tests using UART debug console(which is using serial 8250 driver for console). I am getting device debug console UART RX hang after iterations 1500. after this issue am not* able to issue any command. Able to see logs though. Later I kept some debug prints in isr and able to see that device is able to generate interrupts when some data is received. So I came to conclusion that some malfunctioning is happening in upper layer not sure which layer has this problem. Can some one give some ideas at which layer I can check? One more observation is when I perform a open and close calls on debug UART port(in my case ttyS0) while device is in UART RX hang state, then I notice the UART console RX again below active and able issue commands from UART console itself. ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: LPC bus access howto
On Mon, 21 Nov 2011 17:01:29 +0100 Andre Haupt an...@bitwigglers.org wrote: Hi all, We have a FPGA which will be connected to the LPC bus. This FPGA will provide some GPIO functionality, a rotary encoder, etc. Now i want to write a kernel driver to talk to this FPGA. I am unsure how to get access to the LPC bus in the first place. What kernel APIs should i use? How to get the memory mapping right, etc? The LPC is typically automatically mapped by the hardware (southbridge) for some fixed ranges, various configurable ranges and might also use PCI substractive decoding. LPC is indeed an ISA bus with the physical layer replaced by something with fewer signals, but from the point of view of the software there is almost no difference, so look for how to program ISA drivers and you will probably have your answer. -- Guillaume Knispel Avencall - 10 bis, rue Lucien Voilin - 92800 Puteaux Tel. : (+33) 141 389 960 ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
sock_buff is NULL !
HI Team, Trying to make this code work; but some how it is entering the if condition mentioned below.sock_buff is still a NULL Pointer.I can see that Function was registered with the Ipv4 Hooks. Any ideas/scenarios where the sock_buff remains as NULL Pointer??? Testing this code by trying to do ssh with this machine. Any Help is really appreciated !! # static struct nf_hook_ops netfilter_ops; struct sk_buff *sock_buff; unsigned int main_hook(unsigned int hooknum,struct sk_buff **skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff*)) { sock_buff = *skb; if(!sock_buff){ printk(KERN_ERR Entered unexpected loop \n); return NF_ACCEPT; }/* Check for sk_buff NULL */ } int init_module() { netfilter_ops.hook = (nf_hookfn *) main_hook; netfilter_ops.hooknum = NF_INET_PRE_ROUTING; netfilter_ops.pf= PF_INET; netfilter_ops.priority = NF_IP_PRI_FIRST; nf_register_hook(netfilter_ops); } ## -Thnx, VKS ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
RE: sock_buff is NULL !
From: kernelnewbies-boun...@kernelnewbies.org [mailto:kernelnewbies-boun...@kernelnewbies.org] On Behalf Of Kesava Srinivas Sent: Monday, November 21, 2011 11:03 AM To: kernelnewbies@kernelnewbies.org Subject: sock_buff is NULL ! HI Team, Trying to make this code work; but some how it is entering the if condition mentioned below.sock_buff is still a NULL Pointer.I can see that Function was registered with the Ipv4 Hooks. Any ideas/scenarios where the sock_buff remains as NULL Pointer??? Testing this code by trying to do ssh with this machine. Any Help is really appreciated !! # static struct nf_hook_ops netfilter_ops; struct sk_buff *sock_buff; unsigned int main_hook(unsigned int hooknum,struct sk_buff **skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff*)) { sock_buff = *skb; if(!sock_buff){ printk(KERN_ERR Entered unexpected loop \n); return NF_ACCEPT; }/* Check for sk_buff NULL */ } int init_module() { netfilter_ops.hook = (nf_hookfn *) main_hook; netfilter_ops.hooknum = NF_INET_PRE_ROUTING; netfilter_ops.pf= PF_INET; netfilter_ops.priority = NF_IP_PRI_FIRST; nf_register_hook(netfilter_ops); } ## -Thnx, VKS Which kernel version are you using? The function prototype of a netfilter hook does vary from kernel version to kernel version, but in the kernels I’ve seen the skb parameter is a typed sk_buff *skb, not sk_buff **skb. In other words, you get passed a pointer to the sk_buff, not the address of a pointer to an sk_buff. Jeff Haran ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: sock_buff is NULL !
Thanks Jeff for the reply. Yes; after changing the double pointer to a Normal Pointer., I can see that ., if block was skipped. -Thnx, VKS On Tue, Nov 22, 2011 at 12:50 AM, Jeff Haran jha...@bytemobile.com wrote: ** ** ** ** *From:* kernelnewbies-boun...@kernelnewbies.org [mailto: kernelnewbies-boun...@kernelnewbies.org] *On Behalf Of *Kesava Srinivas *Sent:* Monday, November 21, 2011 11:03 AM *To:* kernelnewbies@kernelnewbies.org *Subject:* sock_buff is NULL ! ** ** HI Team, Trying to make this code work; but some how it is entering the if condition mentioned below.sock_buff is still a NULL Pointer.I can see that Function was registered with the Ipv4 Hooks. Any ideas/scenarios where the sock_buff remains as NULL Pointer??? Testing this code by trying to do ssh with this machine. Any Help is really appreciated !! # static struct nf_hook_ops netfilter_ops; struct sk_buff *sock_buff; unsigned int main_hook(unsigned int hooknum,struct sk_buff **skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff*)) { sock_buff = *skb; if(!sock_buff){ printk(KERN_ERR Entered unexpected loop \n); return NF_ACCEPT; }/* Check for sk_buff NULL */ } int init_module() { netfilter_ops.hook = (nf_hookfn *) main_hook; netfilter_ops.hooknum = NF_INET_PRE_ROUTING; netfilter_ops.pf= PF_INET; netfilter_ops.priority = NF_IP_PRI_FIRST; nf_register_hook(netfilter_ops); } ## -Thnx, VKS ** ** Which kernel version are you using? The function prototype of a netfilter hook does vary from kernel version to kernel version, but in the kernels I’ve seen the skb parameter is a typed sk_buff *skb, not sk_buff **skb. In other words, you get passed a pointer to the sk_buff, not the address of a pointer to an sk_buff. ** ** Jeff Haran ** ** -- -VKS Masters,Computer ScienceEngineering. ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
RE: sock_buff is NULL !
From: Kesava Srinivas [mailto:vunnavafut...@gmail.com] Sent: Monday, November 21, 2011 11:32 AM To: Jeff Haran Cc: kernelnewbies@kernelnewbies.org Subject: Re: sock_buff is NULL ! Thanks Jeff for the reply. Yes; after changing the double pointer to a Normal Pointer., I can see that ., if block was skipped. -Thnx, VKS On Tue, Nov 22, 2011 at 12:50 AM, Jeff Haran jha...@bytemobile.com wrote: From: kernelnewbies-boun...@kernelnewbies.org [mailto:kernelnewbies-boun...@kernelnewbies.org] On Behalf Of Kesava Srinivas Sent: Monday, November 21, 2011 11:03 AM To: kernelnewbies@kernelnewbies.org Subject: sock_buff is NULL ! HI Team, Trying to make this code work; but some how it is entering the if condition mentioned below.sock_buff is still a NULL Pointer.I can see that Function was registered with the Ipv4 Hooks. Any ideas/scenarios where the sock_buff remains as NULL Pointer??? Testing this code by trying to do ssh with this machine. Any Help is really appreciated !! # static struct nf_hook_ops netfilter_ops; struct sk_buff *sock_buff; unsigned int main_hook(unsigned int hooknum,struct sk_buff **skb,const struct net_device *in,const struct net_device *out,int (*okfn)(struct sk_buff*)) { sock_buff = *skb; if(!sock_buff){ printk(KERN_ERR Entered unexpected loop \n); return NF_ACCEPT; }/* Check for sk_buff NULL */ } int init_module() { netfilter_ops.hook = (nf_hookfn *) main_hook; netfilter_ops.hooknum = NF_INET_PRE_ROUTING; netfilter_ops.pf= PF_INET; netfilter_ops.priority = NF_IP_PRI_FIRST; nf_register_hook(netfilter_ops); } ## -Thnx, VKS Which kernel version are you using? The function prototype of a netfilter hook does vary from kernel version to kernel version, but in the kernels I’ve seen the skb parameter is a typed sk_buff *skb, not sk_buff **skb. In other words, you get passed a pointer to the sk_buff, not the address of a pointer to an sk_buff. Jeff Haran -- -VKS Masters,Computer ScienceEngineering. I am a bit surprised that you didn’t get a compiler warning when you built this. Type checking is your friend. 8^) Jeff Haran ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Freeing work_struct memory
I've got a bug I'm having trouble identifying. It seems like it could be related to my work_struct usage. I essentially have this: struct my_worker { work_struct work; /* some other data */ }; void worker_fn(struct work_struct *work) { struct my_worker *worker = container_of(work, struct my_worker, work); /* ... do some stuff ... */ kfree(worker); } void worker_caller() { struct my_worker *worker = kmalloc(sizeof(*worker), GFP_KERNEL); INIT_WORK(worker-work, worker_fn); /* ... add some other stuff to *worker ... */ schedule_work(worker-work); } I frequently get a kernel panic with a specific test, but the stack trace is rarely the same, which seems to indicate to me that I'm corrupting data somewhere. So my question is: Can I free the memory for struct my_worker *worker inside worker_fn? Or does the work_queue stuff need to continue to use the struct work_struct work member after the end of worker_fn? -Kai Meyer ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
x86: Executing a raw vmlinux image (embedded environment)
Hi All, Firstly, a little introduction an background - I am currently the maintainer for the x86 port of Das U-Boot (or more simply U-Boot). While the x86 port is not as well known as the more major ports like ARM and PPC, it is starting to gain more attention and more developer input which has beed nice to see after my solo efforts over the last few years. One of my biggest annoyances with the x86 U-Boot port is that, while it is an embedded boot loader, it still tries to boot Linux as if it was a conventional PC - i.e. it has 'real mode' and 'BIOS' implementation and loads a bzImage. But this approach is completely unnecessary and only adds to the boot time (load bzImage from storage into RAM, decompress, then run). So I want to shortcut bzImage and migrate towards treating the loading of the Linux kernel from U-Boot like any other embedded environment: - Decompress vmlinux directly from storage into the appropriate memory location - Setup required data structures - Jump into vmlinux U-Boot has it's own compressed kernel image container (uImage) and support code which will allow me to decompress the vmlinux directly from storage into RAM. In my current situation, I have ~1.7MB of onboard (i.e. cached) flash memory where I plan to store the compressed kernel and an MMC where I plan to store the file system. So after building a very stripped down kernel (no TCP/IP for example) I get: /vmlinux2,629,659 bytes /vmlinux.o 2,889,050 bytes /arch/i386/boot/bzImage 1,104,864 bytes /arch/x86/boot/bzImage 1,104,864 bytes /arch/x86/boot/vmlinux.bin 1,092,060 bytes /arch/x86/boot/compressed/vmlinux 1,099,538 bytes /arch/x86/boot/compressed/vmlinux.bin 2,094,132 bytes /arch/x86/boot/compressed/vmlinux.bin.gz1,074,711 bytes I understand that /arch/x86/boot/compressed/vmlinux.bin.gz is a compressed version of /arch/x86/boot/compressed/vmlinux.bin, and /arch/i386/boot/bzImage and /arch/x86/boot/bzImage are the same file and that it is the 16-bit boot code + /arch/x86/boot/compressed/vmlinux.bin.gz but I don't understand the rest... My guess is that /vmlinux.o is the ELF image generated by the compiler + linker stage and /vmlinux may be /vmlinux.o objdump'd into a raw binary and perhaps /arch/x86/boot/vmlinux.bin is a further stripped version of/vmlinux, but I'm at a loss with /arch/x86/boot/compressed/vmlinux In any event, it looks like either /arch/x86/boot/compressed/vmlinux.bin or /vmlinux is what I need to copy into RAM @ 0x10 (1MiB) which is where my non-relocatable kernel is compiled to. I also have looked at the documentation for the x86 32-boot protocol found in linux/Documentation/x86/boot.txt So what I'm needing is: - Confirmation of exactly which vmlinux to use - Confirmation that I do load it @ 0x10 - How to setup the memory map (keeping in mind I have 2GB of contiguous memory with no BIOS/ACPI etc to worry about clobbering - Any other tricks I need to be aware of.. Any help will be greatly appreciated Thanks, Graeme ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: x86: Executing a raw vmlinux image (embedded environment)
/vmlinux 2,629,659 bytes /vmlinux.o 2,889,050 bytes /arch/i386/boot/bzImage 1,104,864 bytes /arch/x86/boot/bzImage 1,104,864 bytes /arch/x86/boot/vmlinux.bin 1,092,060 bytes /arch/x86/boot/compressed/vmlinux 1,099,538 bytes /arch/x86/boot/compressed/vmlinux.bin 2,094,132 bytes /arch/x86/boot/compressed/vmlinux.bin.gz 1,074,711 bytes I understand that /arch/x86/boot/compressed/vmlinux.bin.gz is a compressed version of /arch/x86/boot/compressed/vmlinux.bin, and /arch/i386/boot/bzImage and /arch/x86/boot/bzImage are the same file and that it is the 16-bit boot code + /arch/x86/boot/compressed/vmlinux.bin.gz This is correct. but I don't understand the rest... My guess is that /vmlinux.o is the ELF image generated by the compiler + linker stage and /vmlinux may be /vmlinux.o objdump'd into a raw binary and perhaps /arch/x86/boot/vmlinux.bin is a further stripped version of/vmlinux, but I'm at a loss with /arch/x86/boot/compressed/vmlinux vmlinux is ELF image with ELF header. So actual point of kernel entry would be at an offset, somewhere after the ELF header. vmlinux.bin is what you would get after doing #objcopy -O binary vmlinux vmlinux.bin. vmlinux.bin has only obj code and nothing else. In any event, it looks like either /arch/x86/boot/compressed/vmlinux.bin or /vmlinux is what I need to copy into RAM @ 0x10 (1MiB) which is where my non-relocatable kernel is compiled to. copy vmlinux.bin. - How to setup the memory map (keeping in mind I have 2GB of contiguous memory with no BIOS/ACPI etc to worry about clobbering - Any other tricks I need to be aware of.. Check if x86 kernel expects some parameters(like machineid, bootargs location etc) in some registers. Check if x86 has low level debug support(like DEBUG_LL). Also you might want to check how initial page tables are being setup in kernel. -syed ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Path for STOLEN Packets!!!
Hi , Even after lot of google; didn't get the accurate answer for this. After STEALING Packets (NF_STOLEN); want to send the Manipulated Packet (added extra header) to some of the available net devices. Please let me know what is the Function that I Should call to do this step ?? Also; once the skb was expanded by 20 bytes to add new ip header; do I need to reassign the skb pointer to the new location ?? -Thanks in Advance, VKS ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies