Repository navigation
fix: observe unsent bytes on Android, where SIOCOUTQNSD is denied - #11
Merged
Merged
Conversation
Android's SELinux policy lets apps issue SIOCOUTQ but not SIOCOUTQNSD (priv_sock_ioctls), so every Linux ack observer failed with EACCES and the TCP fake, disorder and SplitWaitSent failed at connect time. When SIOCOUTQNSD fails with EACCES or EPERM, read tcpi_notsent_bytes from getsockopt(TCP_INFO) (offset 144 on every arch, Linux 4.6+; via socketcall on linux/386). A kernel whose TCP_INFO ends before the field leaves the socket without Sent observation. The choice is made once per connection and shared by split wait, disorder and the fake. Methods that need unsent bytes now check the socket before the first piece is written and fail with ErrSplitWaitUnsupported, ErrDisorderUnsupported or ErrFakeUnsupported (wrapping the errno), never with a substitute. PlatformCapabilities on Android no longer claims SplitWaitSent, the TCP fake or disorder; it lists them in the new Capabilities.Conditional. ProbeCapabilities resolves them on a live socket, and ProbeConn reports the per-socket mechanism and ConnCapabilities.SentErr.
Nemu-x
added a commit
to Nemu-x/ClashFest
that referenced
this pull request
Oct 29, 2026
Patch 0021 is SlothClash's regenerated 0023, byte-identical: it pins github.com/Nemu-x/desync main at 673cbef (v0.2.1-0.20261029232908-673cbefddb80, Nemu-x/desync#11; it becomes v0.2.1 once tagged) and makes the desync outbound accept a method the library lists in Capabilities.Conditional (split-wait sent, disorder, fake on Android, where apps may not read SIOCOUTQNSD), logging once per outbound that it is verified per connection. Both Go modules require the same version, synced with go list -mod=mod. The bridge's desyncCapabilities now carries conditional and probed: desync.ProbeCapabilities of a loopback connection, run once per process, so the UI sees what a socket of the app can really do. The preset catalog and the desync-only profile generator filter by that probe (falling back to the platform report), so Android keeps the fake, disorder and split-wait sent presets where TCP_INFO provides unsent bytes.
Nemu-x
added a commit
to Nemu-x/SlothClash
that referenced
this pull request
Oct 29, 2026
Patch 0023 now pins github.com/Nemu-x/desync main at 673cbef (v0.2.1-0.20261029232908-673cbefddb80, Nemu-x/desync#11); it becomes v0.2.1 once tagged. Android denies apps SIOCOUTQNSD, so the library no longer claims split-wait sent, disorder and the TCP fake there: it lists them in Unsupported and in Capabilities.Conditional, and a socket without TCP_INFO unsent bytes fails before sending. As in Citrus, the desync outbound accepts a method listed in Conditional and logs once per outbound that it is verified per connection; tests cover an Android-like capability report with and without Conditional. YAML keys are unchanged and identical to Citrus.
Nemu-x
added a commit
to Nemu-x/SlothClash
that referenced
this pull request
Oct 30, 2026
Patch 0023 now pins github.com/Nemu-x/desync main at 673cbef (v0.2.1-0.20261029232908-673cbefddb80, Nemu-x/desync#11); it becomes v0.2.1 once tagged. Android denies apps SIOCOUTQNSD, so the library no longer claims split-wait sent, disorder and the TCP fake there: it lists them in Unsupported and in Capabilities.Conditional, and a socket without TCP_INFO unsent bytes fails before sending. As in Citrus, the desync outbound accepts a method listed in Conditional and logs once per outbound that it is verified per connection; tests cover an Android-like capability report with and without Conditional. YAML keys are unchanged and identical to Citrus.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On Android, SELinux allows apps only the socket ioctls in
unpriv_sock_ioctls;SIOCOUTQNSD(0x894b) is inpriv_sock_ioctlsand denied to every app (Android 8+, Termux too). Every send-queue observation read it, so the TCP fake, disorder andSplitWaitSentfailed at connect time on Android whilePlatformCapabilities()reported them supported.SIOCOUTQNSDfirst; onEACCES/EPERM→getsockopt(TCP_INFO)tcpi_notsent_bytes(offset 144 on every arch; linux/386 via socketcall); on a shortTCP_INFO(kernel < 4.6) or another failure, Sent is unsupported for that socket with the reason kept. Other ioctl errors stay errors. The result is cached per connection, so the denied ioctl is tried (and audit-logged) once.sentcheck the socket's observation before the first piece and returnErrFakeUnsupported/ErrDisorderUnsupported/ErrSplitWaitUnsupportedwrapping the errno; nothing is substituted.SplitWaitAckedkeeps working onSIOCOUTQalone.PlatformCapabilities()reportsFakeTCP,DisorderandAck.Sentas false, listed inUnsupportedand in a newCapabilities.Conditional;ProbeCapabilities(conn)resolves them on a live socket;ProbeConnreports the socket's own mechanism (SIOCOUTQ/SIOCOUTQNSD,SIOCOUTQ/TCP_INFO,SIOCOUTQ) andSentErr. desync-probe resolves them over a loopback connection, so Termux runs keep the fake and disorder presets.presets.Available(PlatformCapabilities())now drops fake/disorder on Android; callers that want them (Citrus, the mihomo patch) should treatConditionalmethods as allowed in config validation and rely on the per-connection error.SIOCOUTQNSDis denied by seccomp/LSM take the same fallback. README gets an Android column;docs/connection-io.mda section "Android send-queue observation".Tests:
TCP_INFOlayout and parsing (both byte orders, lengths 0–280), the fallback chain with a stub kernel, the denied ioctl tried once, capability reporting, every method under the denial with and withoutTCP_INFO(7 cases × tcp4/tcp6: server reads 0 bytes, error wraps the sentinel andEACCES), and the 30siocoutqnsd-denied/...low-hop drop subtests as root. Kernel cross-check: with a full peer windowSIOCOUTQNSDandtcpi_notsent_bytesboth read 983094.Checks: gofmt; vet on Go 1.26.10 and 1.20.14 for windows, linux (amd64/386/arm/arm64), darwin, android/arm64; Windows tests (both Go); Docker Linux
-raceas root withDESYNC_REQUIRE_LOWHOP=1, Go 1.20,GOARCH=386, and as an unprivileged user. Android 16 emulator (kernel 6.6, Enforcing): the test binaries pass inadb shelland inside a debuggable app viarun-as(u:r:runas_app), withavc: denied { ioctl } ioctlcmd=0x894bonce per connection and the probe reportingSIOCOUTQ/TCP_INFO, fake and disorder available. Not verified: a physical device, a normally launcheduntrusted_app, a real kernel < 4.6, seccomp on every vendor build.