Skip to content

gh-132710: only use stable _uuid.generate_time_safe() to deduce MAC address #132901

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Apr 25, 2025

@picnixz
Copy link
Member Author

picnixz commented Apr 25, 2025

cc @zanieb

@picnixz picnixz force-pushed the fix/uuid/mac-address-libuuid-132710 branch 2 times, most recently from 2d398c9 to 99bdd52 Compare April 25, 2025 08:02
@picnixz picnixz force-pushed the fix/uuid/mac-address-libuuid-132710 branch from 99bdd52 to ee71d62 Compare April 25, 2025 08:03
@picnixz
Copy link
Member Author

picnixz commented Apr 25, 2025

@zanieb Does it actually solve your issue? because my system also appears to be unable to get the MAC address... but I was offline (I work offline during the week in general) and I didn't check when I'm online.

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

It's kind of hard to test because I haven't added support for the latest 3.14 in python-build-standalone and the patch doesn't apply cleanly to 3.13.

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

Okay, the patch does apply cleanly to the previous 3.14 alpha so I can test this. On macOS, it does resolve the problem. I did not test Linux.

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

I tested a Linux build at astral-sh/python-build-standalone#595 (comment) and it didn't seem to work.

@picnixz
Copy link
Member Author

picnixz commented Apr 25, 2025

Hum. It's very strange. Did I mess the configure script? what's the value of HAVE_UUID_GENERATE_TIME_SAFE_STABLE_MAC?

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

Looking at the logs... "HAVE_UUID_GENERATE_TIME_SAFE_STABLE_MAC": "0",

@picnixz
Copy link
Member Author

picnixz commented Apr 25, 2025

... so it's not _unix_node() that is being called?

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

The builds are attached there if you want to hop into a debugger.

Briefly... yeah it looks like it's called and we try each getter until we reach the random one:

(Pdb) getter
<function _unix_getnode at 0xffffb77b74d0>
(Pdb) s
--Call--
> /python/install/lib/python3.14/uuid.py(634)_unix_getnode()
-> def _unix_getnode():
(Pdb) n
> /python/install/lib/python3.14/uuid.py(636)_unix_getnode()
-> if _generate_time_safe and _has_stable_extractable_node:
(Pdb) n
--Return--
> /python/install/lib/python3.14/uuid.py(636)_unix_getnode()->None
-> if _generate_time_safe and _has_stable_extractable_node:
(Pdb) n
> /python/install/lib/python3.14/uuid.py(706)getnode()
-> if (_node is not None) and (0 <= _node < (1 << 48)):
(Pdb) l
701  	   for getter in _GETTERS + [_random_getnode]:
702  	       try:
703  	           _node = getter()
704  	       except:
705  	           continue
706  ->	       if (_node is not None) and (0 <= _node < (1 << 48)):
707  	           return _node
708  	   assert False, '_random_getnode() returned invalid value: {}'.format(_node)
709  	
710  	
711  	_last_timestamp = None
(Pdb) n
> /python/install/lib/python3.14/uuid.py(701)getnode()
-> for getter in _GETTERS + [_random_getnode]:
(Pdb) n
> /python/install/lib/python3.14/uuid.py(702)getnode()
-> try:
(Pdb) getter
<function _ip_getnode at 0xffffb77b71d0>
(Pdb) n
> /python/install/lib/python3.14/uuid.py(703)getnode()
-> _node = getter()
(Pdb) n
> /python/install/lib/python3.14/uuid.py(706)getnode()
-> if (_node is not None) and (0 <= _node < (1 << 48)):
(Pdb) _node
(Pdb) n
> /python/install/lib/python3.14/uuid.py(701)getnode()
-> for getter in _GETTERS + [_random_getnode]:
(Pdb) n
> /python/install/lib/python3.14/uuid.py(702)getnode()
-> try:
(Pdb) getter
<function _ifconfig_getnode at 0xffffb77b7110>
(Pdb) n
> /python/install/lib/python3.14/uuid.py(703)getnode()
-> _node = getter()
(Pdb) n
> /python/install/lib/python3.14/uuid.py(706)getnode()
-> if (_node is not None) and (0 <= _node < (1 << 48)):
(Pdb) _node
(Pdb) n
> /python/install/lib/python3.14/uuid.py(701)getnode()
-> for getter in _GETTERS + [_random_getnode]:
(Pdb) n
> /python/install/lib/python3.14/uuid.py(702)getnode()
-> try:
(Pdb) getter
<function _random_getnode at 0xffffb77b7650>
(Pdb) n
> /python/install/lib/python3.14/uuid.py(703)getnode()
-> _node = getter()
(Pdb) n
> /python/install/lib/python3.14/uuid.py(706)getnode()
-> if (_node is not None) and (0 <= _node < (1 << 48)):
(Pdb) _node
23292345252342

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

So, the patch worked but it turns out generate_time_safe is necessary for MAC address retrieval on (at least) ubuntu:latest?

@picnixz
Copy link
Member Author

picnixz commented Apr 25, 2025

Maybe we should add all possible getnode fallbacks based on ifconfig, ip, arp, netstat, lanscan?

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

We did try _ip_getnode and _ifconfig_getnode as expected there. I didn't look into why those might fail. It does feel like a bit of a separate concern than this patch.

@picnixz
Copy link
Member Author

picnixz commented Apr 25, 2025

I suggest adding a print in the except: continue as well just in case and also print the output of the invoked command to see whether we need to upgrade how the output is being parsed.

@zanieb
Copy link
Contributor

zanieb commented Apr 26, 2025

Those commands are just not installed by default in the ubuntu image. If you apt-get install net-tools, the getnode result is static.

@picnixz
Copy link
Member Author

picnixz commented Apr 26, 2025

Ha! so that's why. Let's also fix this by adding them as a dependency then

@picnixz picnixz added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 26, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @picnixz for commit 16200ae 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F132901%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 26, 2025
@picnixz picnixz added the needs backport to 3.13 bugs and security fixes label Apr 26, 2025
@picnixz
Copy link
Member Author

picnixz commented Apr 26, 2025

Ok the refleaks were fixed in #132989.

@picnixz picnixz requested a review from hugovk April 28, 2025 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants