Fix: should always drop packet when handle UDP packet (#2659)

This commit is contained in:
gVisor bot 2023-04-05 14:05:23 +08:00
parent d20ac0dc8a
commit 193fa1b7c5
2 changed files with 6 additions and 2 deletions

View file

@ -13,8 +13,6 @@ import (
) )
func handleUDPToRemote(packet C.UDPPacket, pc C.PacketConn, metadata *C.Metadata) error { func handleUDPToRemote(packet C.UDPPacket, pc C.PacketConn, metadata *C.Metadata) error {
defer packet.Drop()
addr := metadata.UDPAddr() addr := metadata.UDPAddr()
if addr == nil { if addr == nil {
return errors.New("udp addr invalid") return errors.New("udp addr invalid")

View file

@ -273,6 +273,7 @@ func resolveMetadata(ctx C.PlainContext, metadata *C.Metadata) (proxy C.Proxy, r
func handleUDPConn(packet C.PacketAdapter) { func handleUDPConn(packet C.PacketAdapter) {
metadata := packet.Metadata() metadata := packet.Metadata()
if !metadata.Valid() { if !metadata.Valid() {
packet.Drop()
log.Warnln("[Metadata] not valid: %#v", metadata) log.Warnln("[Metadata] not valid: %#v", metadata)
return return
} }
@ -284,6 +285,7 @@ func handleUDPConn(packet C.PacketAdapter) {
} }
if err := preHandleMetadata(metadata); err != nil { if err := preHandleMetadata(metadata); err != nil {
packet.Drop()
log.Debugln("[Metadata PreHandle] error: %s", err) log.Debugln("[Metadata PreHandle] error: %s", err)
return return
} }
@ -292,6 +294,7 @@ func handleUDPConn(packet C.PacketAdapter) {
if !metadata.Resolved() { if !metadata.Resolved() {
ip, err := resolver.ResolveIP(context.Background(), metadata.Host) ip, err := resolver.ResolveIP(context.Background(), metadata.Host)
if err != nil { if err != nil {
packet.Drop()
return return
} }
metadata.DstIP = ip metadata.DstIP = ip
@ -309,6 +312,7 @@ func handleUDPConn(packet C.PacketAdapter) {
} }
if handle() { if handle() {
packet.Drop()
return return
} }
@ -316,6 +320,8 @@ func handleUDPConn(packet C.PacketAdapter) {
cond, loaded := natTable.GetOrCreateLock(lockKey) cond, loaded := natTable.GetOrCreateLock(lockKey)
go func() { go func() {
defer packet.Drop()
if loaded { if loaded {
cond.L.Lock() cond.L.Lock()
cond.Wait() cond.Wait()