Hi, "Bartek Dolewski" <doles2@xxxxxxxxx> writes: > Hi all > Again I have problems with some kernel programming stuff. I decided to > make my first device driver more robust. So I wanted to add > access_ok() both in function read() and write() from fops. But when I > type: echo "Message" >> /dev/mydevice I get this error: > bash: echo: write error: Bad address > > Here my source code. First, implementation of read() function: > > static ssize_t FirstModule_Write(struct file *flip, const char > *buffer, size_t length, loff_t *off) > { > int i; > > if(!access_ok(VERIFY_READ, buffer, length)); > return -EFAULT; You return -EFAULT unconditionally ^. No matter what access_ok() says. It's funny that you already have it indented according to the actual code-flow :) > for(i=0; i < length && i < BUF_LEN; i++) > get_user(msg2[i],buffer+i); > msg2_Ptr = msg2; > printk(KERN_INFO "Your message from Userland is: %s",msg2); > > I think that I have to verify reading mode because I`ll get some data > from userspace buffer. Second argument is of course address of this > buffer and last one ... that`s right, I don`t know how to interpret > this argument. It is some length of memory block. There is the snippet > from #include <asm/uaccess.h>: > * access_ok: - Checks if a user space pointer is valid > * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE. Note that > * %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe > * to write to a block, it is always safe to read from it. > * @addr: User space pointer to start of block to check > * @size: Size of block to check > Size of what block ? Size of address of this buffer or WHOLE buffer ? The memory region that spans from addr to addr+size. So in your case from buffer[0] to buffer[length - 1]. The call you have should be correct if I didn't miss something. Hannes -- To unsubscribe from this list: send an email with "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please read the FAQ at http://kernelnewbies.org/FAQ