3

I want to communicate between my Android device and my Linux box over IP through the USB network interface mode.

I have connected my Android device to my Linux box with and put the Android device into network interface mode via some Java reflection hackery. (I'm not using the standard tethering setting on Android because I want to use my Linux box as the gateway and not the other way round). I used ip addr add to add an IP address on both ends (Linux box and Android device) and then added a route with ip routevia my Linux box for internet access. I have also enabled IPv4 forwarding on the Linux box side, as well as enabling all of the necessary iptables rules.

My problem is this: only root can communicate over the interface. For example, with my Linux box at 10.42.0.1 and the Android device at 10.42.0.2 across the USB network interface, running ping 10.42.0.1 or ping 8.8.8.8 on the Android device without running from an su shell will not work. Running the exact same commands as root functions perfectly. The same commands over the WiFi interface on the Android side run fine without root.

I am assuming this is some new security feature implemented in Android 5.0 / 5.1, as it worked fine in KitKat. I am posting this here because I believe the problem is due to something which has been switched on in the kernel or something else not specific to Android. Since I don't really have much experience in networking, I was hoping somebody could tell me what I need to do to alleviate the issue.

3
  • 4
    I'm voting to close this question as off-topic because it's about Android, not about Linux. Although Android is based on the Linux kernel and uses the same basic security mechanisms as Linux, they are configured differently, and this configuration is what would explain the observed behavior. Aug 18 '15 at 22:32
  • Ask on Android Enthusiasts. Be sure to mention what device model you're using, and if applicable what alternate ROM you installed. One possible explanation is SEAndroid, whose scope keeps expanding with each Android version. Aug 18 '15 at 22:34
  • Alright @Gilles, I 'll do that.
    – jackos2500
    Aug 18 '15 at 22:42
0

Do other network functions work?  Try to telnet from one machine to the other.  If you can successfully connect as root, and not as non-root, you have a problem.  Even if you get "Connection refused" (or something similar) as root and "Permission denied" (or something similar) as non-root, you have a problem.

TL;DR

If other network functions work as non-root, you probably don't really have a problem.  The ping program uses the ICMP protocol, whose use is restricted to root.  Therefore, the ping program is usually installed setuid to root.  Do

ls -ld $(which root)

If it's not owned by root and setuid (---s--x--x at least), make it so by executing

chown root path_to_ping
chmod 4755 path_to_ping

as root.

1
  • I should have mentioned this in my question: I came across this issue with ping before, but solved it by adding the user in question to a certain group which I cannot recall the name of at the minute! To answer your question, I have tried using telnet as well as netcat and ssh among other things on both ends but to no avail. (telnet just hangs on "Trying 10.42.0.2") Binding sockets as non-root through something like netcat -l doesn't work either. Running the same as root or over WiFi works fine.
    – jackos2500
    Aug 18 '15 at 23:39

Not the answer you're looking for? Browse other questions tagged or ask your own question.