Re: Passing kernel space data buffer where userspace is expected.

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

 



Hi Prasad

On Thu, Aug 7, 2008 at 8:50 AM, Prasad Joshi <prasadjoshi124@xxxxxxxxx> wrote:
> ssize_t my_write(struct file *filp, const char __user *buf, size_t len,
> loff_t *ppos)
> {
>     size_t ret;
>     char *data = kmalloc(sizeof(char)*len, GFP_KERNEL);
>
>     copy_from_user(data, buf, len);
>     encrypt_data(data, len);
>     ret = do_sync_write(filp, data, len, ppos);
>
>     kfree(data);
>     return ret;
> }
>
> After running the code and writing data to the file using echo "test" >
> /mnt_pt/file    I am getting bad address error
>
> Is it because do_sync_write() also expects buf pointer from the userspace?
> ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len,
> loff_t *ppos)
>
> But, the only thing do_sync_write should be concerned with whether it can
> access the data pointer or not. So, if the data pointer is valid and kernel
> is able to access the location why so worry about userspace pointer?

Either your suspicion is right, or the write isn't finished yet but
you already kfree()-ed the buffer.  The reason why I suspected that is
this line:

if (-EIOCBQUEUED == ret)
               ret = wait_on_sync_kiocb(&kiocb);

in do_sync_write(). Thus, what you further need is probably check the
return value and act accordingly.

I'm not really fs guy...so this is the best idea I can suggest   so far.

regards,

Mulyadi.

--
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