RE: Problem with copy_from_user

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

 



Hi all,

Ok, I am resending the same question with more details.

I am trying to implement a protocol in linux kernel (2.6.14) for
experimental purposes and I am facing a weird problem.

rt_instance is an instance of a structure in user space.
rt_u is a variable in user space which points to rt_instance.
rt_k is a variable in kernel space which I want to use to read rt_instance,
hence, it should point to rt_instance too.

The following code is a system call which I wrote, which basically passes
the address of rt_instance to the kernel by copying rt_u to rt_u . Then, I
use copy_from_user to copy rt_instance to a local variable (local_rt) in
kernel space. Then, I read the content of local_rt and the code works fine:
n = 0, and local_rt.session_list shows the correct value.

asmlinkage int sys_asimcast(struct routing_table *rt_u) {
	rt_k = rt_u;
	if (rt_k != NULL) {
		struct routing_table local_rt;
		int n = copy_from_user(&local_rt, rt_k, sizeof(struct
routing_table));
		printk("rt_k.session_list = %d; n = %d.\n",
(int)local_rt.session_list, n);
	}
	return 2;
}

Now, I inserted the same code into ip_rcv function (/net/IPv4/ip_input.c,
right before the return statement) to read again the rt_instance, using the
same pointer rt_k.
copy_from_user returns 0 (means that it could read the structure properly)
BUT the data which has been read is incorrect.

if (rt_k != NULL) {
	struct routing_table local_rt;
	int n = copy_from_user(&local_rt, rt_k, sizeof(struct
routing_table));	printk("local_rt.session_list = %d; n = %d.\n",
(int)local_rt.session_list, n);
}

The bottom line is: the same code, written in the system call works, but
doesn't work in the kernel. Whenever I read the structure from the sys call,
it is read correctly, while from the ip_rcv function, it is not.
BTW, I made sure that rt_k is pointing to the same address in both cases (a
print statement showed the same value).

I am wondering if this problem has to do with the fact that copy_from_user
is user context only? I am not sure exactly what this means. Should I change
the context and how?

Best regards,

-- Laurent


--
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