-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
uuid.getnode() should return the MAC address on Android #76380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Currently uuid.getnode() returns a random 48-bit number and so the UUIDs are not persistent across time. The reason is that on Android the 'ip link list' command fails. uuid._ip_getnode() should invoke the 'ip link' command instead. |
Over in the PR I suggested: Here's another thought: what if you just added another getter that calls ip link list and placed that after one that calls ip link. Wouldn't that accomplish both goals? Then if ip link fails, we fall back to the old behavior, so nothing changes. It's uglier, but it doesn't special case for the Android platform, and eventually we can decide to remove ip link list altogether. |
Why the 'ip link list' command fails on Android at first place? Does Android use its own independent implementation? Or its version is based on the fork of very old version of iproute2 that didn't supported the list command (if there was such version)? |
The result of various 'ip' commands on Android, the last 'ip link list' command is run as root and succeeds (did not think about trying that before): generic_x86_64:/data/local/tmp/python $ ip link list 1|generic_x86_64:/data/local/tmp/python $ ip link help 1|generic_x86_64:/data/local/tmp/python $ ip link generic_x86_64:/data/local/tmp/python # ip link list |
On Dec 5, 2017, at 16:28, Xavier de Gaye <report@bugs.python.org> wrote:
Well, that’s weird! |
What if "ip link list" was intentionally prohibited "for security reasons", and "ip link" works just due to oversight? Xavier, could you please inspect the sources of the ip command on Android? Is it the standard iproute2 with additional patches prohibiting the part of the functionality? |
Whatever the change made to fix this issue, it is not possible to add a test case for this change. So following the suggestion made by Barry in PR 4696, we can add (in another issue) a new keyword parameter to getnode() named 'methods' whose value may be None (the default, meaning try all the known methods) or a tuple containing a subset of the following methods ('unix', 'ifconfig', 'ip', 'arp', 'lanscan', 'netstat', 'random') that would raise an exception if the value cannot be obtained using one of the requested method tried in the requested order. This would also improve the documentation on the methods getnode() is using. Then if we decide to make the change for 'ip link' in the current issue, one can add a test case that would first test for the avaibility of the ip command and if the command exists would fail if getnode(methods=('ip',)) raises an exception. |
You may be right Serhiy. Those tests have been run on the emulator at API 24 (Android 7.0 Nougat, the first API version where SELinux is run in enforced mode) where 'ip link list' fails, but on my device (a Samsung API 21, Android 5.1 Lollipop) running the 'ip link list' (using the termux package installed from google PlayStore) the command is ok. The Android source of iproute2 can be:
The Android SELinux policies are at: Maybe we should just close this issue as 'wont fix' then. |
'adb logcat' is a tool that monitors many kind of events on Android. Both ip commands prints a SElinux record on logcat: Upon the successfull 'ip link' command, logcat prints: Upon the failed 'ip link' command, logcat prints: |
Oops, the second failed command is 'ip link list' of course. |
It is also possible that rather than an oversight in Android, it is a side effect of SELinux on the implementation of iproute2 if the 'ip link list' command does a little bit more than the 'ip link' command and if this 'little bit more' is prohibited by a SELinux policy. I guess this means diving into the source of iproute2 to confirm that :-( |
Attached ip_link.strace and ip_link_list.strace, the output of strace for the 'ip link' and 'ip link list' commands. At the end of the process, both commands create an PF_NETLINK socket to receive from the kernel link information through the NETLINK_ROUTE group. The sendto() function fails with EACCES for 'ip link list' and its SELinux avc record relates to this event (the netlink prefix used throughout the documentation [1] is 'nlmsg' and the resource denied in the avc record is 'nlmsg_write'). The SELinux avc record for 'ip link' relates to a failed attempt to open "/data/misc/net/group" (it does not exist). |
On Dec 6, 2017, at 02:06, Xavier de Gaye <report@bugs.python.org> wrote:
Even with say, exception raising mocks for the getters?
I am thinking about this slightly differently. What if getnode() accepted a 1 file changed, 4 insertions(+), 2 deletions(-) modified Lib/uuid.py _node = None -def getnode(): The first time this runs, it may launch a separate program, which could
@@ -677,7 +677,9 @@ def getnode():
for getter in getters + [_random_getnode]:
try:
_node = getter()
- except:
+ except Exception as error:
+ if handler is not None:
+ handler(getter, error)
continue
if _node is not None:
return _node
(Maybe we spell |
I would be okay with any of these resolutions:
How to handle exceptions in the getters should be addressed in a new issue. |
On archlinux it is easy to know precisely what patches are applied to iproute2 and how it is built (see https://git.archlinux.org/svntogit/packages.git/tree/trunk?h=packages/iproute2). The attached two files, archlinux-ip_link.strace and archlinux-ip_link_list.strace, contain the output of strace run on the commands 'ip link' and 'ip link list' on archlinux.
Conclusions:
I will update the PR to do only that change: s/ip link list/ip link/ |
LGTM, and thanks! |
Thanks Serhiy and Barry for your comments and reviews :-) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: