344 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
Jing ChenandgVisor bot c88ffa321e Returns ENOBUFS when writing to a veth device whose buffer is full.
A task is stuck when it keeps sendMsg w/o any recvMsg  until  the number of
message exceeds the buffer limit. The change also significantly bumps the
limit from 64 to 1000 for a larger buffer.

Reported-by: syzbot+8788f5c1ba95e12ab07d@syzkaller.appspotmail.com
Reported-by: syzbot+67759fceac0c30ece991@syzkaller.appspotmail.com
PiperOrigin-RevId: 704904404
2024-12-10 17:35:54 -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
Jing Chen a093ad0450 Simplify and format gVisor codebase.
The changes are just output of `gofmt -s -w .`.
2024-10-13 00:50:32 -07:00
Jing ChenandgVisor bot 35d3c6eb73 Update MTU value for ethernet devices.
L2 MTU includes both payload and ethernet header. gVisor has supported setting
data link layer MTU, it will be  up to users to set up proper value for a
device's MTU if a larger value is expected.

By doing the change, gVisor will be consistent with runc:

```shell
# runc
root@cec4d7238802:/# ip link set dev lo mtu 1234
root@cec4d7238802:/# ip link list dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 1234 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

# runsc before the change.
root@7cd89278d414:/# ip link set dev lo mtu 1234
root@7cd89278d414:/# ip link list dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 1220
    link/loopback 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff

# runsc after the change.
root@e811c5851226:/# ip link set dev lo mtu 1234
root@e811c5851226:/# ip link list dev lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 1234
    link/loopback 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff
```
PiperOrigin-RevId: 684746090
2024-10-11 01:36:07 -07:00
Koichi Shiraishi 0cf77c02f8 all: remove use io/ioutil deprecated package & fix some deprecated thing
Signed-off-by: Koichi Shiraishi <zchee.io@gmail.com>
2024-10-10 20:36:24 +09:00
Kevin KrakauerandgVisor bot 4d37180f89 netstack: remove sniffer.LogPacketsToPCAP
This was always set to 1, with the deteriminant of whether to log PCAP output
instead being whether `sniffer.Endpoint.writer` was non-nil. There's no reason
to keep it around.

PiperOrigin-RevId: 675712237
2024-09-17 14:38:09 -07: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
gVisor bot ac5d20cfb9 Fix some lint issues
PiperOrigin-RevId: 675064804
2024-09-16 02:33:51 -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
Kevin KrakauerandgVisor bot 57902f651c netstack: make sniffer output more consistent and add custom timestamps
DumpPacket() can now be called directly with an optional timestamp value. This
is useful in the child CL.

PiperOrigin-RevId: 670642321
2024-09-03 11:43:27 -07:00
Kevin KrakauerandgVisor bot 7ef3dda2a1 netstack: make sniffer.Endpoint public
There's no reason for it to be private and break the "accept interfaces return
structs" rule.

PiperOrigin-RevId: 670624250
2024-09-03 10:58:10 -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
Nayana BidariandgVisor bot 979bbf238b Mark structs as savable in netstack.
PiperOrigin-RevId: 661475603
2024-08-09 18:26:06 -07:00
Andrei VaginandgVisor bot bcf4aeb94a tcpip/link/veth: don't report CapabilityTXChecksumOffload
While testing docker-in-gvisor, we found that veth devices with enabled
CapabilityTXChecksumOffload don't work as expected. Packets issued from the
gvisor sandbox have incorrect checksum-s.

PiperOrigin-RevId: 651157380
2024-07-10 14:43:54 -07:00
Andrei VaginandgVisor bot 2d9b51ec34 Automated rollback of changelist 651095633
PiperOrigin-RevId: 651133212
2024-07-10 13:33:08 -07:00
Lucas ManningandgVisor bot bd58900fba Change veth WritePackets to deep clone its list of packets.
The buffers from the buffer package are meant to be copy-on-write, but IP
headers still work with the underlying []byte, so writes are not tracked.
This allows data races in situations where packet buffers are shared
across goroutines.

PiperOrigin-RevId: 650429239
2024-07-08 17:49:45 -07:00
Jing ChenandgVisor bot 096478a2ff Fix the MAC address parse in IFLA_ADDRESS and add the tests.
PiperOrigin-RevId: 650333797
2024-07-08 12:19:08 -07:00
Andrei VaginandgVisor bot 9d1849029e tcpip/link/veth: don't send any packets if another end has been closed
Reported-by: syzbot+077cb394a25e5bfa4ed9@syzkaller.appspotmail.com
PiperOrigin-RevId: 650316007
2024-07-08 11:27:23 -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