0
votes

I have native executable on device at /data/local/tmp and using java api to run the exe java.runtime.exec() method. However, I get permission denied error:13(stacktrace attached below.)

String runexec= "/data/local/tmp/test";
Process p = Runtime.getRuntime().exec(runexec);




Java.io.IOException: Cannot run program "/data/local/tmp/test": error=13, Permission denied
W/System.err:     at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
W/System.err:     at java.lang.Runtime.exec(Runtime.java:692)
W/System.err:     at java.lang.Runtime.exec(Runtime.java:525)
W/System.err:     at java.lang.Runtime.exec(Runtime.java:422)
W/System.err:     at android.view.View.performClick(View.java:6891)
W/System.err:     at android.widget.TextView.performClick(TextView.java:12651)
W/System.err:     at android.view.View$PerformClick.run(View.java:26083)
W/System.err:     at android.os.Handler.handleCallback(Handler.java:789)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:98)
W/System.err:     at android.os.Looper.loop(Looper.java:164)
W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6938)
W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
W/System.err:     at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
W/System.err: Caused by: java.io.IOException: error=13, Permission denied
W/System.err:     at java.lang.UNIXProcess.forkAndExec(Native Method)
W/System.err:     at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
W/System.err:     at java.lang.ProcessImpl.start(ProcessImpl.java:128)
W/System.err:     at java.lang.ProcessBuilder.start(Pro


Edit: test exe has a+x or say 777 permission and functions properly via adb shell however, fails when invoked with java.

1
You may have permissions on test, but do you have permissions on every other segment of your path?MarsAtomic
yes, I have verified folder and file permissions. The test works invoked with su -c ...user755
Verify that data, local and tmp are directories and that test is actually an exe (as opposed to a directory or some non-executable like a data file).MarsAtomic
yes, I can list the file but cannot execute it.user755
What OS are you using? I think it's clear now that the underlying problem is OS-related, as opposed to Java. This sounds like it's going to be something weird, like a file system mounted with noexec. I'm quickly moving out of my depth here, so I suggest trying unix.stackexchange.com. I assume when you used su you used root?MarsAtomic

1 Answers

0
votes

You are using Android OS. I had a similar problem on RHEL. The secret was that SELINUX just LOVES to prevent stuff like this.

Check the log file /var/log/messages and search it for your executable name. You may find something similar to this: "SELinux is preventing pool-2-thread-1 from execute access on the file <your_exec_here>"