LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 09-10-2012, 02:00 PM   #1
wcrandthor
LQ Newbie
 
Registered: Aug 2012
Distribution: OpenSUSE 12.1
Posts: 9

Rep: Reputation: Disabled
Question What is the point of using the linux macro access_ok()


I've been doing some research and I'm a little confused about this macro. Hopefully someone can give me some guidance. I have some ioctl code (which I've inharented, not written) and the first thing it does if check if access_ok() before moving on to copying data over from user space:

switch(cmd) {
case COMMAND:
if(! access_ok(VERIFY_READ, (void *)arg, sizeof(Message_par_t)))
return(retval);
if(! access_ok(VERIFY_WRITE, (void *)arg, sizeof(Message_par_t)))
return(retval);

argp = &Command;
__lddk_copy_from_user( (void *) argp,(Command_par_t *) arg, sizeof(Command_par_t));

So the code works just fine, but I'm not sure it's needed. The first question comes from this description of access_ok's return:

"The function returns non-zero if the region is likely accessible (though access may still result in -EFAULT). This function simply checks that the address is likely in user space, not in the kernel."

So this means that it really does nothing more then make sure the pointer we're checking against is probably initialized in user space? Since we know that we couldn't come into thsi function other than a user space call, and it couldn't happen unless we opened a valid file descriptor to this device, is this really needed? Is it really any safer then just making sure we didn't get a NULL pointer?

Second question comes from this description:

"The type argument can be specified as VERIFY_READ or VERIFY_WRITE. The VERIFY_WRITE symbolic also identifies whether the memory region is readable as well as writable."

Does this mean the first check in my code is redundant? If we're going to check for a writable area we get readable as a free-be?
 
Old 09-10-2012, 02:29 PM   #2
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,402

Rep: Reputation: 1131Reputation: 1131Reputation: 1131Reputation: 1131Reputation: 1131Reputation: 1131Reputation: 1131Reputation: 1131Reputation: 1131
Nope ... it's designed to guard against invalid addresses being provided by the caller... perhaps with nefarious intentions.
 
Old 09-10-2012, 02:33 PM   #3
wcrandthor
LQ Newbie
 
Registered: Aug 2012
Distribution: OpenSUSE 12.1
Posts: 9

Original Poster
Rep: Reputation: Disabled
OK, but is this an accurate statement:
"The type argument can be specified as VERIFY_READ or VERIFY_WRITE. The VERIFY_WRITE symbolic also identifies whether the memory region is readable as well as writable"

Meaning that if I'm going to do an access_ok(WRITE) check I don't need to also preform an access_ok(READ)check?
 
  


Reply

Tags
ioctl, kernel


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro software for Linux? nyheat Linux - Software 4 03-18-2008 11:59 AM
#defining a macro inside a macro? saravkrish Programming 1 05-24-2005 09:48 PM
Is there a detailed point by point comparison on Linux to Windows? Paul Parr Linux - General 4 04-26-2003 02:35 AM


All times are GMT -5. The time now is 11:32 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration