ioctl permission denied

1,494 views
Skip to first unread message

talon

unread,
Nov 29, 2011, 2:40:45 AM11/29/11
to android-ndk
Hi All,

I have a C++ program which configures interfaces and adds or removes
routes, I implemented those calls through ioctl calls (SIOCADDRT,
SIOCSIFADDR).
I compiled the program as lib and run it from java. At beginning of
the C++ program i change user to root (my devices is rooted) and then
create thread for the main proc which creates some other threads.
When some thread tries to set interface or add/remove routes it
receives error 13 - permission denied - although it has root
permission.
I set permission in AndroidManifest.xml file.
How can i resolve the permission problem through the C++ code?????

10x

David Turner

unread,
Nov 29, 2011, 11:45:25 AM11/29/11
to andro...@googlegroups.com
How to you change your user to root exactly. What are your threads euid() and geuid()?


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Tal Alon

unread,
Nov 30, 2011, 4:17:09 AM11/30/11
to andro...@googlegroups.com
Hi,

first I solved the problem by compiling my C++ project as executable (include $(BUILD_EXECUTABLE)) instead of lib (include $(BUILD_SHARED_LIBRARY)) and run it from java after creating new root shell process.
code:
        java.lang.Process sh;
        sh = Runtime.getRuntime().exec("su -c sh");
OutputStream os = sh.getOutputStream(); 

String yourExe = "./executableFilePath"; 
        os.write((yourExe + "\n").getBytes("ASCII")); 

This is a new root process which has permissions for ioctl calls, i add interfaces and change the routing table.
At these solution the java program and the C++ don't have shared memory but they have to communicate via sockets (unix domain, datagram). 


second I changed to root by calling system("su"); at the beginning of C++ code before i create the main thread but it doesn't work the permission doesn't changed. 
If i run user process can i create thread that has root permission?

Dianne Hackborn

unread,
Nov 30, 2011, 3:27:34 PM11/30/11
to andro...@googlegroups.com
On stock Android apps can't run as root.
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Chris Stratton

unread,
Nov 30, 2011, 3:28:11 PM11/30/11
to andro...@googlegroups.com
On Wednesday, November 30, 2011 4:17:09 AM UTC-5, talon wrote:

second I changed to root by calling system("su"); at the beginning of C++ code before i create the main thread but it doesn't work the permission doesn't changed. 
If i run user process can i create thread that has root permission?

No, this won't work.  "su" is an executable program run by your process but it does not change the uid of your process, instead, it creates a new process with a root uid (if the installation permits it to). 

uid is per-process, not per thread.

So, basically, if you need to do something as root, you must use interprocess communication between the root helper process and your application process.


Reply all
Reply to author
Forward
0 new messages