Re: read contents from user memory area from a module
Thank you, Sangman. Reimplement access_process_vm() or get_user_pages seems to be impractical... What I am thinking is to use system call like ptrace, but can a module call ptrace?? That also sounds strange... Fangkai On Wed, Apr 28, 2010 at 7:47 PM, Sangman Kim wrote: > Hi Fangkai, > > Ah, that function is not exported, which means you should look for some > other function or you can implement something similar by yourself (or you > can illegally use it with a direct address to access_process_vm().) > > I don't know about any exported function for similar purpose, but probably > others would know. > > On Wed, Apr 28, 2010 at 7:38 PM, Yang Fangkai > wrote: >> >> Hi, Sangman, >> >> Thanks for your reply! I have tried this access_process_vm(). >> It reports error when I include <../mm/memory.c>, saying redefinition >> of __init_module and __init_module... >> >> Fangkai >> >> On Wed, Apr 28, 2010 at 7:35 PM, Sangman Kim >> wrote: >> > Hi, >> > >> > You might want to look at access_process_vm() in mm/memory.c. >> > If you know the pid of the target process, you can use it to search the >> > corresponding task_struct using find_task_by_pid_ns() with init_pid_ns. >> > >> > Good luck :) >> > >> > Sangman >> > >> > On Wed, Apr 28, 2010 at 7:21 PM, Yang Fangkai >> > wrote: >> >> >> >> Dear List, >> >> >> >> I am developing a virtual device driver such that the user can >> >> write to the driver a process' pid and a virtual address, and the >> >> module will use these two values to get the memory contents of the >> >> target process. I am wondering if there is any easy functions that can >> >> fetch user page's data at this virtual address. Thank you! >> >> >> >> I have tried get_user but this is not possible because the >> >> modules executing get_user at another process's context. I also tried >> >> to use ptrace_readdata, however, it seems that the file at >> >> /kernel/ptrace.c leaves a function access_process_vm undefined and >> >> also I don't know how to compile the source code of my module with >> >> this file (the linker seaches file in /linux/include by default). I am >> >> wondering if there are any other solutions... >> >> >> >> Best, >> >> >> >> Fangkai >> >> >> >> -- >> >> To unsubscribe from this list: send an email with >> >> "unsubscribe kernelnewbies" to ecar...@nl.linux.org >> >> Please read the FAQ at http://kernelnewbies.org/FAQ >> >> >> > >> > > > -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: read contents from user memory area from a module
Hi Fangkai, Ah, that function is not exported, which means you should look for some other function or you can implement something similar by yourself (or you can illegally use it with a direct address to access_process_vm().) I don't know about any exported function for similar purpose, but probably others would know. On Wed, Apr 28, 2010 at 7:38 PM, Yang Fangkai wrote: > Hi, Sangman, > > Thanks for your reply! I have tried this access_process_vm(). > It reports error when I include <../mm/memory.c>, saying redefinition > of __init_module and __init_module... > > Fangkai > > On Wed, Apr 28, 2010 at 7:35 PM, Sangman Kim > wrote: > > Hi, > > > > You might want to look at access_process_vm() in mm/memory.c. > > If you know the pid of the target process, you can use it to search the > > corresponding task_struct using find_task_by_pid_ns() with init_pid_ns. > > > > Good luck :) > > > > Sangman > > > > On Wed, Apr 28, 2010 at 7:21 PM, Yang Fangkai > > wrote: > >> > >> Dear List, > >> > >>I am developing a virtual device driver such that the user can > >> write to the driver a process' pid and a virtual address, and the > >> module will use these two values to get the memory contents of the > >> target process. I am wondering if there is any easy functions that can > >> fetch user page's data at this virtual address. Thank you! > >> > >>I have tried get_user but this is not possible because the > >> modules executing get_user at another process's context. I also tried > >> to use ptrace_readdata, however, it seems that the file at > >> /kernel/ptrace.c leaves a function access_process_vm undefined and > >> also I don't know how to compile the source code of my module with > >> this file (the linker seaches file in /linux/include by default). I am > >> wondering if there are any other solutions... > >> > >> Best, > >> > >> Fangkai > >> > >> -- > >> To unsubscribe from this list: send an email with > >> "unsubscribe kernelnewbies" to ecar...@nl.linux.org > >> Please read the FAQ at http://kernelnewbies.org/FAQ > >> > > > > >
Re: read contents from user memory area from a module
Hi, Sangman, Thanks for your reply! I have tried this access_process_vm(). It reports error when I include <../mm/memory.c>, saying redefinition of __init_module and __init_module... Fangkai On Wed, Apr 28, 2010 at 7:35 PM, Sangman Kim wrote: > Hi, > > You might want to look at access_process_vm() in mm/memory.c. > If you know the pid of the target process, you can use it to search the > corresponding task_struct using find_task_by_pid_ns() with init_pid_ns. > > Good luck :) > > Sangman > > On Wed, Apr 28, 2010 at 7:21 PM, Yang Fangkai > wrote: >> >> Dear List, >> >> I am developing a virtual device driver such that the user can >> write to the driver a process' pid and a virtual address, and the >> module will use these two values to get the memory contents of the >> target process. I am wondering if there is any easy functions that can >> fetch user page's data at this virtual address. Thank you! >> >> I have tried get_user but this is not possible because the >> modules executing get_user at another process's context. I also tried >> to use ptrace_readdata, however, it seems that the file at >> /kernel/ptrace.c leaves a function access_process_vm undefined and >> also I don't know how to compile the source code of my module with >> this file (the linker seaches file in /linux/include by default). I am >> wondering if there are any other solutions... >> >> Best, >> >> Fangkai >> >> -- >> To unsubscribe from this list: send an email with >> "unsubscribe kernelnewbies" to ecar...@nl.linux.org >> Please read the FAQ at http://kernelnewbies.org/FAQ >> > > -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: read contents from user memory area from a module
Hi, You might want to look at access_process_vm() in mm/memory.c. If you know the pid of the target process, you can use it to search the corresponding task_struct using find_task_by_pid_ns() with init_pid_ns. Good luck :) Sangman On Wed, Apr 28, 2010 at 7:21 PM, Yang Fangkai wrote: > Dear List, > >I am developing a virtual device driver such that the user can > write to the driver a process' pid and a virtual address, and the > module will use these two values to get the memory contents of the > target process. I am wondering if there is any easy functions that can > fetch user page's data at this virtual address. Thank you! > >I have tried get_user but this is not possible because the > modules executing get_user at another process's context. I also tried > to use ptrace_readdata, however, it seems that the file at > /kernel/ptrace.c leaves a function access_process_vm undefined and > also I don't know how to compile the source code of my module with > this file (the linker seaches file in /linux/include by default). I am > wondering if there are any other solutions... > > Best, > > Fangkai > > -- > To unsubscribe from this list: send an email with > "unsubscribe kernelnewbies" to ecar...@nl.linux.org > Please read the FAQ at http://kernelnewbies.org/FAQ > >
read contents from user memory area from a module
Dear List, I am developing a virtual device driver such that the user can write to the driver a process' pid and a virtual address, and the module will use these two values to get the memory contents of the target process. I am wondering if there is any easy functions that can fetch user page's data at this virtual address. Thank you! I have tried get_user but this is not possible because the modules executing get_user at another process's context. I also tried to use ptrace_readdata, however, it seems that the file at /kernel/ptrace.c leaves a function access_process_vm undefined and also I don't know how to compile the source code of my module with this file (the linker seaches file in /linux/include by default). I am wondering if there are any other solutions... Best, Fangkai -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: repetitive log message
Hi On Wed, Apr 28, 2010 at 22:28, wrote: > hey all, > > after my kernel module release, this error message get repetitive(every > second) printed in the syslog file: > > [73954.719416] Pid: 0, comm: swapper Tainted: P 2.6.25-rt > ai3.7.1-core2 #1 > [73954.719416] [dequeue_task_idle+0x30/0x60] dequeue_task_idle+0 > x30/0x60 You mean, after a certain kernel module is unloaded, right? I think, the simplest way to do it, try to reinsert it back (insmod or modprobe). Then check, does the repetitive messages stop? If yes, maybe the kernel module's exit function doesn't do something cleanly. Hopefully, you have the source code of this module, then you can track it down there. -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Dynamic Kernel Module Section Addresses
On Wed, Apr 28, 2010 at 12:07 AM, Venkatram Tummala wrote: > On Tue, Apr 27, 2010 at 11:58 PM, Joel Fernandes wrote: > >> Hey Venkatram, >> >> On Wed, Apr 28, 2010 at 11:33 AM, Venkatram Tummala < >> venkatram...@gmail.com> wrote: >>> >>> to find these addresses by "p modules", the module has to be already >>> loaded.right? So, the initialization function of the module must have >>> been already executedright? So, the question is how can we step through >>> the initialization function of the module..? "p modules" won't help >>> us..probably looking at /sys is a faster way to find module segment >>> addresses, or am I missing something here in "p modules"?? >>> >>> >> Why don't you try setting breakpoints in kernel (kernel/module.c) after >> the module has been loaded but before your modules' init function is called? >> >> From kernel/module.c , in SYSCALL_DEFINE3(init_module..): >> the line load_module(...) loads your module into the kernel, and the line >> do_one_initcall(mod->init); calls the init functions. >> So I think if you set a break point in between these lines, you should be >> able to get the address of text section etc just in time before the init >> functions is called, using p modules or something. >> > Apparently the trick didn't work for me because the vm in vmware workstation is supposed to get freezed when a breakpoint is encountered. So, the kernel freezes & we only have the gdb console to play with. Once we hit continue, the vm & hence the kernel comes back alive but again by that time, the initialization function finishes executing. So, i cannot look at a /sys entry to find the module section addresses while gdb is sitting on a breakpoint. We only have the gdb console to look the section address & nothing else while at a breakpoint. "p modules" will help but it is too much of a work every time one tries to debug. In Summary, the only way is to force the kernel to place the module at exactly the same address everytime. Anybody has any ideas as to how we can achieve this? Thanks. Venkatram > > Hey Joel, > > Yup, that is exactly the trick mentioned by Mulyadi in the previous post. > Will try that & there is no reason why this won't work. This will definitely > solve the problem. > > Thanks Everybody, > Venkatram > >> >> -Joel >> >> >
Doubts in fast system call
Hello All, My problem is i want to find a fast way to switch from user mode to kernel mode. I read about the sysenter instructions on the net. I want to know a method to find whether my OS uses sysenter or software interrupt method (int 0x80). Can anybody please help me in finding this? Also i would really appreciate if you can suggest any other fast way to change from user to kernel mode... Thank you... Thanks, Bala
RE: Not able to boot Linux-2.6.33.2
-Original Message- From: kernelnewbies-bou...@nl.linux.org [mailto:kernelnewbies-bou...@nl.linux.org] On Behalf Of Anuz Pratap Singh Tomar Sent: Tuesday, April 27, 2010 5:11 AM To: Srdjan Todorovic Cc: Mukesh Yadav; kernelnewbies@nl.linux.org Subject: Re: Not able to boot Linux-2.6.33.2 I think the root file system is mounted or you would not get this far. The modules directory is not accessed until the init process is executing, which itself is on the root file system. I think one problem is that the modules directory for the kernel is missing. This directory is built by the make install command. Are you building the kernel on one system and booting it on another (the Virtualbox)? Bruce
Re: about copy_from_user().
Hi! On 19:36 Wed 28 Apr , calix wrote: > Hi, > > When I use copy_from_user(void *to, const void __user *from, unsigned long > n), should the n is less than a PAGESIZE? It does not need to be smallor than PAGESIZE, but it must not be larger than either the user space buffer or kernel space buffer. Allocating more than PAGESIZE in kernel space is usually not such good idea, because it might easily be much slower. Note that kernel space buffers must be physically continuous (except when using vmalloc, which is even slower) and memory fragmentation might cause slowdowns. -Michi -- programing a layer 3+4 network protocol for mesh networks see http://michaelblizek.twilightparadox.com -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
repetitive log message
hey all, after my kernel module release, this error message get repetitive(every second) printed in the syslog file: [73954.719416] Pid: 0, comm: swapper Tainted: P 2.6.25-rt ai3.7.1-core2 #1 [73954.719416] [dequeue_task_idle+0x30/0x60] dequeue_task_idle+0 x30/0x60 [73954.719416] [deactivate_task+0x29/0x50] deactivate_task+0x29/ 0x50 [73954.719416] [default_idle+0x0/0x90] default_idle+0x0/0x90 [73954.719416] [jbd:schedule+0x1dd/0x310] schedule+0x1dd/0x290 [73954.719416] [default_idle+0x0/0x90] default_idle+0x0/0x90 [73954.719416] [default_idle+0x0/0x90] default_idle+0x0/0x90 [73954.719416] [cpu_idle+0x3c/0xb0] cpu_idle+0x3c/0xb0 [73954.719416] === my question is how can I narrow done the cause of this? greetings maurice -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Not able to boot Linux-2.6.33.2
On Wed, Apr 28, 2010 at 13:35, Mukesh Yadav wrote: > Hi Folks > > I made some progress. I could boot system at runlevel 1. With following > changes: > 1. Setting root=/dev/sda1 at grub. > 2. Avoiding booting "initrd". I compiled everything in kernel. Removed > initrd entry from grub. > > So, as far as booting is concerned, it seems to be someting wrong with > initrd image. IIRC, you did mkinitramfs to create initrd, right? Try using mkinitrd instead and see how it goes -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
about copy_from_user().
Hi, When I use copy_from_user(void *to, const void __user *from, unsigned long n), should the n is less than a PAGESIZE? If so ,why? Thanks for any suggestion. -- Best Regards! make a difference. Calix
Re: question about get_user
I believe that you are having pid and passing that to your character driver. How about using find_task_by_id(pid) function in your virtual driver. it returns pointer to task_struct for particular pid. e.g. pid_t pid; struct task_struct *my; my = find_task_by_id(pid) printf("%s",my->comm); //print or do whatever you want to do with it Regards, _-_Mayank Rana_-_ --- On Wed, 4/28/10, Manish Katiyar wrote: From: Manish Katiyar Subject: Re: question about get_user To: "Yang Fangkai" Cc: "nidhi mittal hada" , "Kernelnewbies" Date: Wednesday, April 28, 2010, 12:49 PM On Wed, Apr 28, 2010 at 12:24 PM, Yang Fangkai wrote: > Hi, Nidhi, > > Thanks! Now I know what is the problem. > > But in my project, I am developing a virtual char device driver > such that user can read any process's memory contents by specifying > its pid and virtual address. Therefore, a device /dev/gh is > registered, and the user try to do something like: > > echo -n targetpid>/dev/gh & echo -n addr>/dev/gh > > Therefore, the target process can't be modified. The device driver > will retrieve the value by pid and virtual address and return it to > user at terminal. Isn't it something similar to ptrace with PTRACE_PEEKTEXT, PTRACE_PEEKDATA Thanks - Manish > I don't know how to solve this problem with get_user > under my scenario. Thank you! > > Fangkai > > On Wed, Apr 28, 2010 at 1:42 AM, nidhi mittal hada > wrote: >> you should somehow call the kernel module from user space program ... >> may be using ioctl .. >> so that you are in same process context --- as the one you are sending >> address from . >> >> write char dev driver with ioctl method defined >> then call ioctl from user space >> >> ioctl(fd,,addrees you want to send) >> >> >> Now in kernel module >> >> get_user(kernel data variable, ); >> >> Nidhi >> >> >> >> >> >> >> >> On Wed, Apr 28, 2010 at 11:55 AM, Yang Fangkai >> wrote: >>> >>> Hi, Nidhi, >>> >>> Thanks for your reply! Yes, you are right. I pass the address >>> to the module from bash command echo, therefore when the address is >>> referred, the current pid is bash's pid, instead of the simple program >>> I wrote. >>> >>> But how can I fix this problem? >>> >>> Thank you! >>> >>> Fangkai >>> >>> On Wed, Apr 28, 2010 at 1:01 AM, nidhi mittal hada >>> wrote: >>> > >>> > in your kernel module try to print current->pid >>> > is it same as the user space process id ? >>> > i think when in kernel module you are not in the same process context >>> > whihc >>> > you want to refer ... >>> > >>> > >>> > Nidhi >>> > >>> > On Wed, Apr 28, 2010 at 10:38 AM, Yang Fangkai >>> > wrote: >>> >> >>> >> Hi, all, >>> >> >>> >> I have a problem with get_user() macro. What I did is as follows: >>> >> >>> >> I run the following program >>> >> >>> >> int main() >>> >> { >>> >> int a = 20; >>> >> printf("address of a: %p", &a); >>> >> sleep(200); >>> >> return 0; >>> >> } >>> >> >>> >> When the program runs, it outputs the address of a, say, 0xbff91914. >>> >> >>> >> Then I pass this address to a module running in Kernel Mode that >>> >> retrieves the contents at this address (at the time when I did this, I >>> >> also made sure the process didn't terminate, because I put it to sleep >>> >> for 200 seconds... ): >>> >> >>> >> The address is firstly sent as a string, and I cast them into pointer >>> >> type. >>> >> >>> >> int * ptr = (int*)simple_strtol(buffer, NULL,16); >>> >> printk("address: %p",ptr); // I use this line to make sure the cast is >>> >> correct. When running, it does output bff91914 >>> >> int val = 0; >>> >> int res; >>> >> res= get_user(val, (int*) ptr); >>> >> >>> >> However, res is always not 0, meaning that get_user returns error. I >>> >> am wondering what is the problem >>> >> >>> >> Thank you!! >>> >> >>> >> -- >>> >> To unsubscribe from this list: send an email with >>> >> "unsubscribe kernelnewbies" to ecar...@nl.linux.org >>> >> Please read the FAQ at http://kernelnewbies.org/FAQ >>> >> >>> > >>> > >>> > >>> > -- >>> > Thanks & Regards >>> > Nidhi Mittal Hada >>> > Scientific officer D >>> > Computer Division >>> > Bhabha Atomic Research Center >>> > Mumbai >>> > >>> > >>> > >> >> >> >> -- >> Thanks & Regards >> Nidhi Mittal Hada >> Scientific officer D >> Computer Division >> Bhabha Atomic Research Center >> Mumbai >> >> >> > > -- > To unsubscribe from this list: send an email with > "unsubscribe kernelnewbies" to ecar...@nl.linux.org > Please read the FAQ at http://kernelnewbies.org/FAQ > > -- Thanks - Manish == [$\*.^ -- I miss being one of them == -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Timekeeping problem: time runs too fast
Hello all, I'm working on the porting of uClinux 2.6.19 for a new architecture. The system is booting without problems, but I have a problem concerning timekeeping. Indeed, the date command shows that time runs too fast (5 sec in reality for around 10 minutes in Linux...). So I have read documentation about timekeeping, the important things seems to be the following: - jiffies -> number of timer interrupts (ticks) since the system startup. - xtime.tv_sec -> number of seconds elapsed since Epoch (1970, jan 1 00:00:00) - xtime.tv_nsec -> number of nanoseconds elapsed during the current second. These variables are updated at each timer interrupts, notably in update_wall_time() where xtime fields are modified in an algorithm involving the kernel clock (clocksource). Does this timekeeping mechanism perfectly functionnal for this version of the kernel? I have an other question concerning the macro CLOCK_TICK_RATE (include/asm-'arch-name'/timex.h): this macro seems to be architecture dependant. It's generally 1193180. What is this macro used for? What value should I give to it? Thanks in advance for your help. Regards. -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: question about get_user
Nidhi, I have thought about this possibility but that seems to be incredibly complicated. I need to go through all the paging mechanism or even deal with page fault manually! That is a bit too far than I plan to do. Thanks! Fangkai On Wed, Apr 28, 2010 at 2:55 AM, nidhi mittal hada wrote: > > that clearly shows that > the process you will call module from is not the one whose address you > want to get value of ... > > > i think with using pid you will search list of processes maintained by > kernel > and then you need to traverse mm_struct of reqd process > then virtual memory address space of the process vm_areas > > and then you will find what is the value present at a particular address > for a particular process > > > Nidhi > > On Wed, Apr 28, 2010 at 12:24 PM, Yang Fangkai > wrote: >> >> Hi, Nidhi, >> >> Thanks! Now I know what is the problem. >> >> But in my project, I am developing a virtual char device driver >> such that user can read any process's memory contents by specifying >> its pid and virtual address. Therefore, a device /dev/gh is >> registered, and the user try to do something like: >> >> echo -n targetpid>/dev/gh & echo -n addr>/dev/gh >> >> Therefore, the target process can't be modified. The device driver >> will retrieve the value by pid and virtual address and return it to >> user at terminal. I don't know how to solve this problem with get_user >> under my scenario. Thank you! >> >> Fangkai >> >> On Wed, Apr 28, 2010 at 1:42 AM, nidhi mittal hada >> wrote: >> > you should somehow call the kernel module from user space program ... >> > may be using ioctl .. >> > so that you are in same process context --- as the one you are sending >> > address from . >> > >> > write char dev driver with ioctl method defined >> > then call ioctl from user space >> > >> > ioctl(fd,,addrees you want to send) >> > >> > >> > Now in kernel module >> > >> > get_user(kernel data variable, ); >> > >> > Nidhi >> > >> > >> > >> > >> > >> > >> > >> > On Wed, Apr 28, 2010 at 11:55 AM, Yang Fangkai >> > wrote: >> >> >> >> Hi, Nidhi, >> >> >> >> Thanks for your reply! Yes, you are right. I pass the address >> >> to the module from bash command echo, therefore when the address is >> >> referred, the current pid is bash's pid, instead of the simple program >> >> I wrote. >> >> >> >> But how can I fix this problem? >> >> >> >> Thank you! >> >> >> >> Fangkai >> >> >> >> On Wed, Apr 28, 2010 at 1:01 AM, nidhi mittal hada >> >> wrote: >> >> > >> >> > in your kernel module try to print current->pid >> >> > is it same as the user space process id ? >> >> > i think when in kernel module you are not in the same process context >> >> > whihc >> >> > you want to refer ... >> >> > >> >> > >> >> > Nidhi >> >> > >> >> > On Wed, Apr 28, 2010 at 10:38 AM, Yang Fangkai >> >> > >> >> > wrote: >> >> >> >> >> >> Hi, all, >> >> >> >> >> >> I have a problem with get_user() macro. What I did is as follows: >> >> >> >> >> >> I run the following program >> >> >> >> >> >> int main() >> >> >> { >> >> >> int a = 20; >> >> >> printf("address of a: %p", &a); >> >> >> sleep(200); >> >> >> return 0; >> >> >> } >> >> >> >> >> >> When the program runs, it outputs the address of a, say, 0xbff91914. >> >> >> >> >> >> Then I pass this address to a module running in Kernel Mode that >> >> >> retrieves the contents at this address (at the time when I did this, >> >> >> I >> >> >> also made sure the process didn't terminate, because I put it to >> >> >> sleep >> >> >> for 200 seconds... ): >> >> >> >> >> >> The address is firstly sent as a string, and I cast them into >> >> >> pointer >> >> >> type. >> >> >> >> >> >> int * ptr = (int*)simple_strtol(buffer, NULL,16); >> >> >> printk("address: %p",ptr); // I use this line to make sure the cast >> >> >> is >> >> >> correct. When running, it does output bff91914 >> >> >> int val = 0; >> >> >> int res; >> >> >> res= get_user(val, (int*) ptr); >> >> >> >> >> >> However, res is always not 0, meaning that get_user returns error. I >> >> >> am wondering what is the problem >> >> >> >> >> >> Thank you!! >> >> >> >> >> >> -- >> >> >> To unsubscribe from this list: send an email with >> >> >> "unsubscribe kernelnewbies" to ecar...@nl.linux.org >> >> >> Please read the FAQ at http://kernelnewbies.org/FAQ >> >> >> >> >> > >> >> > >> >> > >> >> > -- >> >> > Thanks & Regards >> >> > Nidhi Mittal Hada >> >> > Scientific officer D >> >> > Computer Division >> >> > Bhabha Atomic Research Center >> >> > Mumbai >> >> > >> >> > >> >> > >> > >> > >> > >> > -- >> > Thanks & Regards >> > Nidhi Mittal Hada >> > Scientific officer D >> > Computer Division >> > Bhabha Atomic Research Center >> > Mumbai >> > >> > >> > > > > > -- > Thanks & Regards > Nidhi Mittal Hada > Scientific officer D > Computer Division > Bhabha Atomic Research Center > Mumbai > > > -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar..
Re: question about get_user
that clearly shows that the process you will call module from is not the one whose address you want to get value of ... i think with using pid you will search list of processes maintained by kernel and then you need to traverse mm_struct of reqd process then virtual memory address space of the process vm_areas and then you will find what is the value present at a particular address for a particular process Nidhi On Wed, Apr 28, 2010 at 12:24 PM, Yang Fangkai wrote: > Hi, Nidhi, > > Thanks! Now I know what is the problem. > > But in my project, I am developing a virtual char device driver > such that user can read any process's memory contents by specifying > its pid and virtual address. Therefore, a device /dev/gh is > registered, and the user try to do something like: > > echo -n targetpid>/dev/gh & echo -n addr>/dev/gh > > Therefore, the target process can't be modified. The device driver > will retrieve the value by pid and virtual address and return it to > user at terminal. I don't know how to solve this problem with get_user > under my scenario. Thank you! > > Fangkai > > On Wed, Apr 28, 2010 at 1:42 AM, nidhi mittal hada > wrote: > > you should somehow call the kernel module from user space program ... > > may be using ioctl .. > > so that you are in same process context --- as the one you are sending > > address from . > > > > write char dev driver with ioctl method defined > > then call ioctl from user space > > > > ioctl(fd,,addrees you want to send) > > > > > > Now in kernel module > > > > get_user(kernel data variable, ); > > > > Nidhi > > > > > > > > > > > > > > > > On Wed, Apr 28, 2010 at 11:55 AM, Yang Fangkai > > wrote: > >> > >> Hi, Nidhi, > >> > >>Thanks for your reply! Yes, you are right. I pass the address > >> to the module from bash command echo, therefore when the address is > >> referred, the current pid is bash's pid, instead of the simple program > >> I wrote. > >> > >> But how can I fix this problem? > >> > >> Thank you! > >> > >> Fangkai > >> > >> On Wed, Apr 28, 2010 at 1:01 AM, nidhi mittal hada > >> wrote: > >> > > >> > in your kernel module try to print current->pid > >> > is it same as the user space process id ? > >> > i think when in kernel module you are not in the same process context > >> > whihc > >> > you want to refer ... > >> > > >> > > >> > Nidhi > >> > > >> > On Wed, Apr 28, 2010 at 10:38 AM, Yang Fangkai < > wolfgang.y...@gmail.com> > >> > wrote: > >> >> > >> >> Hi, all, > >> >> > >> >> I have a problem with get_user() macro. What I did is as follows: > >> >> > >> >> I run the following program > >> >> > >> >> int main() > >> >> { > >> >> int a = 20; > >> >> printf("address of a: %p", &a); > >> >> sleep(200); > >> >> return 0; > >> >> } > >> >> > >> >> When the program runs, it outputs the address of a, say, 0xbff91914. > >> >> > >> >> Then I pass this address to a module running in Kernel Mode that > >> >> retrieves the contents at this address (at the time when I did this, > I > >> >> also made sure the process didn't terminate, because I put it to > sleep > >> >> for 200 seconds... ): > >> >> > >> >> The address is firstly sent as a string, and I cast them into pointer > >> >> type. > >> >> > >> >> int * ptr = (int*)simple_strtol(buffer, NULL,16); > >> >> printk("address: %p",ptr); // I use this line to make sure the cast > is > >> >> correct. When running, it does output bff91914 > >> >> int val = 0; > >> >> int res; > >> >> res= get_user(val, (int*) ptr); > >> >> > >> >> However, res is always not 0, meaning that get_user returns error. I > >> >> am wondering what is the problem > >> >> > >> >> Thank you!! > >> >> > >> >> -- > >> >> To unsubscribe from this list: send an email with > >> >> "unsubscribe kernelnewbies" to ecar...@nl.linux.org > >> >> Please read the FAQ at http://kernelnewbies.org/FAQ > >> >> > >> > > >> > > >> > > >> > -- > >> > Thanks & Regards > >> > Nidhi Mittal Hada > >> > Scientific officer D > >> > Computer Division > >> > Bhabha Atomic Research Center > >> > Mumbai > >> > > >> > > >> > > > > > > > > > -- > > Thanks & Regards > > Nidhi Mittal Hada > > Scientific officer D > > Computer Division > > Bhabha Atomic Research Center > > Mumbai > > > > > > > -- Thanks & Regards Nidhi Mittal Hada Scientific officer D Computer Division Bhabha Atomic Research Center Mumbai
Re: question about get_user
Oh, yes, something like that... Maybe I should have used ptrace to solve this problem instead of by get_user.. Thanks! Fangkai On Wed, Apr 28, 2010 at 2:19 AM, Manish Katiyar wrote: > On Wed, Apr 28, 2010 at 12:24 PM, Yang Fangkai > wrote: >> Hi, Nidhi, >> >> Thanks! Now I know what is the problem. >> >> But in my project, I am developing a virtual char device driver >> such that user can read any process's memory contents by specifying >> its pid and virtual address. Therefore, a device /dev/gh is >> registered, and the user try to do something like: >> >> echo -n targetpid>/dev/gh & echo -n addr>/dev/gh >> >> Therefore, the target process can't be modified. The device driver >> will retrieve the value by pid and virtual address and return it to >> user at terminal. > > Isn't it something similar to ptrace with PTRACE_PEEKTEXT, PTRACE_PEEKDATA > > Thanks - > Manish >> I don't know how to solve this problem with get_user >> under my scenario. Thank you! >> >> Fangkai >> >> On Wed, Apr 28, 2010 at 1:42 AM, nidhi mittal hada >> wrote: >>> you should somehow call the kernel module from user space program ... >>> may be using ioctl .. >>> so that you are in same process context --- as the one you are sending >>> address from . >>> >>> write char dev driver with ioctl method defined >>> then call ioctl from user space >>> >>> ioctl(fd,,addrees you want to send) >>> >>> >>> Now in kernel module >>> >>> get_user(kernel data variable, ); >>> >>> Nidhi >>> >>> >>> >>> >>> >>> >>> >>> On Wed, Apr 28, 2010 at 11:55 AM, Yang Fangkai >>> wrote: Hi, Nidhi, Thanks for your reply! Yes, you are right. I pass the address to the module from bash command echo, therefore when the address is referred, the current pid is bash's pid, instead of the simple program I wrote. But how can I fix this problem? Thank you! Fangkai On Wed, Apr 28, 2010 at 1:01 AM, nidhi mittal hada wrote: > > in your kernel module try to print current->pid > is it same as the user space process id ? > i think when in kernel module you are not in the same process context > whihc > you want to refer ... > > > Nidhi > > On Wed, Apr 28, 2010 at 10:38 AM, Yang Fangkai > wrote: >> >> Hi, all, >> >> I have a problem with get_user() macro. What I did is as follows: >> >> I run the following program >> >> int main() >> { >> int a = 20; >> printf("address of a: %p", &a); >> sleep(200); >> return 0; >> } >> >> When the program runs, it outputs the address of a, say, 0xbff91914. >> >> Then I pass this address to a module running in Kernel Mode that >> retrieves the contents at this address (at the time when I did this, I >> also made sure the process didn't terminate, because I put it to sleep >> for 200 seconds... ): >> >> The address is firstly sent as a string, and I cast them into pointer >> type. >> >> int * ptr = (int*)simple_strtol(buffer, NULL,16); >> printk("address: %p",ptr); // I use this line to make sure the cast is >> correct. When running, it does output bff91914 >> int val = 0; >> int res; >> res= get_user(val, (int*) ptr); >> >> However, res is always not 0, meaning that get_user returns error. I >> am wondering what is the problem >> >> Thank you!! >> >> -- >> To unsubscribe from this list: send an email with >> "unsubscribe kernelnewbies" to ecar...@nl.linux.org >> Please read the FAQ at http://kernelnewbies.org/FAQ >> > > > > -- > Thanks & Regards > Nidhi Mittal Hada > Scientific officer D > Computer Division > Bhabha Atomic Research Center > Mumbai > > > >>> >>> >>> >>> -- >>> Thanks & Regards >>> Nidhi Mittal Hada >>> Scientific officer D >>> Computer Division >>> Bhabha Atomic Research Center >>> Mumbai >>> >>> >>> >> >> -- >> To unsubscribe from this list: send an email with >> "unsubscribe kernelnewbies" to ecar...@nl.linux.org >> Please read the FAQ at http://kernelnewbies.org/FAQ >> >> > > > > -- > Thanks - > Manish > == > [$\*.^ -- I miss being one of them > == > -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
can someone tell me why should i use PAGE_ALIGN after kmalloc?
Here is a example : / capsule_header_array[capsule_index] = (efi_capsule_header_t *)kmalloc ( capsule_header_size + PAGE_SIZE, GFP_KERNEL); if (capsule_header_array[capsule_index] == NULL) { printk(KERN_ALERT " Oops - constructcapsuleheaderarray() malloc 0x%08x fail \n", (unsigned int)(capsule_header_size + PAGE_SIZE)); return -1; } // // make it page aligned // capsule_header_array[capsule_index] = (efi_capsule_header_t *) \ (unsigned long)PAGE_ALIGN((unsigned long)capsule_header_array[capsule_index]); Thanks for any help~! -- Best Regards! make a difference. Calix
Re: Dynamic Kernel Module Section Addresses
On Tue, Apr 27, 2010 at 11:58 PM, Joel Fernandes wrote: > Hey Venkatram, > > On Wed, Apr 28, 2010 at 11:33 AM, Venkatram Tummala < > venkatram...@gmail.com> wrote: >> >> to find these addresses by "p modules", the module has to be already >> loaded.right? So, the initialization function of the module must have >> been already executedright? So, the question is how can we step through >> the initialization function of the module..? "p modules" won't help >> us..probably looking at /sys is a faster way to find module segment >> addresses, or am I missing something here in "p modules"?? >> >> > Why don't you try setting breakpoints in kernel (kernel/module.c) after the > module has been loaded but before your modules' init function is called? > > From kernel/module.c , in SYSCALL_DEFINE3(init_module..): > the line load_module(...) loads your module into the kernel, and the line > do_one_initcall(mod->init); calls the init functions. > So I think if you set a break point in between these lines, you should be > able to get the address of text section etc just in time before the init > functions is called, using p modules or something. > Hey Joel, Yup, that is exactly the trick mentioned by Mulyadi in the previous post. Will try that & there is no reason why this won't work. This will definitely solve the problem. Thanks Everybody, Venkatram > > -Joel > >
Re: question about get_user
On Wed, Apr 28, 2010 at 12:24 PM, Yang Fangkai wrote: > Hi, Nidhi, > > Thanks! Now I know what is the problem. > > But in my project, I am developing a virtual char device driver > such that user can read any process's memory contents by specifying > its pid and virtual address. Therefore, a device /dev/gh is > registered, and the user try to do something like: > > echo -n targetpid>/dev/gh & echo -n addr>/dev/gh > > Therefore, the target process can't be modified. The device driver > will retrieve the value by pid and virtual address and return it to > user at terminal. Isn't it something similar to ptrace with PTRACE_PEEKTEXT, PTRACE_PEEKDATA Thanks - Manish > I don't know how to solve this problem with get_user > under my scenario. Thank you! > > Fangkai > > On Wed, Apr 28, 2010 at 1:42 AM, nidhi mittal hada > wrote: >> you should somehow call the kernel module from user space program ... >> may be using ioctl .. >> so that you are in same process context --- as the one you are sending >> address from . >> >> write char dev driver with ioctl method defined >> then call ioctl from user space >> >> ioctl(fd,,addrees you want to send) >> >> >> Now in kernel module >> >> get_user(kernel data variable, ); >> >> Nidhi >> >> >> >> >> >> >> >> On Wed, Apr 28, 2010 at 11:55 AM, Yang Fangkai >> wrote: >>> >>> Hi, Nidhi, >>> >>> Thanks for your reply! Yes, you are right. I pass the address >>> to the module from bash command echo, therefore when the address is >>> referred, the current pid is bash's pid, instead of the simple program >>> I wrote. >>> >>> But how can I fix this problem? >>> >>> Thank you! >>> >>> Fangkai >>> >>> On Wed, Apr 28, 2010 at 1:01 AM, nidhi mittal hada >>> wrote: >>> > >>> > in your kernel module try to print current->pid >>> > is it same as the user space process id ? >>> > i think when in kernel module you are not in the same process context >>> > whihc >>> > you want to refer ... >>> > >>> > >>> > Nidhi >>> > >>> > On Wed, Apr 28, 2010 at 10:38 AM, Yang Fangkai >>> > wrote: >>> >> >>> >> Hi, all, >>> >> >>> >> I have a problem with get_user() macro. What I did is as follows: >>> >> >>> >> I run the following program >>> >> >>> >> int main() >>> >> { >>> >> int a = 20; >>> >> printf("address of a: %p", &a); >>> >> sleep(200); >>> >> return 0; >>> >> } >>> >> >>> >> When the program runs, it outputs the address of a, say, 0xbff91914. >>> >> >>> >> Then I pass this address to a module running in Kernel Mode that >>> >> retrieves the contents at this address (at the time when I did this, I >>> >> also made sure the process didn't terminate, because I put it to sleep >>> >> for 200 seconds... ): >>> >> >>> >> The address is firstly sent as a string, and I cast them into pointer >>> >> type. >>> >> >>> >> int * ptr = (int*)simple_strtol(buffer, NULL,16); >>> >> printk("address: %p",ptr); // I use this line to make sure the cast is >>> >> correct. When running, it does output bff91914 >>> >> int val = 0; >>> >> int res; >>> >> res= get_user(val, (int*) ptr); >>> >> >>> >> However, res is always not 0, meaning that get_user returns error. I >>> >> am wondering what is the problem >>> >> >>> >> Thank you!! >>> >> >>> >> -- >>> >> To unsubscribe from this list: send an email with >>> >> "unsubscribe kernelnewbies" to ecar...@nl.linux.org >>> >> Please read the FAQ at http://kernelnewbies.org/FAQ >>> >> >>> > >>> > >>> > >>> > -- >>> > Thanks & Regards >>> > Nidhi Mittal Hada >>> > Scientific officer D >>> > Computer Division >>> > Bhabha Atomic Research Center >>> > Mumbai >>> > >>> > >>> > >> >> >> >> -- >> Thanks & Regards >> Nidhi Mittal Hada >> Scientific officer D >> Computer Division >> Bhabha Atomic Research Center >> Mumbai >> >> >> > > -- > To unsubscribe from this list: send an email with > "unsubscribe kernelnewbies" to ecar...@nl.linux.org > Please read the FAQ at http://kernelnewbies.org/FAQ > > -- Thanks - Manish == [$\*.^ -- I miss being one of them == -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Dynamic Kernel Module Section Addresses
Hey Venkatram, On Wed, Apr 28, 2010 at 11:33 AM, Venkatram Tummala wrote: > > to find these addresses by "p modules", the module has to be already > loaded.right? So, the initialization function of the module must have > been already executedright? So, the question is how can we step through > the initialization function of the module..? "p modules" won't help > us..probably looking at /sys is a faster way to find module segment > addresses, or am I missing something here in "p modules"?? > > Why don't you try setting breakpoints in kernel (kernel/module.c) after the module has been loaded but before your modules' init function is called? >From kernel/module.c , in SYSCALL_DEFINE3(init_module..): the line load_module(...) loads your module into the kernel, and the line do_one_initcall(mod->init); calls the init functions. So I think if you set a break point in between these lines, you should be able to get the address of text section etc just in time before the init functions is called, using p modules or something. -Joel