Re: buffer passed in proc_read not from userspace?

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

 



On Fri, Feb 27, 2009 at 9:54 PM, Matthias Kaehlcke
<matthias@xxxxxxxxxxxx> wrote:
> El Fri, Feb 27, 2009 at 07:38:59PM +0530 Sabin ha dit:
>
>> I saw the following code:
>> static int uart_read_proc(char *page, char **start, off_t off,
>>                           int count, int *eof, void *data)
>> {
>>         struct tty_driver *ttydrv = data;
>>         struct uart_driver *drv = ttydrv->driver_state;
>>         int i, len = 0, l;
>>         off_t begin = 0;
>>
>>         len += sprintf(page, "serinfo:1.0 driver%s%s revision:%s\n",
>>                         "", "", "");
>>
>> I dont understand why sprintf is used and not copy_to_user?
>> When we write a module/driver we treat both read and write buffer as
>> coming from userspace and hence use put_user/get_user or
>> copy_from_user/copy_to_user.
>> Anybody has any idea why proc read is handled differently?
>
> good observation!
>
> the read_proc function of an proc entry is called from
> proc_file_read(), which passes it a non-userspace
> buffer. proc_file_read() is in charge of copying the data from this
> buffer to the buffer provided by userspace:
>
> http://lxr.linux.no/linux+v2.6.28/fs/proc/generic.c#L41
>
>
> write_proc on the other receives a user space buffer from
> proc_file_write() and is therefore required to use copy_from_user() or
> get_user():
>
> http://lxr.linux.no/linux+v2.6.28/fs/proc/generic.c#L187

ufff, late reply again. bottom line is, eventually it will call
copy_{to,from}_user.

regarding sprintf, it's printing the string to the target address (in
this case *page) including the number/string formatted with format
string.

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