title: How does the Linux kernel know how many bytes it should read from system call path arguments?
body: <p>I searched in google I found that Linux kernel uses a struct for variables.</p>
  
  <pre><code>#define EMBEDDED_LEVELS 2
  struct nameidata {
      struct path path;
      struct qstr last;
      struct path root;
      struct inode    *inode; /* path.dentry.d_inode */
      unsigned int    flags;
      unsigned    seq, m_seq;
      int     last_type;
      unsigned    depth;
      int     total_link_count;
      struct saved {
          struct path link;
          struct delayed_call done;
          const char *name;
          unsigned seq;
      } *stack, internal[EMBEDDED_LEVELS];
      struct filename *name;
      struct nameidata *saved;
      struct inode    *link_inode;
      unsigned    root_seq;
      int     dfd;
  } __randomize_layout;
  </code></pre>
  
  <p>for example for <code>execve</code> systeml call (found here <a href="https://elixir.bootlin.com/linux/latest/source/fs/exec.c" rel="nofollow noreferrer">https://elixir.bootlin.com/linux/latest/source/fs/exec.c</a>) <br/>
  this function will pass the filename pointer to another function as a <strong>pathName</strong> and set the <strong>nameidata</strong> struct name to this <strong>pathName</strong></p>
  
  <pre><code>static int __do_execve_file(int fd, struct filename *filename,
                  struct user_arg_ptr argv,
                  struct user_arg_ptr envp,
                  int flags, struct file *file)
  </code></pre>
  
  <p>my question here is how is it calculating the length of the parameter passed to this function from stack (for example <code>"/bin/sh"</code>)?</p>
  
  <p>(Editor's note: the <code>const char *pathname</code> arg to <a href="http://man7.org/linux/man-pages/man2/execve.2.html" rel="nofollow noreferrer"><code>execve(2)</code></a> doesn't <em>have</em> to point to stack memory.  I think this question is assuming the shellcode use-case where you do construct a path on the user-space stack and pass a pointer to that.)</p>
  
  <p>(I am learning assembly and I'm stuck in parameter passing section to system calls)</p>