From 9e27f3413b085834c19a1432688aa3db6c6c28fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 16 Nov 2026 06:46:49 +0000 Subject: [PATCH] Fix unbounded ICMP sockets in direct outbound The direct outbound opens one ICMP socket for each echo flow. The sockets were kept for one minute after the last packet and their number was not limited, so scanning hosts through the outbound could accumulate an unbounded number of sockets, which has been reported to panic the kernel on macOS. Close idle flows after ICMPTimeout as the stacks do, and keep at most 1024 flows, closing a least recently active one when the limit is reached. --- constant/network.go | 2 ++ go.mod | 2 +- go.sum | 4 ++-- protocol/direct/outbound.go | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/constant/network.go b/constant/network.go index 88a1dd815..f3983a145 100644 --- a/constant/network.go +++ b/constant/network.go @@ -5,6 +5,8 @@ import ( F "github.com/sagernet/sing/common/format" ) +const ICMPFlowMax = 1024 + type InterfaceType uint8 const ( diff --git a/go.mod b/go.mod index 45dbd95bf..e19ddea4d 100644 --- a/go.mod +++ b/go.mod @@ -55,7 +55,7 @@ require ( github.com/sagernet/sing-shadowsocks2 v0.2.2-0.20261110092058-52ade8ab7e95 github.com/sagernet/sing-shadowtls v0.2.2-0.20261114073233-97863830a3b3 github.com/sagernet/sing-snell v0.0.0-20261110094602-04667b0a321c - github.com/sagernet/sing-tun v0.9.7-0.20261114080500-78e734ea0994 + github.com/sagernet/sing-tun v0.9.7-0.20261116064316-e7af358a2cc9 github.com/sagernet/sing-usbip v0.0.0-20260817040617-28bd42667eca github.com/sagernet/sing-vmess v0.2.9-0.20261110093549-d800eb57f96c github.com/sagernet/smux v1.5.50-sing-box-mod.1 diff --git a/go.sum b/go.sum index 0de74a5c5..f885068e8 100644 --- a/go.sum +++ b/go.sum @@ -338,8 +338,8 @@ github.com/sagernet/sing-shadowtls v0.2.2-0.20261114073233-97863830a3b3 h1:UY+nv github.com/sagernet/sing-shadowtls v0.2.2-0.20261114073233-97863830a3b3/go.mod h1:sWqKnGlMipCHaGsw1sTTlimyUpgzP4WP3pjhCsYt9oA= github.com/sagernet/sing-snell v0.0.0-20261110094602-04667b0a321c h1:OODxu54K5ZvgnS97t8HlN3tily8Oj+s6ygOJ1ZzyfFQ= github.com/sagernet/sing-snell v0.0.0-20261110094602-04667b0a321c/go.mod h1:Na4U54WiSQxWD/KEFIIdr+rPE9Qnr/kk8EtKXa18pRk= -github.com/sagernet/sing-tun v0.9.7-0.20261114080500-78e734ea0994 h1:nrivq/RdNSFDFEv91aKO3Vw3m1e075PtlRmJbjIejM8= -github.com/sagernet/sing-tun v0.9.7-0.20261114080500-78e734ea0994/go.mod h1:NqRKOzmp+umzkKtiSRa+AIP6pmCtdCGTUZLb1zscf4I= +github.com/sagernet/sing-tun v0.9.7-0.20261116064316-e7af358a2cc9 h1:Z3yiRxPm+qgbJPmdjJSwqzDzQXqlCKRKBuoSy8Ts4Aw= +github.com/sagernet/sing-tun v0.9.7-0.20261116064316-e7af358a2cc9/go.mod h1:NqRKOzmp+umzkKtiSRa+AIP6pmCtdCGTUZLb1zscf4I= github.com/sagernet/sing-usbip v0.0.0-20260817040617-28bd42667eca h1:5wA+IE0Fq1CGVLOgSpm0gKKZ03HzugcJ2JyhmDqeX6A= github.com/sagernet/sing-usbip v0.0.0-20260817040617-28bd42667eca/go.mod h1:ADAZZU85MnM91XNhd2TdZRTaIbA7RjTZuQ1KCHcUbNg= github.com/sagernet/sing-vmess v0.2.9-0.20261110093549-d800eb57f96c h1:3svsvOhs6e7BcHY8o9+Fo0qGJ+enoLTdPIaRbqwsiaE= diff --git a/protocol/direct/outbound.go b/protocol/direct/outbound.go index 3b3d75254..1275de93f 100644 --- a/protocol/direct/outbound.go +++ b/protocol/direct/outbound.go @@ -87,7 +87,7 @@ func NewOutbound(ctx context.Context, router adapter.Router, logger log.ContextL icmpControl := defaultDialer.ICMPControl() outbound.icmpPort = ping.NewPort(ctx, logger, func(destination netip.Addr) control.Func { return icmpControl - }, 0) + }, C.ICMPTimeout, C.ICMPFlowMax) } return outbound, nil }