Re: sys_open fails with error 14

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

On Dec 6, 2007 11:48 AM, Sandeep K Sinha <sandeepksinha@xxxxxxxxx> wrote:
> Well, I am trying to write a kernel module which when inserted should
> created a file foo at any absolute location.
> This is a code snippet of the same. It returns with error No -14.
> This a part of the constructor code for the module. I am using 2.6.20 kernel.
>
>         char x1[64]="/home/ssinha/foo";
>         printk(KERN_INFO "Hello world \n");
>         return1 = sys_open(x1,O_CREAT | O_WRONLY | O_TRUNC,0);
>         printk(KERN_ALERT "Returned Value is : %d. \n",return1);
>
> Am I logically wrong somewhere ??
>
> Regards,
> Sandeep.

First, I would recommend looking up the error description for the
error code 14. This can be found in include/asm-generic/errno-base.h
and turns out to be EFAULT "Bad address". So presumably you passed a
"bad address" into the function. As far as I can see, the only address
you pass is the filename. I would now recommend to look up the
definition of the function sys_open(). This can be found in fs/open.c
around line 1066. There the filename parameter is qualified with
__user, meaning it expects an address that comes from userspace, not
the kernel space. And why will this function fail if you provide it
with a kernel address? It's rather simple; the kernel must not allow
userspace to pass kernel addresses in its system calls, otherwise the
user processes could access (read or write) kernel data!

I hope this helps.

Kind regards,
Vegard Nossum

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux