<div dir="ltr"><div><div><div><div><div><div><div><div><div><div><div>Hi,<br></div>Thanks Valdis for your nice explanation. After practising i got another doubt <br></div>if read from my driver as below<br></div><br></div>cat /dev/myDev<br><br></div>for this how many times read function will call because some times it is executing only once but some times it is executing infinite times.<br></div>Like for write also <br></div>echo "hello" > /dev/myDev<br></div>for that particular call it is executing 1 or 2 times.<br></div>So can one please clarify my doubts<br></div>Thanks & Regards<br></div>Prasad<br></div><div class="gmail_extra"><br><div class="gmail_quote">On 2 January 2015 at 21:32, <span dir="ltr"><<a href="mailto:Valdis.Kletnieks@vt.edu" target="_blank">Valdis.Kletnieks@vt.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Fri, 02 Jan 2015 07:50:55 +0530, me storage said:<br>
<br>
> Can any one please tell me difference between kernal space & user space in<br>
> code perspective<br>
<br>
</span>Two biggies:<br>
<br>
1) Kernel space pages are usually nailed down and not paging in and out,<br>
this is *not* true for userspace pages (so special tap-dancing in<br>
copy_(to/from)_user() is needed to make sure no page faults happen).<br>
<br>
2) Data inside the kernel can usually be trusted from a security standpoint.<br>
Data in userspace *MUST NOT* be trusted. Also, beware of TOCTOU (time of<br>
check / time of use) bugs - that's why we should copy the user-supplied data<br>
to an internal buffer *first*, and then validity-check the buffer - if we check<br>
the value in userspace and then later copy it, there's a race condition where<br>
the userspace value can be changed after the check but before the copy.<br>
<br>
Also, keep in mind that a userspace pointer needs to be translated before<br>
using it to dereference data from kernel space....<br>
</blockquote></div><br></div>