From: "Sardañons, Eliel" <Eliel.Sardanons@philips.edu.ar>
To: "'linux-kernel@vger.kernel.org'" <linux-kernel@vger.kernel.org>
Subject: copy_to_user - (is the best way?)
Date: Thu, 29 Mar 2001 09:25:11 -0300 [thread overview]
Message-ID: <A0C675E9DC2CD411A5870040053AEBA0284141@MAINSERVER> (raw)
I have been looking, the syscalls and drivers in the kernel and always what
I see is something like this:
int func(char *user_buffer) {
/* A lot of function stuff */
...
/* then at the end when you write user_buffer I see */
if (copy_to_user(user_buffer, from, n))
return -EFAULT
return 0;
}
copy_to_user use access_ok () to check that user_buffer is in the current
proccess address space... The problem is that you always make what you need
to do and then you check that buffer is ok or not! why you don't first check
buffer and then make all what you need to do and at the end you write to the
buffer without checking? let say something like this..
int func(char *user_buffer) {
if (access_ok(buffer, n)) {
/* A lot of function stuff */
...
__copy_user(to, from, n);
return 0;
}
return -EFAULT;
}
This idea wont work if you don't have n (the size) to be writed to the
user_buffer, but I think will increase performance.. because sometime what I
call /* A lot of function stuff */ is disable interrupts (asm ("cli");) and
isn't so funny (I think) to disable interrupts when you know that it will
return an Error Code at the end...
an example of what I'm talking about take a look at kernel/info.c
in this implementation of sys_sysinfo() you first do all the things you need
to do (disable interrupts.. etc) but at the end if 'info' is out of the
process address space it return a segmentation fault why don't first check
info with access_ok() and then continue with the syscall or driver or what
else...
Thanks.
Eliel Sardanons
reply other threads:[~2001-03-29 12:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=A0C675E9DC2CD411A5870040053AEBA0284141@MAINSERVER \
--to=eliel.sardanons@philips.edu.ar \
--cc=linux-kernel@vger.kernel.org \
/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®