title: app_process can't create file in /system - SEED Android Device Rooting Lab
body: <p>I've been doing the SEED Android Device Rooting Lab to understand a little bit more about Android rooting, and it has gone well so far.</p>
  
  <p>But I've encountered a problem when trying to execute code as root via switching the app_process program for one coded by me that simply writes a dummy file to the /system directory and executes the real app_process64.</p>
  
  <p>The problem that I'm encountering is that with this code, the dummy file is not being created. I have compiled this code with NDK:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  
  extern char** environ;
  
  int main(int argc, char** argv) {
      //Write the dummy file
      FILE* f = fopen("/system/dummy2", "w");
      if (f == NULL) {
          printf("Permission Denied.\n");
          exit(EXIT_FAILURE);
      }
      fclose(f);
      //Launch the original binary
      char* cmd = "/system/bin/app_process_original";
      execve(cmd, argv, environ);
      //execve() returns only if it fails
      return EXIT_FAILURE;
  }
  </code></pre>
  
  <p>I can't quite understand why it wouldn't work. I have the file structure as follows: Symlink with name app_process that points to this program, a symlink called app_process_original that points to the app_process64 which is the one that has to run.</p>
  
  <p>The system boots as per usual, but the file does not show up. I think that app_process is not running as root. The lab uses Android 7.1. If I execute the program under root once Android has started, the file appears, so it seems to be a permissions issue, but the lab is about acquiring root permissions through this program, so I'm really confused.</p>
  
  <p>Does anyone see what the problem is here? Is app_process not running as root?</p>
  
  <p>Thank you in advance.</p>