Re: Problem with copy_from_user

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

 



On 11/11/05, Laurent Nadeau <nadelau@xxxxxxx> wrote:
> Hi all,
>
> I am trying to implement a protocol in linux kernel (2.6.14) for
> experimental purposes and I am facing a weird problem.
>
> I created a system call; in that code, the data read by copy_from user()
> is correct.
> rt is a pointer in kernel space and rt_u is a pointer in user space.
>
> asmlinkage int sys_asimcast(struct routing_table *rt_u) {
>         rt = rt_u;

You are saying rt is pointer in kernel space and rt_u is of user
space, but in code you are assigning rt = rt_u ?  I think local_rt is
variable of kernel space ?


>         printk("Kernel has received pointer to routing table(%d);\n", (int)rt);
>         if (rt != NULL) {
>                 struct routing_table local_rt;
>                 int n = copy_from_user(&local_rt, rt, sizeof(struct routing_table));
>                 printk("rt.session_list = %d; n = %d.\n", (int)local_rt.session_list, n);
>         }
>         return 2;
> }
>


> Now, I copied the same code in ip_rcv (/net/IPv4/ip_input.c) and the
> data which is read is incorrect (the value of pointer rt remains the same);
>

Which same code ? The code above ? and in net/ipv4/ip_input.c
where/at_which_place you copied the code ? The code below is part of
functions which you copied ? I think its better for you to provide
some more code to get help !

> struct routing_table local_rt;
> if (rt != NULL) {
>         n = get_rt(&local_rt, rt);
>         printk("local_rt.session_list = %d; n = %d.\n",
> (int)local_rt.session_list, n);
> }
>


> I am wondering if this problem has to do with the fact that
> copy_from_user is user context only? If yes, should I change the context
> and how?
>

copy_from_user actually checks for that the address_of_source (from
which data is to be read) is from user space or not and if its not
from user space then it will fail and return zeros in destination
address !

> Sorry if the question sounds stupid, but I've een struggling with that
> issue for a while... :(

I don't think that any question (asked) sounds stupid, but it will be
good to have details/code with it to get help from others !


--
Fawad Lateef

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



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