Skip to content

Commit 31cdbd6

Browse files
authored
net/tstun: fix gvisor inbound GSO packet injection (tailscale#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>
1 parent a2c42d3 commit 31cdbd6

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

net/tstun/wrap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,8 +1258,8 @@ func (t *Wrapper) SetJailedFilter(filt *filter.Filter) {
12581258
//
12591259
// pkt will be copied into buffs before writing to the underlying tun.Device.
12601260
// Therefore, callers must allocate and pass a buffs slice that is sized
1261-
// appropriately for holding pkt.Size() + PacketStartOffset as either a single
1262-
// element (buffs[0]), or split across multiple elements if the originating
1261+
// appropriately for holding pkt.Size() + PacketStartOffset as a single
1262+
// element (buffs[0]) and split across multiple elements if the originating
12631263
// stack supports GSO. sizes must be sized with similar consideration,
12641264
// len(buffs) should be equal to len(sizes). If any len(buffs[<index>]) was
12651265
// mutated by InjectInboundPacketBuffer it will be reset to cap(buffs[<index>])

wgengine/netstack/netstack.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,13 +826,18 @@ func (ns *Impl) DialContextUDP(ctx context.Context, ipp netip.AddrPort) (*gonet.
826826
// across subsequent inbound packet injection calls.
827827
func (ns *Impl) getInjectInboundBuffsSizes() (buffs [][]byte, sizes []int) {
828828
batchSize := 1
829-
if ns.linkEP.SupportedGSO() == stack.HostGSOSupported {
829+
gsoEnabled := ns.linkEP.SupportedGSO() == stack.HostGSOSupported
830+
if gsoEnabled {
830831
batchSize = conn.IdealBatchSize
831832
}
832833
buffs = make([][]byte, batchSize)
833834
sizes = make([]int, batchSize)
834835
for i := 0; i < batchSize; i++ {
835-
buffs[i] = make([]byte, tstun.PacketStartOffset+tstun.DefaultTUNMTU())
836+
if i == 0 && gsoEnabled {
837+
buffs[i] = make([]byte, tstun.PacketStartOffset+ns.linkEP.GSOMaxSize())
838+
} else {
839+
buffs[i] = make([]byte, tstun.PacketStartOffset+tstun.DefaultTUNMTU())
840+
}
836841
}
837842
return buffs, sizes
838843
}

0 commit comments

Comments
 (0)