Skip to content

fix(bsd): size In6Ifreq to the real struct in6_ifreq and read ifru_flags6 - #193

Draft
andrewgazelka wants to merge 1 commit into
shellrow:mainfrom
andrewgazelka:fix/bsd-in6-ifreq-size
Draft

andrewgazelka wants to merge 1 commit into
shellrow:mainfrom
andrewgazelka:fix/bsd-in6-ifreq-size

Conversation

@andrewgazelka

Copy link
Copy Markdown

src/os/bsd/ipv6_addr_flags.rs defines In6Ifreq as 48 bytes (name, sockaddr_in6, int). From the FreeBSD, OpenBSD and NetBSD netinet6/in6_var.h (current main/master/trunk), struct in6_ifreq is name[16] plus a union whose largest members are icmp6_ifstat (34 x u64) and in6_ifstat (20 x u64), so 288 bytes on LP64. SIOCGIFAFLAG_IN6 is _IOWR('i', 73, struct in6_ifreq) in all three; the existing constant 0xC1206949 is that encoding for 288 bytes (checked with a C program built from the header struct bodies: size 288, ioctl 0xc1206949). Since the ioctl framework copies the encoded length in and out, the current 48-byte struct is smaller than what the kernel writes back. Also, the kernel returns the flags in ifru_flags6 at union offset 0 (struct offset 16), while the code reads an int at offset 44.

This changes the struct to the real union layout (padded to 288 bytes, compile-time assert), fills ifru_addr and reads ifru_flags6.

Measured: cargo check --target x86_64-unknown-freebsd and --target x86_64-unknown-netbsd pass. Not checked: OpenBSD (tier 3 target), and I did not run this on any BSD host, so the overflow and the wrong-offset read are from the headers, not observed. Header excerpts and sizes: see commit message; sources were the three in6_var.h files above.

AI disclosure: written with Claude (Sonnet); commit carries an Assisted-by: trailer.

…ags6

SIOCGIFAFLAG_IN6 encodes sizeof(struct in6_ifreq) = 0x120 bytes, but the
local struct was 48 bytes, so the kernel's copyout wrote past it, and the
flags were read from an offset the kernel never writes. Use the real
union layout, with a compile-time size assert.

Assisted-by: Claude:claude-sonnet-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant