Skip to content

fix(net): preserve IPv6 UDP socket family in name queries - #2307

Merged
fslongjin merged 1 commit into
DragonOS-Community:masterfrom
fslongjin:codex/fix-udp-dual-stack-name-abi
Sep 21, 2026
Merged

fslongjin merged 1 commit into
DragonOS-Community:masterfrom
fslongjin:codex/fix-udp-dual-stack-name-abi

Conversation

@fslongjin

Copy link
Copy Markdown
Member

Summary

Fix IPv6 UDP getsockname() and getpeername() returning an IPv4 sockaddr
after a successful connection to an IPv4 destination.

This Linux ABI mismatch caused glibc's IPv4-mapped address assertion during
getaddrinfo() result sorting, aborting curl before it could connect to npm
registry. The issue also reproduces without DNS or external networking using
getaddrinfo(NULL, "443", ...) with AF_UNSPEC and SOCK_STREAM hints.

Implementation

  • Keep normalized IPv4 endpoints inside UDP for routing and receive matching.
  • Convert only name-query output copies to IPv4-mapped IPv6 for IPv6 sockets.
  • Share the conversion between local and peer queries through one private helper.
  • Preserve IPv4/native IPv6 behavior, ports, existing errors and generic short-buffer copyout.

The kernel change adds no fields, locks, allocations or application-specific
behavior. Semantics were checked against Linux 6.6.139's IPv6 datagram connect
and inet6_getname() implementations.

Regression coverage

Seven tests extend the existing UDP IPv6 dunitest suite:

  • IPv4 and mapped-IPv6 destination inputs, full local/peer address assertions
  • Native IPv6 → AF_UNSPEC disconnect → IPv4 socket reuse
  • Explicit wildcard bind with local-port preservation
  • Unbound/ENOTCONN and unchanged IPv4 name representation
  • Zero and truncated output buffers with sentinel protection
  • Isolated getaddrinfo(NULL) reproducer

Validation

  • make kernel
  • make fmt FMT_CHECK=--check (including clippy)
  • git diff --check
  • Linux host: seven new cases repeated ten times, 70/70
  • DragonOS x86_64 QEMU/KVM, 2 vCPU / 2 GiB:
    • UDP IPv6 complete suite: 20/20
    • UDP device-binding complete suite: 8/8
    • Same socket probe now returns AF_INET6, 28 bytes and mapped addresses
    • Same getaddrinfo(NULL) probe: exit 134 → 0
    • Original npm registry curl request: HTTP 200, exit 0, both with and
      without tracing; no -4 and no disabled TLS verification
  • Independent plan review plus security/concurrency, logic/correctness and
    system/performance reviews completed with no outstanding findings.

Scope

This fixes UDP name-query serialization, not complete IPv6 support. Existing
V6ONLY and unrelated syscall validation gaps are unchanged. Full gVisor,
non-x86_64 runtime suites and end-to-end model generation were not tested.

IPv6 UDP sockets normalize IPv4 and IPv4-mapped destinations to IPv4 internally. Returning those endpoints directly from getsockname/getpeername exposed an AF_INET sockaddr on an AF_INET6 socket, violating Linux's dual-stack ABI and triggering glibc's address-sorting assertion.

Add one private UDP name-query conversion shared by the local and peer accessors. Map IPv4 addresses back to IPv4-mapped IPv6 only for IPv6 sockets, leaving routing, receive matching, port selection and generic sockaddr copyout unchanged. No additional state, allocation or locking is introduced.

Extend the existing dunitest suite with seven cases covering both destination formats, address-family reuse after disconnect, explicit wildcard binding, unbound and IPv4 behavior, truncated name buffers and the isolated getaddrinfo(NULL) reproducer.

Validation: make kernel; make fmt FMT_CHECK=--check; seven new Linux cases repeated ten times; DragonOS QEMU UDP IPv6 suite 20/20 and device-binding suite 8/8. The original socket and getaddrinfo probes now pass. The original npm registry curl request returns HTTP 200 and exit 0 with and without tracing, without forcing IPv4 or disabling TLS verification. Independent plan review and three-role implementation review found no outstanding defects.
Signed-off-by: longjin <longjin@dragonos.org>
@github-actions github-actions Bot added the Bug fix A bug is fixed in this pull request label Sep 21, 2026
@fslongjin

Copy link
Copy Markdown
Member Author

@codex review

@fslongjin
fslongjin merged commit b612271 into DragonOS-Community:master Sep 21, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug fix A bug is fixed in this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant