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
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
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: question about get_user
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 > > > -- 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
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
Re: question about get_user
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 > > > -- 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
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
question about get_user
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