Skip to content

Fix link-layer address enumeration on macOS - #131803

Open
wfurt wants to merge 2 commits into
dotnet:mainfrom
wfurt:fix-macos-link-layer-address
Open

Fix link-layer address enumeration on macOS#131803
wfurt wants to merge 2 commits into
dotnet:mainfrom
wfurt:fix-macos-link-layer-address

Conversation

@wfurt

@wfurt wfurt commented Aug 4, 2026

Copy link
Copy Markdown
Member

Fixes #125711

Summary

  • expand the native and managed link-layer address buffers from 8 to 12 bytes
  • clamp the copied address length to the reported source record and destination capacity
  • use the fixed sdl_data capacity on SunOS, where sockaddr_dl does not expose sdl_len
  • add native compile-time assertions for the interop buffer layout

The hardware-specific scenario requires a special link-layer adapter and was not reproduced locally. The bounds and layouts were validated through native compilation, the existing macOS interface enumeration tests, and specialist review.

Testing

  • ./build.sh libs.native
  • ./dotnet.sh build /t:test src/libraries/System.Net.NetworkInformation/tests/FunctionalTests/System.Net.NetworkInformation.Functional.Tests.csproj (246 passed)

Note

This pull request description was generated with GitHub Copilot.

Copilot AI review requested due to automatic review settings August 4, 2026 13:46
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Unix System.Native interface-address enumeration and its managed interop to safely handle link-layer (AF_LINK / sockaddr_dl) addresses that can exceed the previously assumed 8-byte buffer, particularly on macOS.

Changes:

  • Expand link-layer address storage in native PAL structs and managed interop structs from 8 to 12 bytes.
  • Clamp the link-layer address copy length to both the source record’s reported capacity and the destination buffer size (including a SunOS-specific path where sdl_len isn’t available).
  • Add native compile-time assertions to validate the interop struct layout assumptions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/native/libs/System.Native/pal_interfaceaddresses.h Expands native struct link-layer address buffers to 12 bytes.
src/native/libs/System.Native/pal_interfaceaddresses.c Adds length-clamping helper for AF_LINK and updates copies + adds layout assertions.
src/libraries/Common/src/Interop/Unix/System.Native/Interop.EnumerateInterfaceAddresses.cs Updates managed interop structs to match the new 12-byte native buffers.
Suppressed comments (1)

src/native/libs/System.Native/pal_interfaceaddresses.c:471

  • Same as above: LLADDR(sadl) is computed even when NumAddressBytes clamps to 0. Guarding the copy avoids forming a potentially out-of-bounds pointer for malformed/short records.
            memcpy_s(&nii->AddressBytes, sizeof_member(NetworkInterfaceInfo, AddressBytes), (uint8_t*)LLADDR(sadl), nii->NumAddressBytes);

Comment thread src/native/libs/System.Native/pal_interfaceaddresses.h Outdated
Comment thread src/native/libs/System.Native/pal_interfaceaddresses.c Outdated
Copilot AI review requested due to automatic review settings August 4, 2026 14:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

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.

[macOS] Potential bug in LinkLayerAddressInfo interop

3 participants