28 Commits
Author SHA1 Message Date
Lucas ManningandgVisor bot afa323bd30 Replace most instances of IncRef with Clone.
Incrementing the reference count of a packet as a means of granting ownership
is unsafe when the packet is shared across gorountines. The underlying buffer's
reference count is unchanged since it "technically" has the same owning
PacketBuffer, which means different goroutines operating on the underlying
buffer (and packet itself) race.

Clones are roughly as fast as IncRefs because the PacketBuffers allocate from
a pool and the underlying buffers are cloned with copy-on-write
semantics.

I've left IncRef in places where the original packet in obviously going out of
scope at the end of the function or in some tests.

Reported-by: syzbot+e026046f4bf8ad09ae1f@syzkaller.appspotmail.com
Reported-by: syzbot+559365d6050db4b30e0f@syzkaller.appspotmail.com
Reported-by: syzbot+63c78a2c88a5744c636b@syzkaller.appspotmail.com
PiperOrigin-RevId: 705676806
2024-12-12 17:09:40 -08:00
Nayana BidariandgVisor bot 90266aa28a Netstack S/R: Mark all the structs in netstack as savable.
Marks the structs in netstack as savable. This does not change or break any
existing behavior as the netstack itself is not savable yet.

PiperOrigin-RevId: 635943481
2024-05-21 15:19:07 -07:00
Kevin KrakauerandgVisor bot 3c75945fd6 netstack: remove PacketBuffer.IsNil()
The change was originally motivated by ticket references (cl/450976957), which
were never implemented.

PiperOrigin-RevId: 617480960
2024-03-20 05:31:48 -07:00
Kevin KrakauerandgVisor bot 5b4fbd06d8 netstack: remove PacketBufferPtr
PacketBufferPtr is leftover from a dead experiment. Just use *PacketBuffer.

PiperOrigin-RevId: 611531815
2024-02-29 11:10:38 -08:00
Lucas ManningandgVisor bot 6c8187194a Automated rollback of changelist 538230394
PiperOrigin-RevId: 540671483
2023-06-15 13:21:26 -07:00
Lucas ManningandgVisor bot 639ca440e6 Change Buffer.PullUp so that it returns views that are not shared.
The underlying chunks returned from PullUp should not be shared,
since the underlying slice can sometimes be directly modified. This change
also reworks some of the network parsing code so that ownership of
views is more explicit to the reader.

PiperOrigin-RevId: 538230394
2023-06-06 10:51:15 -07:00
Kevin KrakauerandgVisor bot 89d6bf18c8 have gVisor use renamed buffer package
PiperOrigin-RevId: 537209194
2023-06-01 21:27:49 -07:00
Kevin KrakauerandgVisor bot dd9a3d10bd netstack: change PacketBufferPtr back to *PacketBuffer
The benefits of PacketBufferPtr never materialized and it makes the type
difficult to work with, e.g. it can't be used with go_generics to make a
(performant) list.

This is effectively a rollback of cl/480518221.

PiperOrigin-RevId: 530954630
2023-05-10 11:16:28 -07:00
Adin ScannellandgVisor bot 1ceb814544 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Ayush RanjanandgVisor bot 175db901ca Replace pkg/refs with pkg/refsvfs2.
All VFS1 only bits have been deleted.

Updates #1624

PiperOrigin-RevId: 492273183
2022-12-01 12:46:11 -08:00
Lucas ManningandgVisor bot 1fc476d7fe Return a new packet from fragment reassembly instead of an old one.
PiperOrigin-RevId: 486246464
2022-11-04 15:41:34 -07:00
Kevin KrakauerandgVisor bot 607fdc536d DecRef ptr niling
PiperOrigin-RevId: 480518221
2022-10-11 20:27:23 -07:00
Kevin KrakauerandgVisor bot 4eca206fa4 netstack: introduce PacketBufferPtr
PiperOrigin-RevId: 479437464
2022-10-06 16:16:54 -07:00
Konstantin BogomolovandgVisor bot a4fb3b200f Fix panic on nil map in Fragmentation.
A rare bug occurs when assigning a value to the reassemblers map causes a panic
due to the map being nil. The only way this is possible is if
Fragmentation.Release() is called before Process() is able to finish.

PiperOrigin-RevId: 466771159
2022-08-10 13:25:55 -07:00
Lucas ManningandgVisor bot 1f2b30d70c Refactor netstack to use bufferv2 instead of buffer.
This change has significant performance implications. bufferv2 is reference
counted and pooled, which alleviates heap/GC pressure. Below are the results
from running the iperf benchmark.

HEAD:
BenchmarkIperf/operation.Upload-16    1552  ns/op   46.6GiB total allocations
BenchmarkIperf/operation.Download-16  1114  ns/op   68.6GiB total allocations

w/ change:
BenchmarkIperf/operation.Upload-16    1139  ns/op (-27%)   1.41GiB total allocations (-97%)
BenchmarkIperf/operation.Download-16  753.2 ns/op (-33%)   706MiB  total allocations (-99%)

PiperOrigin-RevId: 462453185
2022-07-21 13:09:31 -07:00
Lucas ManningandgVisor bot e64458ff08 Remove VectorisedView everywhere.
PiperOrigin-RevId: 453471156
2022-06-07 10:36:23 -07:00
Lucas ManningandgVisor bot 6103b4b3b6 Replace VectorisedView in network endpoints.
PiperOrigin-RevId: 451267391
2022-05-26 16:25:30 -07:00
Kevin KrakauerandgVisor bot 2b52af3592 netstack: have IncRef() return *PacketBuffer
This makes it clearer where the new ownership is occuring.

PiperOrigin-RevId: 450987161
2022-05-25 12:26:18 -07:00
Bhasker HariharanandgVisor bot ae089adbb2 Add Leak checking to ipv4 tests.
PiperOrigin-RevId: 428946053
2022-02-15 20:53:01 -08:00
Lucas ManningandgVisor bot 6a28dc7c59 Correct fragmentation reference counting.
Before this change the only reference on the packet after reassembly
processing was held by the reassembler in the holes array. This meant that
after the reassembly cleanup job, there were no references left on the
packet, leading to use after free bugs.

PiperOrigin-RevId: 424479461
2022-01-26 17:26:49 -08:00
Lucas ManningandgVisor bot 8c9dc0babf Update PacketBuffer to hold a Buffer struct instead of a Buffer pointer.
The extra pointer indirection is not necessary and allows for a nil buffer.
This change bumps the PacketBuffer struct size from 296 to 792 bytes.

PiperOrigin-RevId: 422669812
2022-01-18 16:06:43 -08:00
Lucas ManningandgVisor bot 6d15b0ee64 Fix packet buffer reference counting in IP fragmentation/reassembly.
This change also adds a reference counting check to the
fragmentation/reassembly unit tests.

PiperOrigin-RevId: 422097740
2022-01-15 16:35:49 -08:00
Lucas ManningandgVisor bot 84b38f4c6e Add reference counting to packet buffers.
PiperOrigin-RevId: 408426639
2021-11-08 13:28:38 -08:00
Tamir DubersteinandgVisor bot 4f2439fb0e Use opaque types to represent time
Introduce tcpip.MonotonicTime; replace int64 in tcpip.Clock method
returns with time.Time and MonotonicTime to improve type safety and
ensure that monotonic clock readings are never compared to wall clock
readings.

PiperOrigin-RevId: 375775907
2021-05-25 13:00:29 -07:00
Tamir DubersteinandgVisor bot 0b7854cf1e Handle errors
PiperOrigin-RevId: 375490676
2021-05-24 09:26:22 -07:00