From: Vadim Lobanov <vlobanov@speakeasy.net>
To: Hacksaw <hacksaw@hacksaw.org>
Cc: linux-os@analogic.com, "Theodore Ts'o" <tytso@mit.edu>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Tomko <tomko@haha.com>,
Linux Kernel list <linux-kernel@vger.kernel.org>
Subject: Re: Why system call need to copy the date from the userspace before using it
Date: Fri, 15 Apr 2005 22:18:42 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.58.0504152209260.18492@shell3.speakeasy.net> (raw)
In-Reply-To: <200504160450.j3G4oqC9029496@hacksaw.org>
On Sat, 16 Apr 2005, Hacksaw wrote:
> Sorry if this bugs anyone, but I'm learning things here.
>
> What I would expect the kernel to do is this:
>
> system_call_data_prep (userdata, size){
>
> if !4G/4G {
> for each page from userdata to userdata+size
> {
> if the page is swapped out, swap it in
> if the page is not owned by the user process, return -ENOWAYMAN
> otherwise, lock the page
> }
> return userdata;
> }
> else { //kernel land and userland are mutually exclusive
> copy the data into kernel land
> return kernelland_copy_of_userdata;
> }
> }
>
> (And then the syscall would need to run the opposite function
> sys_call_data_unprep to unlock pages.)
>
> Hmm, maybe that interface sucks.
That's one approach. Unfortunately, it's not what the kernel currently
does. The root of the problem is -- it needs to copy the data, even if
the kernel can access userspace data. There are many reasons for why
this is a simpler way to program the interface; if you want actual
concrete examples, let me know.
In order to accomplish the copy_from_user() procedure, from the i386
perspective, the kernel first figures out where userspace is telling it
to look for the data buffer. It checks if the LAST page belongs to
userland, and fails if not; this works because the kernel sits in higher
memory. Then it simply does the direct copy. If during the copy it hits
an invalid page, the exception handler code will run, realize that the
exception occurred because of the copy, and return an error code right
then and there.
Lots of details left out, but this is the 10,000 foot view, I think.
-Vadim Lobanov
> Is it anything close to that?
>
> --
> The best is the enemy of the good -- Voltaire
> The Good Enough is the enemy of the Great -- Me
> http://www.hacksaw.org -- http://www.privatecircus.com -- KB1FVD
>
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/
>
next prev parent reply other threads:[~2005-04-16 5:18 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-04-13 4:21 Tomko
2005-04-13 5:30 ` Vadim Lobanov
2005-04-13 10:29 ` Jan-Benedict Glaw
2005-04-13 10:43 ` Tomko
2005-04-13 11:10 ` Catalin Marinas
2005-04-14 2:10 ` Tomko
2005-04-14 2:18 ` David Schwartz
2005-04-14 14:05 ` Helge Hafting
2005-04-13 11:33 ` Benjamin Herrenschmidt
2005-04-13 11:59 ` Hacksaw
2005-04-13 12:40 ` Richard B. Johnson
2005-04-13 18:37 ` Theodore Ts'o
2005-04-13 19:20 ` Richard B. Johnson
2005-04-16 4:50 ` Hacksaw
2005-04-16 5:18 ` Vadim Lobanov [this message]
2005-04-16 8:30 ` Hacksaw
2005-04-16 19:35 ` Vadim Lobanov
2005-04-16 23:46 ` David Wagner
2005-04-13 6:48 Vadim Lobanov
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=Pine.LNX.4.58.0504152209260.18492@shell3.speakeasy.net \
--to=vlobanov@speakeasy.net \
--cc=benh@kernel.crashing.org \
--cc=hacksaw@hacksaw.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-os@analogic.com \
--cc=tomko@haha.com \
--cc=tytso@mit.edu \
/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
all inboxes | Powered by JetHome®