Re: Best and fastest way to understand kernel subsystem ?
On 12/06/2012 03:24 PM, Shraddha Kamat wrote: What is the best (and the fastest ) way to understand a kernel subsystem ( for e.g., filesystem , Networking .. etc.) Reading the kernel code is the best way. For reference you can use LDD3 and books from OReilly. -- Shraddha ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies -- - Abhijit ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: ext2_find_near()
On 11/14/2012 09:14 AM, Anders Lind wrote: Hi all, Sorry to bother. for ext2_find_near(), why we tro to find near block by tring priveous block? Why not forward? static ext2_fsblk_t ext2_find_near(struct inode *inode, Indirect *ind) { struct ext2_inode_info *ei = EXT2_I(inode); __le32 *start = ind-bh ? (__le32 *) ind-bh-b_data : ei-i_data; __le32 *p; ext2_fsblk_t bg_start; ext2_fsblk_t colour; /* Try to find previous block */ for (p = ind-p - 1; p = start; p--) if (*p) return le32_to_cpu(*p); /* No such thing, so let's try location of indirect block */ if (ind-bh) return ind-bh-b_blocknr; Thank you! To reduce the file fragmentation problem, EXT2 tries to get the block near the block which is already allocated. So we backtrack to see if we have any block free which is already there in our list instead of allocating a new block in some other group. ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies -- - Abhijit ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: set_super_anon in fs/super.c
On 10/24/2012 01:50 PM, Rohan Puri wrote: Look inline for comments. On Tue, Oct 23, 2012 at 7:30 PM, Abhijit Chandrakant Pawar abhi.c.pa...@gmail.com mailto:abhi.c.pa...@gmail.com wrote: Hi Rohan, On Tue, 2012-10-23 at 18:47 +0530, Rohan Puri wrote: On Tue, Oct 23, 2012 at 6:33 PM, Abhijit Chandrakant Pawar abhi.c.pa...@gmail.com mailto:abhi.c.pa...@gmail.com wrote: I am working on the layered file systems. I came across a function called set_super_anon. This is a callback to the sget function to compare the superblock . This function accepts two parameters. first is superblock * and second is void *. If you look at the definition of this function, the void* is never used. Many filesystem uses this function when they are mounting the superblock. Some pass NULL and some pass actual data.I have looked till 2.6.31 but there isnt any trace of the usage of second parameter. If it is never used then why its added to the function param list? Is there any historical reason during the older kernel days? Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org mailto:Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies Hi Abhijit, See the issue is this function is passed as an argument to sget(), now their are many other file-systems that defined their own set_super function for that they need data argument where they usually pass mount-related data For eg. see the definition and usage of function nfs_set_super(). So, the prototype of the sget() should contain function ptr (set_super()) and this function ptr should have data argument also. Now one usage can imply NO USE of the data parameter, which is set_super_anon, but other file-systems may require, so the sget() prototype should be generic to support, both the cases. Yes... thats what I thought. many are passing data un-necessarily to this function wherein they already have captured the required information for their purpose in their own defined function. Do you mean to say, each fs's own set_super function makes a call to set_anon_super() with data parameter as their specific data, but set_anon_super makes no use of it? Wouldnt that cause stack to store the value un-necessarily? It would be good if everybody passes NULL as second param. Yes, each fs's set_super, if makes a call to anon_super() should pass NULL as the second parameter(void *data) since anon_super doesnt make use of this parameter, need for this parameter just arises to match the prototype of sget()'s function ptr agrument. Also do remember the pointer to this data is passed, so only a word-size of extra stack is utilized when a call to this function is made. I have made a patch for those filesystems and submitted to the kernel list. - Rohan - Rohan ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: quick online tutorial on system calls
On 17 Oct 2012 20:31, Robert P. J. Day rpj...@crashcourse.ca wrote: another in an ongoing series of things i'm just throwing together, mostly to document stuff for my own benefit to use later in courseware when i figure out what to do with it. here's a summary i wrote this morning on system calls, which turned out to be longer than i'd planned (it just kind of got away from me): http://www.crashcourse.ca/wiki/index.php/System_calls but a lot of it is just cutting and pasting kernel source for explanatory purposes. feedback welcome. Nice article. May be you would like to add below points as well. 1. Some pointers on context switch when system call is invoked. 2. Data transfer between user and kernel mode in brief. 3. Mention of user mode helper calls in kernel. I am not sure what scope you have planned though but I think these points will help. Abhijit rday -- Robert P. J. Day Ottawa, Ontario, CANADA http://crashcourse.ca Twitter: http://twitter.com/rpjday LinkedIn: http://ca.linkedin.com/in/rpjday ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
BUILD_BUG_ON __bad_udelay for linux 3.3.2 kernel compile on ARM
Hi All, I have compiled the latest linux kernel (3.3.2) (after hearing the provided support of this series after the 2.6 series )for ARM platform on fedora box. I faced couple of problems: 1. BUILD_BUG_ON : There were errors and make stopped for couple of files. The error said , negative type value for array. At this moment, I have just commented the calls. However just wondering what could be potential problem? 2. __bad_udelay After making the above changes, the compilation finished just fine, however doing modpost presented new problems as mentioned below: OBJCOPY arch/arm/boot/zImage Kernel: arch/arm/boot/zImage is ready Building modules, stage 2. MODPOST 2136 modules ERROR: __bad_udelay [sound/pci/ali5451/snd-ali5451.ko] undefined! ERROR: __bad_udelay [drivers/scsi/atp870u.ko] undefined! ERROR: __bad_udelay [drivers/net/ethernet/sun/sungem.ko] undefined! ERROR: __bad_udelay [drivers/gpu/drm/radeon/radeon.ko] undefined! ERROR: __bad_udelay [drivers/gpu/drm/nouveau/nouveau.ko] undefined! ERROR: __bad_udelay [drivers/atm/he.ko] undefined! make[1]: *** [__modpost] Error 1 make: *** [modules] Error 2 I have to go and replace many of the calls for udelay having value greater than 2000 with mdelay(2) or more. So is it that these drivers are not meant for ARM or they are not yet completely supported for ARM? Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Dual booting of Smartphone
Hi All, I know its pre-mature to ask this question but is there any support of dual booting in smartphones which can allow me have two different OS's ( for ex. Android 2.1 + Android 2.3 ) on a single phone? There may be other combinations as well. Is this something which we are looking at near future or is it just a dream at this moment? Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Get USB Device Class Type and Mount point
On 02/10/2012 07:42 PM, Greg KH wrote: On Fri, Feb 10, 2012 at 07:19:26PM +0530, Abhijit Pawar wrote: Step back again, what is the problem you are trying to solve? greg k-h I am trying to find out if any storage disk is connected to USB port and get its mount so that I an encrypt that mount with encrypted filesystem. Great, then do that from userspace, like it is done today. Or do you have a problem with how things are done today with encrypted filesystems? If so, why? greg k-h ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies Hi Greg, The reason I went for kernel module is to get the device add notification. However once I get the notification, I can have netlink socket pass the device data to my user space application. Here the tricky part is I can get the device info, but not able to figure out how can I get the mount path from this device. I tried looking at linux automount feature but its doc is limited and its on demand feature may not allow me to know for sure if the drive is mounted properly. So is there any way I can get the mount path from the USB device structure in userspace? for encrypted filesystem there isnt any problem as I would be overlaying that on the USB device default filesystem. Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Get USB Device Class Type and Mount point
On 02/13/2012 05:51 PM, Mandeep Sandhu wrote: greg k-h I am trying to find out if any storage disk is connected to USB port and get its mount so that I an encrypt that mount with encrypted filesystem. Great, then do that from userspace, like it is done today. Or do you have a problem with how things are done today with encrypted filesystems? If so, why? greg k-h ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies Hi Greg, The reason I went for kernel module is to get the device add notification. However once I get the notification, I can have netlink Well, thats not a good enough reason to go to kernel space! :) Have you looked at Udev? It nicely handles device attach/detach events (hotplug events) from userspace. You should probably look at using it for your purpose. http://en.wikipedia.org/wiki/Udev HTH, -mandeep Yes. I should have looked into libudev and libsysfs which I am doing now. :) Regarding going to kernel , I thought that would be help me in controlling the device in a better way (where I can enable or disable the data transfer interfaces preventing the data copy (if at all thats possible). Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Get USB Device Class Type and Mount point
On 02/09/2012 08:17 PM, Greg KH wrote: On Thu, Feb 09, 2012 at 07:18:53PM +0530, Abhijit Pawar wrote: Hi Greg, On 02/09/2012 05:53 PM, Greg KH wrote: On Thu, Feb 09, 2012 at 11:40:16AM +0530, Abhijit Pawar wrote: Hi , Is there any way we can get the class type of the attached USB device through struct usb_device in a kernel module? I tried getting the device descriptor and interface descriptor and then use them to get the Device and Interface Class and Subclass. struct usb_device_descriptor *descriptor =usbDev-descriptor; struct usb_interface_descriptor *idesc = to_usb_interface(usbDev); Whenever I run my kernel module, I get 0 for DeviceClass and Interface Class. I checked the meaning and it says its the information and to be gathered through interface. That is correct, look at the interface pointer given to your driver. Am I missing something here? What I want is to get the mount point / device path of the USB devices. Like for Storage Device I would like to get its mount path and for HID I would like to get its device path. Both of those things make no sense within the kernel, and you will not be able to detect them from your driver, especially as it is not your driver bound to this type of device, the in-kernel drivers are. Also, these have nothing to do with the class type of a device's interface. Yes. As I am dealing with USB Core, I am not in a position to get the interface directly. However I checked the usb_dump_interface_descriptor( ) from usb/core/devices.c and it gives the interface class ( 8 for Storage) correctly. Isnt it forwared to my module which is relying on the linux usb notifier chain? This chain gives me the device pointer and I am trying to enumerate its interface to know its class. Ah, I thought you were a real driver. Yes, just enumerate the interfaces of the device. Have a pointer to your code anywhere? What are you trying to solve here that you feel you need this information that is easily found from userspace? I am trying to use USB notifier chains to get the device details and then find out its mount path ( in case of Storage). Are you saying that I should be looking into sysFS and udev rules for getting this mount path? I'm saying you shouldn't be doing any of this from within the kernel at all, as again, it can be trivially found from userspace today with no kernel changes needed. Step back again, what is the problem you are trying to solve? greg k-h I am trying to find out if any storage disk is connected to USB port and get its mount so that I an encrypt that mount with encrypted filesystem. Regards, Abhijit Pawar ___ 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
Re: Filtering USB storage data in kernel module
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. 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? Now the way USB is made known to OS is through SCSI and then respective filesystem ( mostly usbfs). Not really, usbfs is only one way, and it has nothing to do with usb disks. So is there any way I can intercept this stack and have my kernel module invoked so that I will get the data. Not easily. Even if its hard, can you please give details of how do I achieve this? I have been thinking on two approaches: 1. Use VFS and write a proxy filesystem for USB device which will filter the data. 2. checking SCSI and any intercepting point. Again, what are you trying to filter? That will determine where you make changes. thanks, greg k-h So what choice do I have now for this? ___ 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 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. Now the way USB is made known to OS is through SCSI and then respective filesystem ( mostly usbfs). Not really, usbfs is only one way, and it has nothing to do with usb disks. So is there any way I can intercept this stack and have my kernel module invoked so that I will get the data. Not easily. Even if its hard, can you please give details of how do I achieve this? I have been thinking on two approaches: 1. Use VFS and write a proxy filesystem for USB device which will filter the data. 2. checking SCSI and any intercepting point. Again, what are you trying to filter? That will determine where you make changes. thanks, greg k-h So what choice do I have now for this? Lots of work, best of luck with this task, it will not be simple or easy. greg k-h Thanks. Its not that simple. I need to check the sCSI family code as well as USB core. Also VFS may be involved. :( :) Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Registering for only Specific Packets from Net-Filter!!!!
On 11/17/2011 12:03 PM, Mulyadi Santosa wrote: On Wed, Nov 16, 2011 at 17:50, Kesava Srinivasvunnavafut...@gmail.com wrote: HI Guys, I'm a Newbie to Linux Kernel Development. Need some Clarification in understanding Net-Filter Hooks. Can I register only for the Necessary Packets [Ex: IPSEC etc...] from the Net-Filters?? AFAIK ; Net-Filter Module send the Packets to the Corresponding Module based on pre-defined HOOKS. Let us say; there are Many Packets reaching that Hooks; and if I am Interested only in some Packets from Net-Filter module; can I do that ??? something like: iptables [some rules] -j ULOG ? Check man iptables and see if that suits your need. FYI ULOG target uses netlink to deliver the packet to user space for further processing. Hi Kesava Srinivas, If this is for any application in user space, I would recommend you take a look at libPcap. Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Filtering USB storage data in kernel module
Hi All, I need to filter the data written/read to and from the USB storage disk. Now the way USB is made known to OS is through SCSI and then respective filesystem ( mostly usbfs). So is there any way I can intercept this stack and have my kernel module invoked so that I will get the data. I have been thinking on two approaches: 1. Use VFS and write a proxy filesystem for USB device which will filter the data. 2. checking SCSI and any intercepting point. I am currently looking at USBMONITOR source code as well. Please let me know if there is any other way to achieve this. Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
sample USB Driver / Probe not getting called
Hi All, Is there any way to call a sample USB driver whenever a USB device is attached to the system irrespective of the class and type of the device? To do this, LDD3, chap 13 mention that for USB device table, we only need to add the driver_info entry as 42. However if I do this, my probe is never getting called. Now, I give the vendor and product id of this Mouse to the device_id table and load my driver again. Still the probe is not getting called. Is it that USB core is getting the proper driver for this mouse before my driver entry in the list? Am I missing something? Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: sample USB Driver / Probe not getting called
On 10/17/2011 04:08 PM, selvamuthukumar v wrote: On Mon, Oct 17, 2011 at 3:05 PM, Abhijit Pawarapawar.li...@gmail.com wrote: Hi All, Is there any way to call a sample USB driver whenever a USB device is attached to the system irrespective of the class and type of the device? To do this, LDD3, chap 13 mention that for USB device table, we only need to add the driver_info entry as 42. However if I do this, my probe is never getting called. Now, I give the vendor and product id of this Mouse to the device_id table and load my driver again. Still the probe is not getting called. Is it that USB core is getting the proper driver for this mouse before my driver entry in the list? Am I missing something? probe function will get called only if no other driver is attached to the device. Make sure the device does not have any other driver. Please refer line 290 and 291. drivers/base/dd.c: 270 static int __driver_attach(struct device *dev, void *data) 271 { 272 struct device_driver *drv = data; 273 274 /* 275 * Lock device and try to bind to it. We drop the error 276 * here and always return 0, because we need to keep trying 277 * to bind to devices and some drivers will return an error 278 * simply if it didn't support the device. 279 * 280 * driver_probe_device() will spit a warning if there 281 * is an error. 282 */ 283 284 if (!driver_match_device(drv, dev)) 285 return 0; 286 287 if (dev-parent)/* Needed for USB */ 288 device_lock(dev-parent); 289 device_lock(dev); 290 if (!dev-driver) 291 driver_probe_device(drv, dev); Thanks for reference to this function. It seems that there isnt any way to override the already attached driver to the device. Is there any? Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Hooking exec system call
On 09/23/2011 03:11 PM, rohan puri wrote: On Fri, Sep 23, 2011 at 2:43 PM, Abhijit Pawar apawar.li...@gmail.com mailto:apawar.li...@gmail.com wrote: On 09/23/2011 02:04 PM, rohan puri wrote: On Fri, Sep 23, 2011 at 2:00 PM, Abhijit Pawar apawar.li...@gmail.com mailto:apawar.li...@gmail.com wrote: On 09/23/2011 01:01 PM, Rajat Sharma wrote: Untidy way : - Yes, you can do that by registering a new binary format handler. Whenever exec is called, a list of registered binary format handlers is scanned, in the same way you can hook the load_binary load_library function pointers of the already registered binary format handlers. Challenge with this untidy way is to identify the correct format, for example if you are interested in only hooking ELF format, there is no special signature withing the registered format handler to identify that, however if one format handler recognizes the file header, its load_binary will return 0. This can give you the hint that you are sitting on top of correct file format. Long time back I had written the similar module in Linux to do the same, but can't share the code :) -Rajat On Thu, Sep 22, 2011 at 3:14 PM, rohan purirohan.pur...@gmail.com mailto:rohan.pur...@gmail.com wrote: On Thu, Sep 22, 2011 at 1:53 PM, Abhijit Pawarapawar.li...@gmail.com mailto:apawar.li...@gmail.com wrote: hi list, Is there any way to hook the exec system call on Linux box apart from replacing the call in System Call table? Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org mailto:Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies Tidy way : - You can do that from LSM (Linux security module). Untidy way : - Yes, you can do that by registering a new binary format handler. Whenever exec is called, a list of registered binary format handlers is scanned, in the same way you can hook the load_binary load_library function pointers of the already registered binary format handlers. Regards, Rohan Puri ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org mailto:Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies So If I use the binary format handler, then I can hook the exec call. however I need to register this. Does that mean that I need to return the negative value so as to have actual ELF handler to be loaded? Regards, Abhijit Pawar Read this, http://www.linux.it/~rubini/docs/binfmt/binfmt.html http://www.linux.it/%7Erubini/docs/binfmt/binfmt.html this might help Regards, Rohan Puri Thanks Rohan. I tried creating a hooking module on the similar line. I am able to load the module but whenever I am launching any application , its load_binary is not being called. here is the source for the module attached. Regards, Abhijit Pawar Hi Abhijit, I have made the change, try to compile and execute this code, it works. Also, I am just curious enough to know that where do you need to do this hooking. Regards, Rohan Puri Hi Rohan, I have been looking at Windows worlds ability to support DLL Injection and API hooking. I was just wondering if this could be something to be done in Linux as well. I am not sure if there is any special use of this module apart from learning the binary handler. May be it could be used as a security module for your own binary handler. Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: Hooking exec system call
On 09/26/2011 12:26 PM, rohan puri wrote: On Mon, Sep 26, 2011 at 12:02 PM, Abhijit Pawar apawar.li...@gmail.com mailto:apawar.li...@gmail.com wrote: On 09/23/2011 03:11 PM, rohan puri wrote: On Fri, Sep 23, 2011 at 2:43 PM, Abhijit Pawar apawar.li...@gmail.com mailto:apawar.li...@gmail.com wrote: On 09/23/2011 02:04 PM, rohan puri wrote: On Fri, Sep 23, 2011 at 2:00 PM, Abhijit Pawar apawar.li...@gmail.com mailto:apawar.li...@gmail.com wrote: On 09/23/2011 01:01 PM, Rajat Sharma wrote: Untidy way : - Yes, you can do that by registering a new binary format handler. Whenever exec is called, a list of registered binary format handlers is scanned, in the same way you can hook the load_binary load_library function pointers of the already registered binary format handlers. Challenge with this untidy way is to identify the correct format, for example if you are interested in only hooking ELF format, there is no special signature withing the registered format handler to identify that, however if one format handler recognizes the file header, its load_binary will return 0. This can give you the hint that you are sitting on top of correct file format. Long time back I had written the similar module in Linux to do the same, but can't share the code :) -Rajat On Thu, Sep 22, 2011 at 3:14 PM, rohan purirohan.pur...@gmail.com mailto:rohan.pur...@gmail.com wrote: On Thu, Sep 22, 2011 at 1:53 PM, Abhijit Pawarapawar.li...@gmail.com mailto:apawar.li...@gmail.com wrote: hi list, Is there any way to hook the exec system call on Linux box apart from replacing the call in System Call table? Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org mailto:Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies Tidy way : - You can do that from LSM (Linux security module). Untidy way : - Yes, you can do that by registering a new binary format handler. Whenever exec is called, a list of registered binary format handlers is scanned, in the same way you can hook the load_binary load_library function pointers of the already registered binary format handlers. Regards, Rohan Puri ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org mailto:Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies So If I use the binary format handler, then I can hook the exec call. however I need to register this. Does that mean that I need to return the negative value so as to have actual ELF handler to be loaded? Regards, Abhijit Pawar Read this, http://www.linux.it/~rubini/docs/binfmt/binfmt.html http://www.linux.it/%7Erubini/docs/binfmt/binfmt.html this might help Regards, Rohan Puri Thanks Rohan. I tried creating a hooking module on the similar line. I am able to load the module but whenever I am launching any application , its load_binary is not being called. here is the source for the module attached. Regards, Abhijit Pawar Hi Abhijit, I have made the change, try to compile and execute this code, it works. Also, I am just curious enough to know that where do you need to do this hooking. Regards, Rohan Puri Hi Rohan, I have been looking at Windows worlds ability to support DLL Injection and API hooking. I was just wondering if this could be something to be done in Linux as well. I am not sure if there is any special use of this module apart from learning the binary handler. May be it could be used as a security
Re: Hooking exec system call
On 09/23/2011 01:01 PM, Rajat Sharma wrote: Untidy way : - Yes, you can do that by registering a new binary format handler. Whenever exec is called, a list of registered binary format handlers is scanned, in the same way you can hook the load_binary load_library function pointers of the already registered binary format handlers. Challenge with this untidy way is to identify the correct format, for example if you are interested in only hooking ELF format, there is no special signature withing the registered format handler to identify that, however if one format handler recognizes the file header, its load_binary will return 0. This can give you the hint that you are sitting on top of correct file format. Long time back I had written the similar module in Linux to do the same, but can't share the code :) -Rajat On Thu, Sep 22, 2011 at 3:14 PM, rohan purirohan.pur...@gmail.com wrote: On Thu, Sep 22, 2011 at 1:53 PM, Abhijit Pawarapawar.li...@gmail.com wrote: hi list, Is there any way to hook the exec system call on Linux box apart from replacing the call in System Call table? Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies Tidy way : - You can do that from LSM (Linux security module). Untidy way : - Yes, you can do that by registering a new binary format handler. Whenever exec is called, a list of registered binary format handlers is scanned, in the same way you can hook the load_binary load_library function pointers of the already registered binary format handlers. Regards, Rohan Puri ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies So If I use the binary format handler, then I can hook the exec call. however I need to register this. Does that mean that I need to return the negative value so as to have actual ELF handler to be loaded? Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hooking exec system call
hi list, Is there any way to hook the exec system call on Linux box apart from replacing the call in System Call table? Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
2.6.39 Kernel Changes for FileSystem, get_sb removed
Hi list, It seems that the support for get_sb function is removed from kernel 2.6.39 onwards. My code which is working till 2.6.38 series is failing with new kernels. I tried finding out but there isnt anything mentioned. So if this function itself is removed then how kernel is going to find out the superblock and use it? Are we supposed to use the mount function provided? This is what i got from one of the kernel patch email. +[mandatory] + -get_sb() is gone. Switch to use of -mount(). Typically it's just +a matter of switching from calling get_sb_... to mount_... and changing the +function type. If you were doing it manually, just switch from setting -mnt_root +to some pointer to returning that pointer. On errors return ERR_PTR(...). diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt It looks like there are other changes related to Pages are also done. Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: 2.6.39 Kernel Changes for FileSystem, get_sb removed
On 09/20/2011 05:14 PM, Abhijit Pawar wrote: Hi list, It seems that the support for get_sb function is removed from kernel 2.6.39 onwards. My code which is working till 2.6.38 series is failing with new kernels. I tried finding out but there isnt anything mentioned. So if this function itself is removed then how kernel is going to find out the superblock and use it? Are we supposed to use the mount function provided? This is what i got from one of the kernel patch email. +[mandatory] + -get_sb() is gone. Switch to use of -mount(). Typically it's just +a matter of switching from calling get_sb_... to mount_... and changing the +function type. If you were doing it manually, just switch from setting -mnt_root +to some pointer to returning that pointer. On errors return ERR_PTR(...). diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt It looks like there are other changes related to Pages are also done. Regards, Abhijit Pawar I have modified the code to use the mount function and its working correctly. There is one more change I noticed for struct address_space_operations: The sync_page is removed. The code is working now. Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: 2.6.39 Kernel Changes for FileSystem, get_sb removed
On 09/20/2011 05:50 PM, rohan puri wrote: On Tue, Sep 20, 2011 at 5:14 PM, Abhijit Pawar apawar.li...@gmail.com mailto:apawar.li...@gmail.com wrote: Hi list, It seems that the support for get_sb function is removed from kernel 2.6.39 onwards. My code which is working till 2.6.38 series is failing with new kernels. I tried finding out but there isnt anything mentioned. So if this function itself is removed then how kernel is going to find out the superblock and use it? Are we supposed to use the mount function provided? This is what i got from one of the kernel patch email. +[mandatory] + -get_sb() is gone. Switch to use of -mount(). Typically it's just +a matter of switching from calling get_sb_... to mount_... and changing the +function type. If you were doing it manually, just switch from setting -mnt_root +to some pointer to returning that pointer. On errors return ERR_PTR(...). diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt It looks like there are other changes related to Pages are also done. Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org mailto:Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies Hi Abhijit, Yes you have to make use of mount function pointer in the struct file_system_type. NOTE : - change is only in one parameter of type struct vfsmount which is basically removed from this function pointer. Regards, Rohan Puri Thanks Rohan. Yes, i have made the changes and things are looking good. struct address_space_operation's sync_page is also removed. Regards, Abhijit Pawar ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: no files can be opened in a C program
On 07/25/2011 05:29 PM, Naveen Kumar wrote: You can use command ulimit -a, there you can check the limit for a process. Thanks, Naveen Ulimit gives 1024 as open file limit. In struct task_struct it has a member called struct files_struct *files; I tried checking for this member and the limit however I am not able to decide correctly why the limit is 1024. Also, is there any distinction between 32 bit and 64 bit systems for this limit? On Mon, Jul 25, 2011 at 5:18 PM, Anuz Pratap Singh Tomar chambilketha...@gmail.com mailto:chambilketha...@gmail.com wrote: On Mon, Jul 25, 2011 at 12:31 PM, Venkateswarlu P p.venkatesh...@gmail.com mailto:p.venkatesh...@gmail.com wrote: What is the Max no of files that can be opened simultaneously within a Single C program. i want this information for kenel compilation See man 3 setrlimit Total number of files that can be opened should depend on file system. And what this has to do with kernel compilation? ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org mailto:Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org mailto:Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies Regards, Abhijit ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Re: interview question how does application connects to device
On 5 July 2011 21:33, Greg Freemyer greg.freem...@gmail.com wrote: On Tue, Jul 5, 2011 at 9:43 AM, Mandeep Sandhu mandeepsandhu@gmail.com wrote: Let me simplify the question. I'll attempt to answer your questions...for my own edification! :) 1) What are the FIVE classic system calls for interfacing with a character device. (ie. If it did not exist in 1970, don't list it). open/close/read/write/seek?...and the infamous ioctl. You listed 6. Historically character devices don't seek. So drop that one to get to 5. (And yes, you can find char devices that implement seek, but ioctl is far more common. And when I learned UNIX 30 years ago, it was just the basic 5 I'm pretty sure that actually have matching driver code..) That is, drivers don't implement seek. seek() just sets a offset variable tracked in the kernel. The driver is not even woken up when the happens. That is if userspace did: open() seek(1) seek(2) seek(3) write() The driver would get invoked for open, and again for write. When write is invoked, the offset field would have a 3 in it. The driver has no way to even know seek(1) and seek(2) calls were made. So if you read a kernel book, you'll find seek() gets very little attention. It's really just a glorified way to say offset=value; 2) Which of the 5 is still heavily used in the kernel but is discouraged for new drivers being accepted into the linux kernel? I'm guessing this is ioctl's...because now the preferred way to communicate/give commands to a device is via sysfs? Correct, ioctl is no longer preferred, but it is definitely still used. And the ext4 team is still adding new ioctl commands despite it being discouraged. (I don't know why they are able to do that, but I know they do.) 3) Name at least 3 alternatives that have been routinely used for out-of-band communication in the Linux kernel since 2000. ioctl's, profs/sysfs, netlink sockets maybe? Yes, except procfs and sysfs are 2 different solutions, so you named 4. As of 2011, both ioctl's and procfs are discouraged for new device driver use. ioctl's will likely be around forever just because there are so many legacy ioctl implementations that need to be supported. Think of stty. That is a hugely complex ioctl based tool that I seriously doubt ever gets rewritten with a new kernel interface. procfs on they other hand will hopefully lose all the non-process specific users, but keep the process specific ones. That is, the current preference is /proc should only have info related to running processes, not all the other miscellaneous stuff. I don’t think there is yet an effort to remove those other files, but hopefully there will be gone at some point. One thing to keep in mind is that anything that interfaces with userspace is part of the kernel ABI and becomes very hard to change / get rid of. That actually means that any patches / driver submissions that impact on the kernel / userspace interface get a extra hard look. It also means a perspective employer will want to make sure you really understand the userspace / kernel interface. It is just too hard to throw out a implementation once accepted by LKML. Even in a embedded world where the driver is not sent upstream you want the kernel ABI to be as stable as possible. Otherwise you have to always be ensuring your kernel and userspace apps are compatible versions. Thanks, -mandeep Hope that helps at least someone in a future interview This is good. One more addition from my side which is not necessarily the answer to Greg's question: Bottom Halves are discouraged now days in driver. Greg ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies ___ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies