0
votes

I'm trying to develop a new syscall for the linux kernel. This syscall will write info on the user buffer that is taken as argument, e.g.:

asmlinkage int new_syscall(..., char *buffer,...){...}

In user space this buffer is statically allocated as:

char buffer[10000];

There's a way (as sizeof() in the user level) to know the whole buffer size (10000 in this case)? I have tried strlen_user(buffer) but it returns me the length of the string that is currently into the buffer, so if the buffer is empty it returns 0.

1
No. Pass the size of the buffer to the system call.Michael Foukarakis
Ok! I'll try in this way! Thanks!!Pietro Luciani
I would also recommend defining char *buffer as char __user *buffer and use copy_From_userFred

1 Answers

0
votes

You can try passing structure which will contain the buffer pointer & the size of the buffer. But the same structure should also be defined in both user-space application & inside your system-call's code in kernel.

struct new_struct
{
   void *p;  //set this pointer to your buffer...
   int size;
};
//from user-application...

int main()
{
   ....
   struct new_struct req_kernel;
   your_system_call_function(...,(void *)&req_kernel,...);
}
........................................................................................
      //this is inside your kernel...
     your_system_call(...,char __user optval,...)
     {
            .....
            struct new_struct req;
            if (copy_from_user(&req, optval, sizeof(req)))

            return -EFAULT;
            //now you have the address or pointer & size of the buffer
            //which you want in kernel with struct req...
    }