Skip to content

Fix MIPS socket option (SO_*) values#1641

Open
retrocpugeek wants to merge 1 commit into
qilingframework:devfrom
retrocpugeek:fix/mips-socket-options
Open

Fix MIPS socket option (SO_*) values#1641
retrocpugeek wants to merge 1 commit into
qilingframework:devfrom
retrocpugeek:fix/mips-socket-options

Conversation

@retrocpugeek

Copy link
Copy Markdown

Summary

linux_mips_socket_options used generic/incorrect SO_* values. MIPS has its own numbering (arch/mips/include/uapi/asm/socket.h) with the buffer/timeout/type options in the 0x1000 range. As a result a guest setsockopt(SOL_SOCKET, SO_RCVBUF, ...) — issued by ordinary programs such as busybox ping — aborted emulation with NotImplementedError: Could not convert emulated socket option 4098 (4098 == 0x1002 == SO_RCVBUF on MIPS).

Closes #1640.

What was wrong

  • SO_SNDBUF/SO_RCVBUF were 0x01/0x02 (should be 0x1001/0x1002); SO_SND/RCVLOWAT and SO_SND/RCVTIMEO_OLD likewise off by the 0x1000 base.
  • SO_RCVLOWAT = 0x04 silently collided with SO_REUSEADDR = 0x04 (became an Enum alias).
  • SO_OOBINLINE/SO_REUSEPORT were 0x00.
  • SO_TYPE/SO_ERROR/SO_ACCEPTCONN/SO_PROTOCOL/SO_DOMAIN were missing.

How

Correct all SO_* values to the MIPS uapi and add the missing ones. No other arch's table is touched.

Testing

test_elf.ELFTest.test_setsockopt_mips_so_rcvbuf opens a socket on a MIPS guest and asserts setsockopt(SOL_SOCKET, SO_RCVBUF) succeeds. Self-contained (no rootfs binary, runs on stock unicorn); fails on dev, passes with this fix.

Verified end-to-end separately: busybox ping on a MIPS64 rootfs now gets past setsockopt and completes an ICMP echo exchange (run with CAP_NET_RAW for the raw socket).

Checklist

  • This PR only contains minor fixes.
  • The new code conforms to Qiling Framework naming convention.
  • Essential comments are added.
  • I have added enough tests for this PR.
  • The target branch is dev branch.

linux_mips_socket_options used generic/incorrect values. MIPS has its own
SO_* numbering (arch/mips/include/uapi/asm/socket.h) with the buffer/timeout/
type options in the 0x1000 range. The table listed SO_SNDBUF=0x01,
SO_RCVBUF=0x02 (should be 0x1001/0x1002), SO_SND/RCVLOWAT and SO_SND/RCVTIMEO_OLD
all wrong, SO_RCVLOWAT=0x04 silently collided with SO_REUSEADDR (Enum alias),
and SO_OOBINLINE/SO_REUSEPORT were 0x00.

A guest setsockopt(SOL_SOCKET, SO_RCVBUF, ...) (e.g. busybox ping) therefore
raised 'Could not convert emulated socket option 4098'. Correct all values to
the MIPS uapi and add the missing SO_TYPE/SO_ERROR/SO_ACCEPTCONN/SO_PROTOCOL/
SO_DOMAIN.

Add test_elf.ELFTest.test_setsockopt_mips_so_rcvbuf: opens a socket on a MIPS
guest and asserts setsockopt(SOL_SOCKET, SO_RCVBUF) succeeds. Self-contained,
runs on stock unicorn; fails on dev, passes with the fix.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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