[GH-ISSUE #5462] [Bug]: Salamander finalmask causes Hysteria2 UDP listener to hang on invalid packet (same root cause as XTLS#6184) #3821

Closed
opened 2026-10-31 20:35:12 +07:00 by bsakaguchi · 2 comments
Owner

Originally created by @Pb110200 on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5462

Describe the bug

3x-ui version: 3.1.1
Xray-core version: 26.6.1
Protocol: Hysteria2 + TLS + salamander finalmask
OS: Ubuntu 22.04

Description

When streamSettings.finalmask.udp[].type = "salamander" is configured on a Hysteria2 inbound, the first invalid UDP packet that hits the port permanently kills the listener. All legitimate client traffic is silently dropped at kernel level until xray.service is restarted.

This is the exact same bug as XTLS/Xray-core#6184 (fixed by #6185), but that fix only covered the sudoku type — salamander has the identical code path issue.

Logs

ERROR - XRAY: transport/internet/finalmask: [mask] drop packet fromxx.xx.xx.xx:41868 with size 6
After this log, all subsequent legitimate client traffic gets silently dropped. ss -uanm shows kernel receive buffer full.

How to reproduce the problem

  1. Go to Inbounds page, create or edit a Hysteria2 inbound
  2. In Stream Settings, add UDP Mask 1 with type salamander and a password
  3. Save and restart xray
  4. Send any malformed UDP packet to the inbound port:
    echo -n 'X' | nc -u -w1 <server_ip> <port>
  5. Observe all legitimate Hysteria2 clients immediately time out
  6. Run ss -uanm — kernel receive buffer is full, dropped packet counter grows

Expected behavior

Invalid UDP packets should be silently discarded without killing the listener. The salamander finalmask should handle decode errors the same way sudoku does after PR #6185 — skip the bad packet and continue reading.
Actual behavior

Actual behavior

The first invalid UDP packet causes the listener to permanently stop responding. The xray process stays alive and accepts new TCP connections, but the UDP port is dead until systemctl restart xray or a full server reboot.

Relevant logs

Jun 21 16:20:12 VM-0-7-ubuntu x-ui[3198034]: ERROR - XRAY: transport/internet/finalmask: [mask] drop packet from xx.xx.xx.xx:41868 with size 6

Screenshots

No response

3x-ui version

3.1.1

Xray-core version

26.6.1

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 22.04

Which parts of the panel are affected?

No response

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @Pb110200 on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5462 ### Describe the bug **3x-ui version:** 3.1.1 **Xray-core version:** 26.6.1 **Protocol:** Hysteria2 + TLS + salamander finalmask **OS:** Ubuntu 22.04 ### Description When `streamSettings.finalmask.udp[].type = "salamander"` is configured on a Hysteria2 inbound, the first invalid UDP packet that hits the port permanently kills the listener. All legitimate client traffic is silently dropped at kernel level until xray.service is restarted. This is the exact same bug as XTLS/Xray-core#6184 (fixed by #6185), but that fix only covered the `sudoku` type — `salamander` has the identical code path issue. ### Logs ERROR - XRAY: transport/internet/finalmask: [mask] drop packet fromxx.xx.xx.xx:41868 with size 6 After this log, all subsequent legitimate client traffic gets silently dropped. `ss -uanm` shows kernel receive buffer full. ### How to reproduce the problem 1. Go to `Inbounds` page, create or edit a Hysteria2 inbound 2. In `Stream Settings`, add `UDP Mask 1` with type `salamander` and a password 3. Save and restart xray 4. Send any malformed UDP packet to the inbound port: `echo -n 'X' | nc -u -w1 <server_ip> <port>` 5. Observe all legitimate Hysteria2 clients immediately time out 6. Run `ss -uanm` — kernel receive buffer is full, dropped packet counter grows ### Expected behavior Invalid UDP packets should be silently discarded without killing the listener. The `salamander` finalmask should handle decode errors the same way `sudoku` does after PR #6185 — skip the bad packet and continue reading. Actual behavior ### Actual behavior The first invalid UDP packet causes the listener to permanently stop responding. The xray process stays alive and accepts new TCP connections, but the UDP port is dead until `systemctl restart xray` or a full server reboot. ### Relevant logs ```shell Jun 21 16:20:12 VM-0-7-ubuntu x-ui[3198034]: ERROR - XRAY: transport/internet/finalmask: [mask] drop packet from xx.xx.xx.xx:41868 with size 6 ``` ### Screenshots _No response_ ### 3x-ui version 3.1.1 ### Xray-core version 26.6.1 ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 22.04 ### Which parts of the panel are affected? _No response_ ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:35:12 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 21, 2026):

The root cause has been confirmed in the xray-core source. This is a real bug, but the framing differs slightly from the issue description: it is not a salamander-specific gap analogous to the sudoku fix in XTLS/Xray-core#6185 — it is a shared infrastructure bug in transport/internet/finalmask/finalmask.go that affects all UDP mask types, including salamander.

What happens

headerManagerConn.ReadFrom() in finalmask.go reads each UDP datagram into a full-size buffer b (65535 bytes). The pre-fix code contained:

n, addr, err = c.PacketConn.ReadFrom(b)
// ...
b = b[:n]           // ← mutates b to the packet length
// ...
if n < sum {        // minimum-size check (sum = 8 for salamander)
    // ...
    continue        // ← outer loop restarts, but b is now tiny
}

When a UDP packet shorter than the salamander salt prefix (8 bytes) arrives — as in the reported case with a 6-byte datagram — the check fires, continue restarts the outer loop, and c.PacketConn.ReadFrom(b) is now called with b capped at 6 bytes. Every subsequent datagram is truncated to 6 bytes by the OS, fails the minimum-size check, and is dropped. b never grows back. The goroutine keeps reading and discarding, the kernel receive buffer fills, and legitimate clients time out.

The log line you observed is produced by exactly this check:

errors.LogError(context.Background(), "[mask] drop packet from ", addr, " with size ", n)

Fix status

This is corrected in xray-core PR XTLS/Xray-core#6331 ("Finalmask: Fix unexpected order and UDP's buf issue"), merged 2026-06-17. The fix renames the mutation to a loop-local variable:

buf := b[:n]   // new local; b (the full-size read buffer) is never modified

so b remains at full capacity across all outer-loop iterations regardless of what any single packet contains.

Affected versions of 3x-ui

3x-ui's go.mod pins xray-core at commit 94ffd50060f1 (2026-06-01) in all releases up to and including the current latest, v3.3.1 (released 2026-06-12). That commit predates the merge of PR #6331 (2026-06-17), so the bug is present in every current release of 3x-ui.

Regarding XTLS/Xray-core#6185

PR #6185 hardened sudoku's own conn_udp.go ReadFrom loop so it continues on decode errors rather than returning them. That was a separate, sudoku-specific robustness improvement. It did not touch finalmask.go and did not address the buffer-mutation bug described here.

Workaround until a dependency update ships

There is no configuration-level workaround. The only option is to avoid salamander finalmask on Hysteria2 inbounds, or to configure firewall rules (iptables/nftables/ufw) to drop non-client source addresses before they reach the Hysteria2 UDP port.

Resolution path

The fix is entirely upstream in xray-core. A 3x-ui release that updates the go.mod pin to a commit at or after 2026-06-17 will include it.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4761624694 --> @github-actions[bot] commented on GitHub (Jun 21, 2026): The root cause has been confirmed in the xray-core source. This is a real bug, but the framing differs slightly from the issue description: it is not a salamander-specific gap analogous to the sudoku fix in XTLS/Xray-core#6185 — it is a shared infrastructure bug in `transport/internet/finalmask/finalmask.go` that affects all UDP mask types, including salamander. **What happens** `headerManagerConn.ReadFrom()` in `finalmask.go` reads each UDP datagram into a full-size buffer `b` (65535 bytes). The pre-fix code contained: ```go n, addr, err = c.PacketConn.ReadFrom(b) // ... b = b[:n] // ← mutates b to the packet length // ... if n < sum { // minimum-size check (sum = 8 for salamander) // ... continue // ← outer loop restarts, but b is now tiny } ``` When a UDP packet shorter than the salamander salt prefix (8 bytes) arrives — as in the reported case with a 6-byte datagram — the check fires, `continue` restarts the outer loop, and `c.PacketConn.ReadFrom(b)` is now called with `b` capped at 6 bytes. Every subsequent datagram is truncated to 6 bytes by the OS, fails the minimum-size check, and is dropped. `b` never grows back. The goroutine keeps reading and discarding, the kernel receive buffer fills, and legitimate clients time out. The log line you observed is produced by exactly this check: ```go errors.LogError(context.Background(), "[mask] drop packet from ", addr, " with size ", n) ``` **Fix status** This is corrected in xray-core PR [XTLS/Xray-core#6331](https://github.com/XTLS/Xray-core/pull/6331) ("Finalmask: Fix unexpected order and UDP's buf issue"), merged **2026-06-17**. The fix renames the mutation to a loop-local variable: ```go buf := b[:n] // new local; b (the full-size read buffer) is never modified ``` so `b` remains at full capacity across all outer-loop iterations regardless of what any single packet contains. **Affected versions of 3x-ui** 3x-ui's `go.mod` pins xray-core at commit `94ffd50060f1` (2026-06-01) in all releases up to and including the current latest, **v3.3.1** (released 2026-06-12). That commit predates the merge of PR #6331 (2026-06-17), so the bug is present in every current release of 3x-ui. **Regarding XTLS/Xray-core#6185** PR #6185 hardened sudoku's own `conn_udp.go` `ReadFrom` loop so it continues on decode errors rather than returning them. That was a separate, sudoku-specific robustness improvement. It did not touch `finalmask.go` and did not address the buffer-mutation bug described here. **Workaround until a dependency update ships** There is no configuration-level workaround. The only option is to avoid salamander finalmask on Hysteria2 inbounds, or to configure firewall rules (`iptables`/`nftables`/`ufw`) to drop non-client source addresses before they reach the Hysteria2 UDP port. **Resolution path** The fix is entirely upstream in xray-core. A 3x-ui release that updates the `go.mod` pin to a commit at or after 2026-06-17 will include it. *This reply was generated automatically; a maintainer may follow up.*
Author
Owner

@MHSanaei commented on GitHub (Jun 21, 2026):

Fixed by bumping the xray-core dependency past the upstream finalmask fix (XTLS/Xray-core#6331, merged 2026-06-17).

go.mod now pins xray-core at be8009c62509 (2026-06-19), which replaces the buggy b = b[:n] in transport/internet/finalmask/finalmask.go with a loop-local buf := b[:n]. The 65535-byte UDP read buffer is no longer shrunk by a short/invalid packet, so the salamander finalmask listener no longer hangs after a malformed datagram.

This will ship in the next release. Thanks for the detailed report and root-cause pointer.

<!-- gh-comment-id:4762579905 --> @MHSanaei commented on GitHub (Jun 21, 2026): Fixed by bumping the xray-core dependency past the upstream finalmask fix (XTLS/Xray-core#6331, merged 2026-06-17). `go.mod` now pins xray-core at `be8009c62509` (2026-06-19), which replaces the buggy `b = b[:n]` in `transport/internet/finalmask/finalmask.go` with a loop-local `buf := b[:n]`. The 65535-byte UDP read buffer is no longer shrunk by a short/invalid packet, so the salamander finalmask listener no longer hangs after a malformed datagram. This will ship in the next release. Thanks for the detailed report and root-cause pointer.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#3821
No description provided.