Skip to content
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

uuid1() fails if only 64-bit interface addresses are available #76683

Closed
anpetral-msft mannequin opened this issue Jan 6, 2018 · 13 comments
Closed

uuid1() fails if only 64-bit interface addresses are available #76683

anpetral-msft mannequin opened this issue Jan 6, 2018 · 13 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@anpetral-msft
Copy link
Mannequin

anpetral-msft mannequin commented Jan 6, 2018

BPO 32502
Nosy @warsaw, @benjaminp, @ned-deily, @yan12125, @bbayles, @anpetral-msft
PRs
  • bpo-32502: Discard 64-bit (and other invalid) hardware addresses #5254
  • [3.6] bpo-32502: Discard 64-bit (and other invalid) hardware addresses (GH-5254) #5290
  • [2.7] bpo-32502: Discard 64-bit (and other invalid) hardware addresses (GH-5254). #9125
  • 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:

    assignee = None
    closed_at = <Date 2018-01-24.13:27:37.868>
    created_at = <Date 2018-01-06.16:26:25.935>
    labels = ['3.7', 'library', 'type-crash']
    title = 'uuid1() fails if only 64-bit interface addresses are available'
    updated_at = <Date 2018-09-11.20:55:01.569>
    user = 'https://github.com/anpetral-msft'

    bugs.python.org fields:

    activity = <Date 2018-09-11.20:55:01.569>
    actor = 'benjamin.peterson'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-01-24.13:27:37.868>
    closer = 'barry'
    components = ['Library (Lib)']
    creation = <Date 2018-01-06.16:26:25.935>
    creator = 'anpetral'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32502
    keywords = ['patch']
    message_count = 13.0
    messages = ['309554', '309556', '309562', '309876', '309882', '309883', '309884', '309885', '310544', '310593', '324404', '324887', '325058']
    nosy_count = 6.0
    nosy_names = ['barry', 'benjamin.peterson', 'ned.deily', 'yan12125', 'bbayles', 'anpetral']
    pr_nums = ['5254', '5290', '9125']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue32502'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7']

    @anpetral-msft
    Copy link
    Mannequin Author

    anpetral-msft mannequin commented Jan 6, 2018

    uuid.py is getting a 64 bit hardware address for the loopback adapter in High Sierra, specifically in _ifconfig_getnode(). The function expects a 48 bit mac address, but is instead getting 64 bits back and converting it to an int value that is too long for the subsequent call in uuid.py. Apple must have moved to using EUI-64 for the loopback adapters.

    This is a sample output of the call to ifconfig that is being parsed:

    b'lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384\n'
    b'\toptions=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>\n'
    b'\tinet 127.0.0.1 netmask 0xff000000 \n'
    b'\tinet6 ::1 prefixlen 128 \n'
    b'\tlladdr 70:cd:60:ff:ab:cd:ef:12 \n'

    As you can see, the lladdr is longer than the usual 48 bit mac address but is nontheless returned for the node value, which then triggers

    ValueError('field 6 out of range (need a 48-bit value)')

    Full traceback:

    Traceback (most recent call last):
      File "/Users/andy/Desktop/test.py", line 3, in <module>
        str(uuid.uuid1())
      File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/uuid.py", line 607, in uuid1
        clock_seq_hi_variant, clock_seq_low, node), version=1)
      File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/uuid.py", line 168, in __init__
        raise ValueError('field 6 out of range (need a 48-bit value)')
    ValueError: field 6 out of range (need a 48-bit value)

    @anpetral-msft anpetral-msft mannequin added OS-mac type-crash A hard crash of the interpreter, possibly with a core dump labels Jan 6, 2018
    @warsaw
    Copy link
    Member

    warsaw commented Jan 6, 2018

    On Jan 6, 2018, at 11:26, Andres Petralli <report@bugs.python.org> wrote:
    > 
    > Traceback (most recent call last):
    >  File "/Users/andy/Desktop/test.py", line 3, in <module>
    >    str(uuid.uuid1())
    >  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/uuid.py", line 607, in uuid1
    >    clock_seq_hi_variant, clock_seq_low, node), version=1)
    >  File "/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/uuid.py", line 168, in __init__
    >    raise ValueError('field 6 out of range (need a 48-bit value)')
    > ValueError: field 6 out of range (need a 48-bit value)

    Interesting. This doesn’t fail for me on 10.13.2.

    @anpetral-msft
    Copy link
    Mannequin Author

    anpetral-msft mannequin commented Jan 6, 2018

    Here's the output from my system. This is a Mac Pro with a firewire port. Looks as if the address was picked up from fw0: actually, not lo0. Guess _find_mac just iterates until it hits a matching word for a hw address:

    lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
    inet 127.0.0.1 netmask 0xff000000
    inet6 ::1 prefixlen 128
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
    nd6 options=201<PERFORMNUD,DAD>
    gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
    stf0: flags=0<> mtu 1280
    UHC58: flags=0<> mtu 0
    XHC0: flags=0<> mtu 0
    UHC90: flags=0<> mtu 0
    UHC61: flags=0<> mtu 0
    UHC29: flags=0<> mtu 0
    UHC26: flags=0<> mtu 0
    UHC93: flags=0<> mtu 0
    EHC253: flags=0<> mtu 0
    EHC250: flags=0<> mtu 0
    fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
    lladdr 70:cd:60:ff:ab:cd:ef:12
    nd6 options=201<PERFORMNUD,DAD>
    media: autoselect <full-duplex>
    status: inactive

    @ned-deily
    Copy link
    Member

    Thanks for your additional analysis. So, assuming I understand it correctly, the problem here is that there can be hardware configurations where the only (or first?) hardware addresses available exceed 48 bits. I'm not sure what might be different for your system when running 10.13, assuming uuid1() used to work on earlier versions of macOS; perhaps another network interface with a smaller address was supported and configured? It seems like such configurations are pretty rare; there don't seem to be any prior bug reports on this and it would be unusual for Mac systems to only have a Firewire (non-loopback) network interface configured. In any case, such configurations presumably are not limited to Macs so I'm removing the macOS tag.

    @ned-deily ned-deily added stdlib Python modules in the Lib dir and removed OS-mac labels Jan 12, 2018
    @ned-deily ned-deily changed the title uuid1() broken on macos high sierra uuid1() fails if only 64-bit interface addresses are available Jan 12, 2018
    @anpetral-msft
    Copy link
    Mannequin Author

    anpetral-msft mannequin commented Jan 13, 2018

    This could be purely incidental to have shown up in 10.13, but yes, the problem comes from the fact that the first hardware ID in the list of devices happens to be an EUI-64 address with 64 bits now. This is the Firewire interface of my Mac Pro and maybe one of the few that actually uses a EUI-64 addresses, hence relatively rare. Maybe the order changed in 10.13 and this now happens to be the first entry returned from 'ifconfig' when previously maybe it was the Ethernet adapter, but given the lookup algorithm in uuid reads in line by line until it finds the first hw id, this is bound to fail on my machine. Clearly, I don't think uuid should make assumptions about order of interfaces that could have mixed EUI-48 and EUI-64 addresses.

    @ned-deily
    Copy link
    Member

    (As a workaround, you *might* be able to reorder the network interfaces in the System Preferences -> Network control panel.)

    @anpetral-msft
    Copy link
    Mannequin Author

    anpetral-msft mannequin commented Jan 13, 2018

    Moving doesn't work, but even removing the firewire adapter (which was unused on my system), doesn't remove it from the output of ifconfig.

    I did however work around the issue by just patching up uuid in a suboptimal manner (truncated the 64bit int to 48bit).

    A proper fix would probably need to discard EUI-64 addresses and look for EUI-48 specifically.

    @anpetral-msft
    Copy link
    Mannequin Author

    anpetral-msft mannequin commented Jan 13, 2018

    Re: rarity. There is at least one more person that ran into the same issue as seen in this report: Azure/azure-cli#5184

    @warsaw
    Copy link
    Member

    warsaw commented Jan 24, 2018

    New changeset 6b273f7 by Barry Warsaw (Bo Bayles) in branch 'master':
    bpo-32502: Discard 64-bit (and other invalid) hardware addresses (bpo-5254)
    6b273f7

    @warsaw
    Copy link
    Member

    warsaw commented Jan 24, 2018

    New changeset d69794f by Barry Warsaw (Bo Bayles) in branch '3.6':
    [3.6] bpo-32502: Discard 64-bit (and other invalid) hardware addresses (GH-5254) (bpo-5290)
    d69794f

    @warsaw warsaw added the 3.7 (EOL) end of life label Jan 24, 2018
    @warsaw warsaw closed this as completed Jan 24, 2018
    @yan12125
    Copy link
    Mannequin

    yan12125 mannequin commented Aug 31, 2018

    Could the fix be backported to 2.7 branch? Apparently on macOS 2.7 is also affected macports/macports-ports#2456

    @yan12125
    Copy link
    Mannequin

    yan12125 mannequin commented Sep 9, 2018

    I created the backport PR for 2.7 branch. Can anyone reopen this issue?

    @benjaminp
    Copy link
    Contributor

    New changeset d919c60 by Benjamin Peterson (Chih-Hsuan Yen) in branch '2.7':
    [2.7] bpo-32502: Discard 64-bit (and other invalid) hardware addresses (GH-9125)
    d919c60

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants