Re: userspace buffer in read/write system call

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

 



>The char * in the arguments of read is a user-space buffer pointer.

It isn't actually a pointer at all.  It's an address.  People often run 
into trouble like yours because they don't grasp that.  "char *" is an 
unfortunate choice of data type for this because it obscures that point 
and prevents the compiler from detecting errors.  Some kernel code uses 
"long" instead, which is a much better choice.  If Linux were like that, 
your code would have failed to compile rather than give you EFAULT (or 
worse) at run time.

Actually ISTR Linux did get in the past few years some kind of typing 
scheme for user space addresses -- but we don't see it here.  Does anyone 
know about that?

A pointer is something that points to a variable.  The usual 
implementations of C use memory to represent a variable and the address in 
some particular address space of that memory to represent a pointer.  A 
more sophisticated implementation might include address space information 
in the pointer and then you truly could have a "char *" argument to 
->read() and read into a user space buffer the same way you read into a 
kernel buffer.

--
Bryan Henderson                     IBM Almaden Research Center
San Jose CA                         Filesystems

-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux