public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Robert Hancock <hancockr@shaw.ca>
To: Clemens Kolbitsch <clemens.kol@gmx.at>
Cc: Chris Smith <smitty1elkml@gmail.com>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: Copy large memory regions from & to userspace
Date: Fri, 31 Aug 2007 19:48:12 -0600	[thread overview]
Message-ID: <46D8C4DC.2080307@shaw.ca> (raw)
In-Reply-To: <fa.tMlh7ZYvNMxPEL69Eww8ErwDEmw@ifi.uio.no>

Clemens Kolbitsch wrote:
> On Friday 31 August 2007 15:25:40 you wrote:
>> On 8/30/07, Clemens Kolbitsch <clemens.kol@gmx.at> wrote:
>>> Hi!
>>> Just a short question: What is the correct method of copying large areas
>>> of memory from userspace into userspace when running in kernel-mode?
>> relayfs?
> 
> no... I'm copying user-memory to user-memory, not kernel-to-user, however 
> running the code in kernel-mode.
> 
> what i wanted to know is how to check the access-rights...
> i didn't get any other answers, so for now i'm just using 
> 
> if (access_ok(VERIFY_READ, from, PAGE_SIZE) &&
>     access_ok(VERIFY_WRITE, to, PAGE_SIZE))
> {
>     memcpy(to, from, PAGE_SIZE);
> }
> 
> and hope that this is the *correct* way to do it...

No, it's not. access_ok does not guarantee that the memory region can be 
validly read or written. It only allows using __copy_to_user or 
__copy_from_user which skips the same checks that access_ok does.

I'm not aware of any code in the kernel that does userspace-to-userspace 
copies directly. Likely because there's rarely a need for it?

-- 
Robert Hancock      Saskatoon, SK, Canada
To email, remove "nospam" from hancockr@nospamshaw.ca
Home Page: http://www.roberthancock.com/


       reply	other threads:[~2007-09-01  1:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <fa.0TqRgC3Smn96vb+Bwv5QRWKBTQg@ifi.uio.no>
     [not found] ` <fa.x2L04usZZxVIMYSdrufu+Hen9aY@ifi.uio.no>
     [not found]   ` <fa.tMlh7ZYvNMxPEL69Eww8ErwDEmw@ifi.uio.no>
2007-09-01  1:48     ` Robert Hancock [this message]
2007-09-01  6:10       ` Copy large memory regions from & to userspace Jan Engelhardt
2007-08-30 22:29 Clemens Kolbitsch
     [not found] ` <9b53a56d0708310625q14defcb1l98ab8ce1df2c8fd7@mail.gmail.com>
2007-08-31 13:45   ` Clemens Kolbitsch

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=46D8C4DC.2080307@shaw.ca \
    --to=hancockr@shaw.ca \
    --cc=clemens.kol@gmx.at \
    --cc=linux-kernel@vger.kernel.org \
    --cc=smitty1elkml@gmail.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