From 29706267219676b8beab0d05dc8cab5364789014 Mon Sep 17 00:00:00 2001 From: Kalmarv <59708937+Kalmarv@users.noreply.github.com> Date: Mon, 23 Nov 2026 20:52:22 -0500 Subject: [PATCH] XCL_NETWORK=0: IPv4-mapped loopback (::ffff:127.x.x.x) goes through A socket for both IPv6 and IPv4 names an IPv4 host by its mapped address, so a connection to 127.0.0.1 from one arrives at the hooks as ::ffff:127.0.0.1. Only ::1 counted as IPv6 loopback, and connect and sendto refused it (WSAENETUNREACH) although nothing leaves the machine. Titles make socket pairs on loopback, which is why loopback is let through at all. Test: only_loopback_goes_through takes the mapped form of 127.0.0.1 as loopback and that of 8.8.8.8 as not; the first fails on main. Co-Authored-By: Claude --- crates/xcl/src/hle/netoff.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crates/xcl/src/hle/netoff.rs b/crates/xcl/src/hle/netoff.rs index 8071b04c61..c2e03e29cf 100644 --- a/crates/xcl/src/hle/netoff.rs +++ b/crates/xcl/src/hle/netoff.rs @@ -89,7 +89,8 @@ fn note(what: &str) { } } -/// 127.0.0.0/8 or ::1 (sockaddr_in / sockaddr_in6) +/// 127.0.0.0/8 or ::1 (sockaddr_in / sockaddr_in6), or 127.0.0.0/8 as an IPv4-mapped address +/// (::ffff:127.x.x.x – how a socket for both IPv6 and IPv4 names an IPv4 host) unsafe fn loopback(name: *const u8, len: i32) -> bool { if name.is_null() || len < 8 { return false; @@ -98,7 +99,7 @@ unsafe fn loopback(name: *const u8, len: i32) -> bool { 2 => *name.add(4) == 127, 23 if len >= 24 => { let a = std::slice::from_raw_parts(name.add(8), 16); - a[..15].iter().all(|&b| b == 0) && a[15] == 1 + (a[..15].iter().all(|&b| b == 0) && a[15] == 1) || (a[..10].iter().all(|&b| b == 0) && a[10..12] == [0xff, 0xff] && a[12] == 127) } _ => false, } @@ -300,6 +301,14 @@ mod tests { assert!(loopback(v6.as_ptr(), 28)); v6[8] = 0x20; assert!(!loopback(v6.as_ptr(), 28)); + let mapped = |a: [u8; 4]| { + let mut m = [0u8; 28]; + m[0] = 23; + m[18..24].copy_from_slice(&[0xff, 0xff, a[0], a[1], a[2], a[3]]); + m + }; + assert!(loopback(mapped([127, 0, 0, 1]).as_ptr(), 28)); + assert!(!loopback(mapped([8, 8, 8, 8]).as_ptr(), 28)); assert_eq!(connect(usize::MAX, v4([8, 8, 8, 8]).as_ptr(), 16), -1); assert_eq!(send_request(std::ptr::null_mut(), std::ptr::null(), 0, std::ptr::null(), 0, 0, 0), 0); }