net/tstun: fix gvisor inbound GSO packet injection (#13283)

buffs[0] was not sized to hold pkt with GSO, resulting in a panic.

Updates tailscale/corp#22511

Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
Jordan Whited
2024-08-27 14:59:43 -07:00
committed by GitHub
parent a2c42d3cd4
commit 31cdbd68b1
2 changed files with 9 additions and 4 deletions

View File

@ -826,13 +826,18 @@ func (ns *Impl) DialContextUDP(ctx context.Context, ipp netip.AddrPort) (*gonet.
// across subsequent inbound packet injection calls.
func (ns *Impl) getInjectInboundBuffsSizes() (buffs [][]byte, sizes []int) {
batchSize := 1
if ns.linkEP.SupportedGSO() == stack.HostGSOSupported {
gsoEnabled := ns.linkEP.SupportedGSO() == stack.HostGSOSupported
if gsoEnabled {
batchSize = conn.IdealBatchSize
}
buffs = make([][]byte, batchSize)
sizes = make([]int, batchSize)
for i := 0; i < batchSize; i++ {
buffs[i] = make([]byte, tstun.PacketStartOffset+tstun.DefaultTUNMTU())
if i == 0 && gsoEnabled {
buffs[i] = make([]byte, tstun.PacketStartOffset+ns.linkEP.GSOMaxSize())
} else {
buffs[i] = make([]byte, tstun.PacketStartOffset+tstun.DefaultTUNMTU())
}
}
return buffs, sizes
}