fix(libc): build getifaddrs netmasks from the address family on macOS hosts #9619
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9619"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T04:41:16Z.
What
guest_interfacesfails on macOS hosts at its netmask check. macOS'sgetifaddrsreturns IPv4 netmasks the way the routing socket stores them: cut down to their significant bytes, sosa_lenis 5 to 8 instead of 16, and on some entriessa_familyis 0. On my machinelo0's second IPv4 netmask is05 00 00 00 ffanden0's is07 02 00 00 ff ff ff, printed by a small probe that calls the host'sgetifaddrs.HostEntriesconverted the netmask withGuestAddress, which picks the layout from the netmask's own family. A family of 0 took the IPv6 branch, so the guest got a 28-byte IPv6 netmask next to an IPv4 address, read fromsin6_addrpast the 5 bytes the host returned. With family 2 the four address bytes were still read pastsa_len.The netmask now goes through
GuestNetmask: the layout comes from the address's family, and on macOS only thesa_lenbytes the host returned are copied, with the rest of the mask left zero. Linux returns complete netmasks of the address's family, so the result there is the same as before. Windows builds its masks from prefix lengths and doesn't reach this code.Tested
mainalone, so this ran on @mugurc'sci/macos-series-2at53db0badbwith #7524, the code of #7937 and the libSceSsl change of #7332, the set @tkcm01 lists on #1.guest_interfaceswithout this change aborts atGuestInterfaces.cpp:262(netmask[0] == address[0] && netmask[1] == address[1], found with lldb); with it, it passes.guest_interfacespasses.check_conventions.pypasses.pr_overlap.pyreports no conflicting lines; #6879 shares the file but conflicts withmain, and it doesn't touch the netmask code.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T09:25:55Z.
Review: CHANGES_REQUESTED
The
GuestNetmaskhelper chooses the output layout from the address family, initializes the mask storage to zero, and copies only the availablesa_lenpayload bytes on macOS. That avoids treatingsa_family == 0as IPv6 and avoids reading beyond a short IPv4 mask. Exact-head conventions andgit diff --checkpass. The reported macOS integration-tree red/green and Linuxguest_interfacespass are useful; current hosted product jobs are skipped, and I did not rerun runtime tests locally. The PR is generic (Unblocks: none).I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T11:31:05Z.
On the #5239 direction: this came from running the suite on the macOS port tree discussed on #1, where
guest_interfacesfails without it, not from a title. I am fine holding it until the queue drops or a maintainer says otherwise. If the preference is to fold it into #8658 instead, say so and I will close this in favour of that.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T13:12:09Z.
Review: DISMISSED
I withdraw the earlier #5239 intake-hold objection. I rechecked exact head
b2cfd1d3fe74aa318fb36eaca952f210f783af8cagainst current main3ca07d086d5f44fbe3c00370e7f03953ab46ca1b: whitespace and conventions pass, andInterfaces.cpppasses GCC 12.2 C++20 syntax checking with the existing missing-field-initializer warning suppressed. A three-way merge with current main is clean. The macOS integration-tree red/green and Linuxguest_interfacespass are author-reported; the hosted relinker/register-context/write-watch matrices pass, while full Linux/Windows product jobs are skipped. I did not run the platform runtime tests locally.The branch base is
17f533556272e5f6833ed730172f12308eee08d2, behind current main. The repository requires branches to be kept up to date with main. Please rebase/update and refresh the focusedguest_interfacesresults on the resulting head. The overlap scanner also cannot compare #6879 because that PR conflicts with main; inspect that shared file manually as part of the refreshed overlap check. I reviewed #8658'sInterfaces.cpppatch too: it changes macOS link-layer handling in separate hunks, and a direct merge of the two PR heads is clean. This request is for current-main and refreshed-overlap validation only, not the obsolete intake hold.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T13:31:11Z.
Rebased onto current
main(8b3e39832a): head45f4739c8d, same diff.check_conventions.pypasses on it.Refreshed results on this head:
guest_interfacepasses 3 of 3 on the macOS integration tree (the sameci/macos-series-2tree as in the description, which carries exactly thisInterfaces.cpp), and a hosted Linux run ofguest_interfacesis at https://github.com/rooklz/AnyPS5/actions/runs/39787382912 (in progress as I write; I'll note the result).#6879 by hand: its
Interfaces.cpphunks add link-layer handling on lines 160 to 182 and 253 to 307 ofmain, and one of them ends with an#endifthree lines above theEntryconstruction this PR changes. The two don't touch the same line, so whichever lands second gets at most a textual conflict in that hunk, resolved by keeping both; neither changes what the other does. #8658'sInterfaces.cpphunks are separate too, as you found.Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-22T13:57:40Z.
The hosted Linux run on head
45f4739c8dfinished:guest_interfacespasses (https://github.com/rooklz/AnyPS5/actions/runs/39787382912, Ubuntu 24.04, GCC, Release).Imported from boykopovar/AnyPS5. Originally posted by maximilianfv on 2026-10-25T15:09:51Z.
Review: COMMENTED
The netmask handling reads correct and matches FreeBSD, but this Mac doesn't show the bug, so I can't confirm the fix here. Comment, not approval; the notes below are non-blocking.
Tested on Apple M1 Pro, macOS 27.0.1 (x86_64 build under Rosetta 2)
Applied at
45f4739c8dto mugurc's macOS series (27e968974) merged withmainat2742004ed2, with other open macOS fixes, then toggled only this PR. 3 runs per side.guest_interfacesOn this host,
getifaddrsalready returns IPv4 netmasks withsa_family2 and zero bytes aftersa_len. A native probe printslo0 05 02 00 00 ff | 00 00 00anden0 07 02 00 00 ff ff fc | 00, where|markssa_len. Your probe showed family 0 (05 00 00 00 ff), so the old code's read pastsa_lenhappens to produce the right mask here, and the test passes both ways. The A/B therefore neither confirms nor contradicts the fix on this machine.Code
GuestNetmask(core/libs/prx/libc/src/Interfaces.cpp:92-105) does what FreeBSD 11.4'srtsock_fix_netmask(sys/net/rtsock.c:1008, used bysysctl_iflistat :1773) does: zero a buffer the size of the address, copy only thesa_lenbytes the host gave, then take the family from the address. A guest gets the console's layout, and Linux and Windows are unchanged.Notes
core/libs/tests/GuestInterfaces.cpp:260-264: for IPv4 the test checks bytes 0-3 and 8-15 of each netmask but never bytes 4-7, which hold the mask itself, so a copy at the wrong offset would still pass. A check that the IPv4 mask is a contiguous run of one-bits from the top, ornetmask[4] == 0xffon the loopback entry, would cover it.core/libs/prx/libc/src/Interfaces.cpp:99-101: for IPv6 the copy reads up to 26 bytes throughnetmask->sa_data, which is declaredchar[14]. That is fine at run time, but stricter-Warray-boundsor fortify builds may flag it.std::memcpy(&mask, netmask, length); mask.ss_family = static_cast<sa_family_t>(family);copies the same bytes from the start of the struct, drops theoffsetofguard, and has the same shape asrtsock_fix_netmask.Testedsection still describes #6879 as sharing the file and conflicting withmain; #6879 is closed now. The branch is also still based on8b3e39832a, from before #8279 guarded the Linux-only headers in this file, so the head doesn't build on macOS by itself, although the merge withmainis clean. A rebase, as mentioned in the thread, would make the "Based on currentmain" box true again.AI-assisted: yes (Claude Code applied the PR, ran the test both ways, probed
getifaddrsnatively, read the code and wrote this review).