Grant the root privilege to the application

1,357 views
Skip to first unread message

Sam

unread,
Apr 18, 2012, 2:18:43 AM4/18/12
to android-ndk
Hi Developers,

I have an application which consists of the native part and higher
layer.

Therefore, it needs to be granted the root privilege to run some
native functions.

As the article I post before, I added a piece of code taken from Bluez
Utils(hidd.c).

<code>
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
close(sk);
return -1;
}
</code>

The code has been built to be a .so by NDK.

Unfortunately, It keeps returning -1 and errno is 13 which means
Permission Denied.

Some experienced developers(Thank you here) mentioned about that the
error happens because this application doesnt have enough permission.

It "SHOULD NOT" be something like

Process process = Runtime.getRuntime().exec("su");

I think this means you possess a system permission but your
application doesnt.
(Let me know if I am wrong)

Is there any way to grant the app for having the root privilege?

Any reply/clue/hint will be highly appreciated.


Regards-



Sam

Tor Lillqvist

unread,
Apr 18, 2012, 4:40:28 AM4/18/12
to andro...@googlegroups.com

Therefore, it needs to be granted the root privilege to run some
native functions.

Therefore, it can't be a normal Android app.

I doubt this mailing list ("group") is intended for help how to break the security of Android.

Yes, I am aware that "rooting" Android devices is quite easy and popular, and presumably in no way illegal in most jurisdictions. Android is said to have lots of malware too, and an app piracy culture, I wonder if there is a causality here? ;) But this is not the place to discuss it, I think.

 --tml

I-Sheng Lin

unread,
Apr 18, 2012, 5:39:18 AM4/18/12
to andro...@googlegroups.com
Well, it depends on how you look at these kind of topics.

Either forum or mailing list should be the open place for developers to discuss any Android-related topic.

If this is a security problem, then we can give Android a hint or patch to improve it.

The phone has been rooted and CM installed. Developers will be able to create more featured applications without limitations.

That's why i mentioned which side you stand for these topics.

Thanks for the reply and it will be better for having your approach here. ; )

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/h1pu3tho2q4J.
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.



--
I-Sheng Lin


Tor Lillqvist

unread,
Apr 18, 2012, 5:45:45 AM4/18/12
to andro...@googlegroups.com


If this is a security problem, then we can give Android a hint or patch to improve it.

The phone has been rooted and CM installed.

Well, that is the security problem then, isn't it? You don't get my irony, do you?

Developers will be able to create more featured applications without limitations.

I guess that's one way to put it, yes. Android truly is the new Windows.

--tml

I-Sheng Lin

unread,
Apr 18, 2012, 6:56:24 AM4/18/12
to andro...@googlegroups.com

Thank you.

sent from my Galaxy Nexus

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-ndk/-/bqSsinu0fBEJ.

Carrie Best

unread,
Apr 18, 2012, 2:37:01 PM4/18/12
to andro...@googlegroups.com
I am having a very similar problem, my app is denied permission but only after the first boot from flashing the images.  After I reboot everything starts up fine, I have been trying to track this issue down but am not finding a lot of info about it.

p.s.  As far as this being the 'right' place to discuss 'jailbreaking or rooting phones', there are many different kinds of users who would need to know these kinds of things.  Who do you think is writing the custom images for device OEM's?  Someone somewhere HAS TO HAVE root privileges to add their code into the OS.

David Turner

unread,
Apr 18, 2012, 2:59:18 PM4/18/12
to andro...@googlegroups.com
On Wed, Apr 18, 2012 at 8:37 PM, Carrie Best <best....@gmail.com> wrote:
I am having a very similar problem, my app is denied permission but only after the first boot from flashing the images.  After I reboot everything starts up fine, I have been trying to track this issue down but am not finding a lot of info about it.

p.s.  As far as this being the 'right' place to discuss 'jailbreaking or rooting phones', there are many different kinds of users who would need to know these kinds of things.  Who do you think is writing the custom images for device OEM's?  Someone somewhere HAS TO HAVE root privileges to add their code into the OS.


Nope, this is not the right place to discuss this topic. android-ndk is only for people developing apps against the official Android native APIs.
Try xda-developers forum. They have plenty of knowledgeable people that should be able to help you.

Sam

unread,
Apr 18, 2012, 8:36:57 PM4/18/12
to android-ndk
Hi David,

If you are an admin for this mailing list and you think this topic is
inappropriate here.

Please remove it. Thanks.

On Apr 19, 2:59 am, David Turner <di...@android.com> wrote:

Sam

unread,
Apr 18, 2012, 8:42:47 PM4/18/12
to android-ndk
Hi Carrie,

Yea, the results seem to be different from different phones.
Thanks for the reply btw. I guess the root cause is that we did not
totally understand the mechanism of Android how to handle it.
: )

Raman Chalotra

unread,
Apr 19, 2012, 5:53:14 AM4/19/12
to android-ndk
Does not adding "INTERNET" Permission in Application Manifest file
help ?
-Raman

I-Sheng Lin

unread,
Apr 19, 2012, 9:27:00 AM4/19/12
to andro...@googlegroups.com
Na...I intend to interact with Bluetooth...

--
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.




--
I-Sheng Lin
+886-929-052-222
"Many things difficult to design prove easy to performance."-Samuel Johnson

karunakar reddy

unread,
Apr 19, 2012, 9:37:34 AM4/19/12
to andro...@googlegroups.com
myself facing the same issue.The Android app is not able to execute the ioctl to wifi driver.But with a native c test app every thing is working fine.Do android app need any special privileges to run ioctls??Any on help me out.. 

Sam

unread,
Apr 19, 2012, 9:45:33 AM4/19/12
to android-ndk
I guess yes. The app needs some special privilege(s) to interact with
system calls.


On Apr 19, 9:37 pm, karunakar reddy <karan.ti...@gmail.com> wrote:
> myself facing the same issue.The Android app is not able to execute the
> ioctl to wifi driver.But with a native c test app every thing is working
> fine.Do android app need any special privileges to run ioctls??Any on help
> me out..
>
>
>
>
>
>
>
> On Thu, Apr 19, 2012 at 6:57 PM, I-Sheng Lin <ckjboy2...@gmail.com> wrote:
> > Na...I intend to interact with Bluetooth...
>
> > *"Many things difficult to design prove easy to performance."-Samuel
> > Johnson
> > *

Chris Stratton

unread,
Apr 19, 2012, 3:13:09 PM4/19/12
to andro...@googlegroups.com
On Wednesday, April 18, 2012 5:45:45 AM UTC-4, Tor Lillqvist wrote:


If this is a security problem, then we can give Android a hint or patch to improve it.

The phone has been rooted and CM installed.

Well, that is the security problem then, isn't it? You don't get my irony, do you?

Actually, given the tendency of carriers to install malware on devices they sell, it's often viewed as a security solution. Though one which may inadvertently introduce a new set of problems (generally quickly corrected, sometimes with new problems in the corrections - such is the nature of ongoing development)

However, targeting its features is not really on topic for the ndk group.  As I said in response to a duplicate post on android-developers, the details have been covered many times on stack overflow.

Chris Stratton

unread,
Apr 19, 2012, 3:21:09 PM4/19/12
to andro...@googlegroups.com
On Thursday, April 19, 2012 9:37:34 AM UTC-4, karan wrote:
myself facing the same issue.The Android app is not able to execute the ioctl to wifi driver.But with a native c test app every thing is working fine.Do android app need any special privileges to run ioctls??Any on help me out.. 

Yes.  Privileges which is the official view of things should not be available to SDK/NDK apps.  (What's missing in official releases is a mechanism for "special" apps to extended the capability of the platform itself - that's a simplification for a general purpose device, but also a limitation for many users). 

Likely your stand alone test executable is being executed from the adb shell, where it runs either as root (on an emulator or unsecured device) or as shell (on a secured device), thus having the necessary permissions (ie, root can do anything, shell can do some things which normally can only be done by a live user interacting with the system apps but not by a 3rd party app).  Many unofficial android versions do give you the (controversial=effective but perhaps without sufficient controls) ability to launch an executable in this way from an android app, but doing so is beyond the scope of this group.  Notably, even with those mechanisms, it's only the stand alone helper executable - AND NOT THE REQUESTING APP - which gets to run as root. 

charles

unread,
May 4, 2012, 3:44:19 AM5/4/12
to andro...@googlegroups.com
Hi!

DISCLAIMER: This is not at all an intended use of either the NDK or SDK, is not guaranteed to work and the programs you run like this can be killed by Dalvik at any time. In other words, do not expect stability (or support from the mailing list) if you use this method.

(That said, it has always worked for me!)

Use the NDK toolchain to cross-compile your C program as a binary.

Write a simple shell script that executes this binary.

Write a C program that runs the script as root, for example:

system("su -c /data/data/com.example.app/bin/myscript")

Compile this program as a shared library and export the relevant function(s) through JNI. Then call the function in your Java application.

SuperUser.apk should prompt you to grant root permissions to your app when it runs the system() call as root.

xda-developers is probably a better place to ask about this kind of thing, but I don't think this is off topic to discuss NDK hacks on this mailing list.

Best,
Charles

Rant:
It would actually be nice if something like this could be officially supported. There are plenty of legitimate reasons to do this, and plenty of ways to spread malware without root.

The "security features" that keep users locked out from using/hacking the devices they own and the bloatware OEMs like to bundle in with Android is hardly better than malware (which can at least be uninstalled!)

I have root on my linux box, but no malware and haven't destroyed everything on my file system (yet). Why is it assumed that having root on phone leads to malware and total destruction?

Tor Lillqvist

unread,
May 4, 2012, 3:50:09 AM5/4/12
to andro...@googlegroups.com

I have root on my linux box,

But do you have root on your TV?

That is what one should compare to, other consumer electronics. And puh-lease, don't confuse "users" with "experienced software developers" like yourself. Also, if you want a phone or tablet with no OEM bloatware, well, there is one brand well known for not allowing such.
 
--tml

Reply all
Reply to author
Forward
0 new messages