public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Robert Hancock <hancockr@shaw.ca>
Cc: Vinay Venkataraghavan <raghavanvinay@yahoo.com>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: copy_from_user/copy_to_user question
Date: Fri, 02 Dec 2005 22:23:45 -0500	[thread overview]
Message-ID: <1133580225.4894.29.camel@localhost.localdomain> (raw)
In-Reply-To: <43910731.4090404@shaw.ca>

Don't strip CC's

On Fri, 2005-12-02 at 20:47 -0600, Robert Hancock wrote:
> Vinay Venkataraghavan wrote:
> > But this is not always the case right. The point that
> > you mention above is specifically why I posted this
> > question. It could well be the case that the   user
> > space page could be swapped out when the user space
> > process is blocked. So when the ioctl is serviced in
> > kernel space, there is no guarantee that the page is
> > still mapped. This could cause a page fault. 
> > I think this is why we need to do a
> > copy_to_user/copy_from_user.
> 
> I don't think this is actually the case. I'm not entirely sure, but I 
> believe that if memcpy from user space works at all on a platform, then 
> if the page is swapped out it will still get swapped in when needed. In 
> any case, this is not the main reason for using these functions. The 
> main reason is that memory addresses passed from userspace might not be 
> valid at all, and reading these addresses directly would cause a kernel 
> oops in that case. These functions set up an exception handler so that 
> invalid address reads/writes return failure instead of crashing the system.

Nope, the kernel is always locked into memory.  If you take a page fault
from the kernel world, you will crash and burn. The kernel is never
"swapped out".  So if you are in kernel mode, going into do_page_fault
in arch/i386/mm/fault.c there is no path to swap a page in.  Even the
vmalloc_fault only handles a page not in the page global descriptor of
the current task.  But if this page is not mapped somewhere in memory
(not swapped out), you will get a kernel oops.

Kernel memory may never be swapped out. What happens if an interrupt
tries to use such memory. How does it handle sleeping?

Just change copy_to_user into memcopy, and see how long your system
stays up and running.  Do it on a machine that you don't need to worry
about rogue applications.  It won't last very long.

-- Steve



  reply	other threads:[~2005-12-03  3:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <5fv0G-3kS-11@gated-at.bofh.it>
     [not found] ` <5fvam-3vP-9@gated-at.bofh.it>
2005-12-03  2:47   ` copy_from_user/copy_to_user question Robert Hancock
2005-12-03  3:23     ` Steven Rostedt [this message]
2005-12-03  3:33       ` Robert Hancock
2005-12-03  4:53         ` Steven Rostedt
2005-12-03 22:35       ` Andi Kleen
2005-12-03 18:26         ` Steven Rostedt
2005-12-06 17:53           ` Vinay Venkataraghavan
2005-12-06 17:56             ` Arjan van de Ven
2005-12-06 18:23             ` Steven Rostedt
2005-12-06 18:23             ` linux-os (Dick Johnson)
2005-12-06 18:42               ` Steven Rostedt
2005-12-06 19:58                 ` linux-os (Dick Johnson)
2005-12-06 20:05               ` Vinay Venkataraghavan
2005-12-02 22:40 Vinay Venkataraghavan
2005-12-03  1:09 ` Steven Rostedt
2005-12-03  1:38   ` Al Viro
2005-12-03  2:02     ` Steven Rostedt
2005-12-03  2:11       ` Vinay Venkataraghavan
2005-12-03  2:22         ` Vinay Venkataraghavan
2005-12-03  2:27         ` Steven Rostedt
2005-12-03  8:33         ` Arjan van de Ven
2005-12-03  9:43       ` Heiko Carstens
2005-12-03 12:14         ` Steven Rostedt
2005-12-03 22:33       ` Andi Kleen
2005-12-05 13:31   ` linux-os (Dick Johnson)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1133580225.4894.29.camel@localhost.localdomain \
    --to=rostedt@goodmis.org \
    --cc=hancockr@shaw.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=raghavanvinay@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox