160 Commits
Author SHA1 Message Date
Ayush RanjanandgVisor bot e161bec8dc Unlock fdbased.endpoint.mu before fdbased.endpoint.Wait().
This prevents the deadlock described in #11456.

Fixes #11456.

PiperOrigin-RevId: 725352718
2025-02-10 14:45:27 -08:00
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 df9ba5fb67 Restore listening connections when netstack s/r is enabled.
This CL restores the listening connections when netstack s/r is enabled.
The changes include:
- New method as a workaround to replace the new routes and nics to the loaded
stack after restore.
- New Restore() for transport layer protocols to restore the protocol level
background workers.
- Adds afterLoad() method for fdbased processors.
- Adds a test to verify listening connection is restored after checkpointing
with netstack s/r enabled.
- Few other changes to save restore fields to enable netstack s/r.

PiperOrigin-RevId: 698453124
2024-11-20 11:13:57 -08:00
Andrei VaginandgVisor bot e2e84bf5ba tcpip/link: use lockdep mutexes
PiperOrigin-RevId: 692004573
2024-10-31 18:56:13 -07:00
Jing Chen 7cc17225e6 Remove references to math/rand package's Read function.
The helper function is deprecated. The package gvisor.dev/gvisor/pkg/rand
depends on crypto/rand which performs worse thatn math/rand, the changes
are fine since they are not at any gVisor's hot path.

The ultimate goal is to migrate math/rand to math/rand/v2.
2024-10-16 18:17:15 +00:00
Kevin KrakauerandgVisor bot dd011f2e9f netstack: check inbound MAC addresses in the fdbased link endpoint
We weren't verifying that inbound MAC addresses match the NIC, which led to
netstack ingesting packets not meant for it.

Fixes #10908.

PiperOrigin-RevId: 675330632
2024-09-16 16:23:27 -07:00
Nayana BidariandgVisor bot 98c83d5022 Make rawfile.MMsgHdr as nosave.
recvMMsgDispatcher.msgHdrs is not required to be saved across s/r, mark it as
nosave and make changes to re-initialize it after restore.

PiperOrigin-RevId: 673859213
2024-09-12 08:33:37 -07:00
Nayana BidariandgVisor bot 740dc367db Mark netstack as save and use it only in tests
- Adds a new flag which will enable netstack s/r. When the flag is not enabled,
there is no change in the existing behavior. The flag will be enabled only in
tests to verify the s/r functionality of netstack.
- Some additional fields in netstack were causing panic when netstack is
save/restored. Such fields are marked as 'save'/'nosave' accordingly to resolve
the panic.

PiperOrigin-RevId: 668566657
2024-08-28 12:49:43 -07:00
Nayana BidariandgVisor bot ee34fd3b9d Mark more structs in netstack as savable.
PiperOrigin-RevId: 663780274
2024-08-16 10:47:24 -07:00
Jamie LiuandgVisor bot d463f4e1d2 tcpip: ensure fdbased/mmap_stub.go uses a stateify-recognized suffix
Our Bazel build infrastructure explicitly recognizes some suffixes that can
appear at the end of filenames (tools/bazeldefs/tags.bzl). It uses these tags
to group files passed to go_stateify (tools/defs.bzl:go_library() =>
calculate_sets()).

Each invocation of go_stateify infers build tags from its input files. Before
this CL, all Go files in pkg/tcpip/link/fdbased (except for fdbased_unsafe.go)
are grouped together to generate fdbased_state_autogen.go, so go_stateify
infers builds tags "!linux !amd64,!arm64" (from mmap_stub.go) and "linux ..."
(from most other files); these contradictory build tags mean that
fdbased_state_autogen.go is never actually compiled, preventing its types from
being registered. After this CL, mmap_nonlinux.go independently generates
fdbased_nonlinux_state_autogen.go.

Fixing this causes fdbased_state_autogen.go to be included for the first time,
exposing a second problem:

```
pkg/tcpip/link/fdbased/endpoint_test.go:80:6: context already declared through import of package context ("context")
        .../pkg/tcpip/link/fdbased/fdbased_state_autogen.go:12:2: other declaration of context
```

(Apparently Go imports are a pessimal hybrid of "shared between files in a
package" and "not shared between files in a package".) To fix this, rename the
test type to testContext.

PiperOrigin-RevId: 663522480
2024-08-15 18:05:29 -07:00
Andrei VaginandgVisor bot b488752cba netstack: implement RTM_SETLINK/IFLA_NET_NS_FD
IFLA_NET_NS_FD specifies a file descriptor that refers to a network namespace.

PiperOrigin-RevId: 648882826
2024-07-02 16:49:27 -07:00
Etienne PerotandgVisor bot d59375d82e Break //pkg/tcpip/link/rawfile's dep on //pkg/tcpip & move it to //pkg.
`//pkg/tcpip/link/rawfile` is a package to deal with raw socket and file FDs.
It is not only used for Netstack, but rather just generally useful raw file
manipulation stuff.

This change removes the Unix-error-to-`//pkg/tcpip`-error translation step
from its functions; this is now the responsibility of its callers. Callers
within Netstack now do the translation by themselves; the translation
function is moved to `//pkg/tcpip`.

This allows the `//pkg/tcpip/link/rawfile` package to not depend on
`//pkg/tcpip`, which in turn means the `//pkg/eventfd` package
(which depends on `rawfile`) no longer transitively depends on
`//pkg/tcpip`, which in turns means the `//pkg/unet` package (which
depends on `//pkg/eventfd`) no longer transitively depends on
`//pkg/tcpip`, which in turns means that the `//pkg/eventchannel`
package (which depends on `//pkg/unet`) no longer transitively
depends on `//pkg/tcpip`, which in turns means that the `//pkg/metric`
package (which depends on `//pkg/eventchannel`) no longer transitively
depends on `//pkg/tcpip`, which finally means that the `//pkg/metric`
package can be used within `//pkg/tcpip`. \o/

This changes does not make it use it, it just moves `rawfile`.

PiperOrigin-RevId: 647943618
2024-06-29 05:11:53 -07:00
Jing ChenandgVisor bot 8ef3239b0b Add SetMTU to change the mtu of device.
The method will be primarily used with RTM_[NEW|SET]LINK when IFLA_MTU
is present.

PiperOrigin-RevId: 646264847
2024-06-24 16:58:13 -07:00
Andrei VaginandgVisor bot 646a033213 tcpip: destroy both ends of one veth pair together
PiperOrigin-RevId: 645562424
2024-06-21 18:50:54 -07:00
Jing ChenandgVisor bot 14c6ef6d52 Lock the mutex when reading a LinkAddress.
PiperOrigin-RevId: 645543579
2024-06-21 17:17:10 -07:00
Jing ChenandgVisor bot 2c5c7869d9 Add SetLinkAddress method to NetworkLinkEndpoint interface.
The method will be primarily used by IFLA_ADDRESS.

PiperOrigin-RevId: 642492748
2024-06-11 21:40:39 -07:00
ignoramousandGitHub 3c20222c76 fdbased: uint32 to int may overflow on 32-bit 2024-05-31 00:09:14 +05:30
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
Lucas ManningandgVisor bot 9401ec1190 Fix flaky fragment reassembly.
Fragmented packets need to be handled by the same processor goroutine.

PiperOrigin-RevId: 635529020
2024-05-20 12:05:33 -07:00
Lucas ManningandgVisor bot 6a7e4c2102 Fix race during fdbased endpoint teardown.
If the fdbased processor is handling packets and the endpoint dispatcher
concurrently is set to nil we can crash the sandbox.

PiperOrigin-RevId: 634007307
2024-05-15 10:55:26 -07:00
Lucas ManningandgVisor bot a67dd10623 Automated rollback of changelist 630263974
PiperOrigin-RevId: 633277180
2024-05-13 11:33:19 -07:00
Jing ChenandgVisor bot cf5c4c9cbf Replace reflect.DeepEqual with [slices/maps].Equal.
They are faster on slice/map comparisons.

PiperOrigin-RevId: 633080355
2024-05-12 21:20:18 -07:00
Nicolas LacasseandgVisor bot f67e10cf38 Automated rollback of changelist 629815554
PiperOrigin-RevId: 630263974
2024-05-02 21:02:05 -07:00
Lucas ManningandgVisor bot 19c7ca8c3b Add fdbased processor goroutines.
Results from iperf microbenchmark:
```
name                                                    old speed                       new speed                       delta
IperfOneConnection/operation.Upload-16                                    226GB/s ± 1%                    240GB/s ± 2%   +6.44%  (p=0.008 n=5+5)
IperfOneConnection/operation.Download-16                                  330GB/s ± 3%                    350GB/s ± 2%   +6.12%  (p=0.016 n=5+4)
IperfManyConnections/operation.Upload/parallel.4-16                       617GB/s ± 2%                    644GB/s ± 1%   +4.43%  (p=0.016 n=5+4)
IperfManyConnections/operation.Download/parallel.4-16                     302GB/s ± 1%                    337GB/s ± 3%  +11.85%  (p=0.008 n=5+5)
IperfManyConnections/operation.Upload/parallel.16-16                      702GB/s ± 3%                    640GB/s ± 4%   -8.82%  (p=0.008 n=5+5)
IperfManyConnections/operation.Download/parallel.16-16                    267GB/s ± 1%                    305GB/s ± 1%  +14.17%  (p=0.008 n=5+5)
IperfManyConnections/operation.Upload/parallel.64-16                      486GB/s ± 7%                    655GB/s ± 1%  +34.88%  (p=0.008 n=5+5)
IperfManyConnections/operation.Download/parallel.64-16                    181GB/s ± 1%                    215GB/s ± 1%  +18.78%  (p=0.008 n=5+5)
```

PiperOrigin-RevId: 629815554
2024-05-01 13:18:13 -07:00
Lucas ManningandgVisor bot 5cecdfbabd Create configuration for fdbased processor goroutines.
This configuration doesn't do anything right now, the implementation is
in the child change.

PiperOrigin-RevId: 627194527
2024-04-22 16:47:19 -07:00