Commit Graph

6025 Commits

Author SHA1 Message Date
Andrei Vagin 0bdd79ccd4 kvm: trap mmap syscalls to map new regions to the guest
We install seccomp rules so that the SIGSYS signal is generated for
each mmap system call. Then our signal handler executes the real mmap
syscall and if a new regions is created, it maps it to the guest.

Signed-off-by: Andrei Vagin <avagin@google.com>
2021-09-22 14:39:36 -07:00
Andrei Vagin 981111a9ee kvm/arm: calculate virtual-to-physical mappings only once 2021-09-22 13:41:18 -07:00
AV c1a726e8c5 kvm: fix tests on arm64 2021-09-22 13:41:18 -07:00
Ghanan Gowripalan 5768a147b1 Populate forwarded packet buffer's TransportHeader
Turns out certain features of iptables (e.g. NAT) will not perform
any checks/work unless both the Network and Transport headers are
populated.

With this change, provide the packet directly to the outgoing
network endpoint's `writePacket` method instead of going
through `WriteHeaderIncludedPacket` which expected the headers
to not be set.

PiperOrigin-RevId: 398304004
2021-09-22 12:39:31 -07:00
Fabricio Voznika cc095a6e4c Remove terminal usage from `runsc spec`
Most usages of `runsc spec`+`runsc run` do not expect stdios to be a terminal.

Updates #6619

PiperOrigin-RevId: 398288237
2021-09-22 11:32:11 -07:00
Arthur Sfez 0ed53e5e92 Handle Shutdown on connecting tcp socket
Fixes #6495

PiperOrigin-RevId: 398121921
2021-09-21 17:29:58 -07:00
Arthur Sfez c633a7f9d1 Deliver endpoints to the accept queue synchronously when possible
Before this change, when a new connection was created after receiving
an ACK that matched a SYN-cookie, it was always delivered asynchronously
to the accept queue. There was a chance that the listening endpoint
would process a SYN from another client before the delivery happened,
and the listening endpoint would not know yet that the queue was about
to be full, once the delivery happened.

Now, when an ACK matching a SYN-cookie is received, the new endpoint is
created and moved to the accept queue synchronously, while holding the
accept lock.

Fixes #6545

PiperOrigin-RevId: 398107254
2021-09-21 16:13:18 -07:00
Andrei Vagin c485602ded socket/unix: clean up socket queue after releasing a queue lock
A socket queue can contain sockets (others and this one). We have to avoid
taking locks of the same class where it is possible.

PiperOrigin-RevId: 398100744
2021-09-21 15:39:44 -07:00
Ayush Ranjan 6fccc18560 [lisa] Implement lisafs protocol methods in VFS2 gofer client and fsgofer.
Introduces RPC methods in lisafs. Makes that gofer client use lisafs RPCs
instead of p9 when lisafs is enabled.

Implements the handlers for those methods in fsgofer.

Fixes #5465

PiperOrigin-RevId: 398080310
2021-09-21 14:09:18 -07:00
Ayush Ranjan e819029f3a [lisa] Plumb lisafs through runsc.
lisafs is only supported in VFS2. Added a runsc flag which enables lisafs.
When the flag is enabled, the gofer process and the client communicate using
lisafs protocol instead of 9P.

Added a filesystem option in fsimpl/gofer which indicates if lisafs is being
used. That will be used to gate lisafs on the gofer client.

Note that this change does not make the gofer client use lisafs just yet.

Updates #5465

PiperOrigin-RevId: 397917844
2021-09-20 22:34:01 -07:00
Ghanan Gowripalan 3fe8d7ecf1 Support getsockname for packet sockets
Updates #6621

PiperOrigin-RevId: 397898852
2021-09-20 19:37:57 -07:00
gVisor bot 206d7bb90c Internal change.
PiperOrigin-RevId: 397813331
2021-09-20 12:28:06 -07:00
Ghanan Gowripalan 5951ec5bce Do not allow unbinding network protocol
Once a packet socket is bound to a network protocol, it cannot be
unbound from that protocol; the network protocol binding may only be
updated to a different network protocol.

To comply with Linux.

PiperOrigin-RevId: 397810878
2021-09-20 12:17:13 -07:00
Ayush Ranjan d139087b3f [lisa] lisafs package POC.
This change mainly aims to define the semantics of communication for the LISAFS
(LInux SAndbox Filesystem) protocol. This protocol aims to replace 9P and
intends to bring some performance benefits with it.

Some of the notable differences from the p9 package are:
- Now the server implementations own the handlers.
- As a result, there is no verbose interface like `p9.File` that all servers
  need to implement. Different implementations can extend their File
  implementations to varying degrees without imposing those extensions to other
  server implementations that might not have anything to do with those features.
- If a server implementation adds a new RPC message, other implementations are
  not compelled to support it.

I wrote a benchmark `BenchmarkSendRecv` in connection_test.go which competes
with p9's `BenchmarkSendRecvChannel`. Running these on an AMD Milan machine
shows that lisafs is **45%** faster.

**With 9P**
goos: linux
goarch: amd64
pkg: gvisor/pkg/p9/p9
cpu: AMD EPYC 7B13 64-Core Processor
BenchmarkSendRecvLegacy-256     82830     14053 ns/op     633 B/op     23 allocs/op
BenchmarkSendRecvChannel-256     776971     1551 ns/op     184 B/op     6 allocs/op

**With lisafs**
goos: linux
goarch: amd64
pkg: pkg/lisafs/connection_test
cpu: AMD EPYC 7B13 64-Core Processor
BenchmarkSendRecv-256     1399610     853.5 ns/op     48 B/op     2 allocs/op

Fixes #5464

PiperOrigin-RevId: 397803163
2021-09-20 11:44:11 -07:00
Ghanan Gowripalan 89a0011c10 Support IPV6_RECVPKTINFO on UDP sockets
PiperOrigin-RevId: 397631833
2021-09-19 13:15:28 -07:00
Nicolas stig124 FORMICHELLA cdf61f3a40
Deprecating apt-key
As apt-key got deprecated in Debian 11 and will be deleted from Debian 12
Replace apt-key by the supported keyring + signed-by method

Related : docker/docker.github.io#11625
Debian wiki : https://wiki.debian.org/DebianRepository/UseThirdParty

Signed-off-by: Nicolas stig124 FORMICHELLA <stigpro@outlook.fr>
2021-09-19 15:35:22 +02:00
Bruno Dal Bo 09477db2bc Avoid ambient clock on ICMP Rate Limiter
PiperOrigin-RevId: 397496920
2021-09-18 06:00:35 -07:00
gVisor bot 21b38e8bcc Merge pull request #6182 from zchee:atomicbitops-bp
PiperOrigin-RevId: 397432940
2021-09-17 17:48:24 -07:00
Ghanan Gowripalan 7dacdbef52 Allow rebinding packet socket protocol
...to change the network protocol a packet socket may receive packets
from.

This CL is a portion of an originally larger CL that was split with
a8ad692fd3
being the dependent CL. That CL (accidentally) included the change in
the endpoint's `afterLoad` method to take the required lock when
accessing the endpoint's netProto field. That change should have been in
this CL.

The CL that made the change mentioned in the commit message is
cl/396946187.

PiperOrigin-RevId: 397412582
2021-09-17 15:37:08 -07:00
Ghanan Gowripalan 4076153be6 Fix lock ordering violation
This fixes a lock ordering violations introduced in
ae3bd32011
and 477d7e5e10
when connecting/binding sockets races with handling of packets/errors as
the connect/bind path takes the transport/internal/network.Endpoint.mu
lock before taking stack.endpointsByNIC.mu but the locks are taken in the
reverse order when handling packets/errors.

The fix is to revert the change to use a lock instead of atomics in
477d7e5e10
and introduce a new lock protecting only the endpoint info in
transport/internal/network.Endpoint.

```
goroutine 60 [semacquire]:
sync.runtime_Semacquire(0x62c957)
	go/gc/src/runtime/sema.go:56 +0x25
gvisor/pkg/sync/sync.(*CrossGoroutineRWMutex).RLock(0xc0006c4870)
	gvisor/pkg/sync/rwmutex_unsafe.go:76 +0x57
gvisor/pkg/sync/sync.(*RWMutex).RLock(...)
	gvisor/pkg/sync/rwmutex_unsafe.go:254
gvisor/pkg/tcpip/transport/internal/network/network.(*Endpoint).State(0xc0006c4858)
	gvisor/pkg/tcpip/transport/internal/network/endpoint.go:123 +0x3c
gvisor/pkg/tcpip/transport/udp/udp.(*endpoint).HandleError(0xc0006c4840, {0x1c3a418, 0x2847498}, 0xc0006bdeea)
	gvisor/pkg/tcpip/transport/udp/endpoint.go:983 +0x5c
gvisor/pkg/tcpip/stack/stack.(*endpointsByNIC).handleError(0xc00003dd70, 0xc0000f08c0, {0x75e1, {0xc0005da110, 0x10}, 0xdeea, {0xc0005da120, 0x10}}, {0x1c3a418, 0x2847498}, ...)
	gvisor/pkg/tcpip/stack/transport_demuxer.go:203 +0x254
gvisor/pkg/tcpip/stack/stack.(*transportDemuxer).deliverError(0xc00047c588, 0xc000688ca8, 0x86dd, 0x11, {0x1c3a418, 0x2847498}, 0xdf2345, {0x75e1, {0xc0005da110, 0x10}, ...})
	gvisor/pkg/tcpip/stack/transport_demuxer.go:631 +0x205
gvisor/pkg/tcpip/stack/stack.(*nic).DeliverTransportError(0xc0000f08c0, {0xc0005da110, 0x10}, {0xc0005da120, 0x10}, 0x62c985, 0x0, {0x1c3a418, 0x2847498}, 0xc000299000)
	gvisor/pkg/tcpip/stack/nic.go:922 +0x253
gvisor/pkg/tcpip/network/ipv6/ipv6.(*endpoint).handleControl(0xc00045d000, {0x1c3a418, 0x2847498}, 0xc000299000)
	gvisor/pkg/tcpip/network/ipv6/icmp.go:209 +0x3ac
gvisor/pkg/tcpip/network/ipv6/ipv6.(*endpoint).handleICMP(0xc00045d000, 0xc000299000, 0x0, 0x10)
	gvisor/pkg/tcpip/network/ipv6/icmp.go:353 +0x96c
gvisor/pkg/tcpip/network/ipv6/ipv6.(*endpoint).processExtensionHeaders(0xc00045d000, {0xc0005b7f0e, 0x28, 0x30}, 0xc000299000, 0x0)
	gvisor/pkg/tcpip/network/ipv6/ipv6.go:1554 +0x849
gvisor/pkg/tcpip/network/ipv6/ipv6.(*endpoint).handleValidatedPacket(0xc00045d000, {0xc0005b7f0e, 0x28, 0x2b206370203a3033}, 0xc000299000, {0x18baf5d, 0x2})
	gvisor/pkg/tcpip/network/ipv6/ipv6.go:1191 +0x396
gvisor/pkg/tcpip/network/ipv6/ipv6.(*endpoint).HandlePacket(0xc00045d000, 0xc000031310)
	gvisor/pkg/tcpip/network/ipv6/ipv6.go:1107 +0x538
gvisor/pkg/tcpip/stack/stack.(*nic).DeliverNetworkPacket(0xc0000f08c0, {0x0, 0xc000688c38}, {0xc0005da09a, 0x6}, 0x86dd, 0xc000299000)
	gvisor/pkg/tcpip/stack/nic.go:779 +0x3fd
gvisor/pkg/tcpip/link/nested/nested.(*Endpoint).DeliverNetworkPacket(0xc0003d1f10, {0xc0005da08a, 0x6}, {0xc0005da09a, 0x6}, 0x62c985, 0x962610)
	gvisor/pkg/tcpip/link/nested/nested.go:59 +0xd1
gvisor/pkg/tcpip/link/sniffer/sniffer.(*endpoint).DeliverNetworkPacket(0xc0003d1f10, {0xc0005da08a, 0x6}, {0xc0005da09a, 0x6}, 0x610f56, 0x6)
	gvisor/pkg/tcpip/link/sniffer/sniffer.go:140 +0x87
gvisor/pkg/tcpip/link/nested/nested.(*Endpoint).DeliverNetworkPacket(0xc0005200f0, {0xc0005da08a, 0x6}, {0xc0005da09a, 0x6}, 0x397800, 0x200)
	gvisor/pkg/tcpip/link/nested/nested.go:59 +0xd1
gvisor/pkg/tcpip/link/ethernet/ethernet.(*Endpoint).DeliverNetworkPacket(0xc0005200f0, {0xc0005032c0, 0x4}, {0x4, 0x26e}, 0x60d600, 0x6)
	gvisor/pkg/tcpip/link/ethernet/ethernet.go:63 +0x1ad
gvisor/pkg/tcpip/link/loopback/loopback.(*endpoint).WriteRawPacket(0xc00019a540, 0xc000298f00)
	gvisor/pkg/tcpip/link/loopback/loopback.go:107 +0x191
gvisor/pkg/tcpip/link/loopback/loopback.(*endpoint).WritePacket(0x62c985, {{{0xc0005da060, 0x10}, {0xc0005da070, 0x10}, {0x1bf6590, 0x6}, {0x0, 0x0}, 0x86dd, ...}, ...}, ...)
	gvisor/pkg/tcpip/link/loopback/loopback.go:80 +0x37
gvisor/pkg/tcpip/link/nested/nested.(*Endpoint).WritePacket(...)
	gvisor/pkg/tcpip/link/nested/nested.go:107
gvisor/pkg/tcpip/link/ethernet/ethernet.(*Endpoint).WritePacket(0xc0005200f0, {{{0xc0005da060, 0x10}, {0xc0005da070, 0x10}, {0x1bf6590, 0x6}, {0x0, 0x0}, 0x86dd, ...}, ...}, ...)
	gvisor/pkg/tcpip/link/ethernet/ethernet.go:78 +0x142
gvisor/pkg/tcpip/link/nested/nested.(*Endpoint).WritePacket(...)
	gvisor/pkg/tcpip/link/nested/nested.go:107
gvisor/pkg/tcpip/link/sniffer/sniffer.(*endpoint).WritePacket(0xc0003d1f10, {{{0xc0005da060, 0x10}, {0xc0005da070, 0x10}, {0x1bf6590, 0x6}, {0x0, 0x0}, 0x86dd, ...}, ...}, ...)
	gvisor/pkg/tcpip/link/sniffer/sniffer.go:169 +0x108
gvisor/pkg/tcpip/stack/stack.(*nic).writePacket(0xc0000f08c0, {{{0xc0005da060, 0x10}, {0xc0005da070, 0x10}, {0x1bf6590, 0x6}, {0x0, 0x0}, 0x86dd, ...}, ...}, ...)
	gvisor/pkg/tcpip/stack/nic.go:380 +0x264
gvisor/pkg/tcpip/stack/stack.(*nic).writePacketBuffer(0xc0006c3540, {{{0xc0005da060, 0x10}, {0xc0005da070, 0x10}, {0x1bf6590, 0x6}, {0x0, 0x0}, 0x86dd, ...}, ...}, ...)
	gvisor/pkg/tcpip/stack/nic.go:324 +0xec
gvisor/pkg/tcpip/stack/stack.(*nic).enqueuePacketBuffer(0xc0000f08c0, 0x62c985, 0xfc2c55, {0x1bfdac0, 0xc000298f00})
	gvisor/pkg/tcpip/stack/nic.go:339 +0x234
gvisor/pkg/tcpip/stack/stack.(*nic).WritePacket(0xc000298f00, 0xffd8, 0x41a000, 0x4)
	gvisor/pkg/tcpip/stack/nic.go:317 +0x50
gvisor/pkg/tcpip/network/ipv6/ipv6.(*endpoint).writePacket(0xc00045d000, 0xc0006c3540, 0xc000298f00, 0x3, 0x0)
	gvisor/pkg/tcpip/network/ipv6/ipv6.go:823 +0x427
gvisor/pkg/tcpip/network/ipv6/ipv6.(*endpoint).WritePacket(0xc00045d000, 0xc0006c3540, {0x86dd, 0x0, 0x0}, 0xc000298f00)
	gvisor/pkg/tcpip/network/ipv6/ipv6.go:774 +0x2db
gvisor/pkg/tcpip/stack/stack.(*Route).WritePacket(0xc0006c3540, {0x37a9f0, 0xc0, 0x0}, 0x86dd)
	gvisor/pkg/tcpip/stack/route.go:462 +0xe4
gvisor/pkg/tcpip/network/ipv6/ipv6.(*protocol).returnError(0xc000298400, {0x1c253e8, 0x2847498}, 0xc000298e00)
	gvisor/pkg/tcpip/network/ipv6/icmp.go:1277 +0x15f8
gvisor/pkg/tcpip/network/ipv6/ipv6.(*endpoint).processExtensionHeaders(0xc00045d000, {0xc0005b7ece, 0x28, 0x30}, 0xc000298e00, 0x0)
	gvisor/pkg/tcpip/network/ipv6/ipv6.go:1565 +0x12e5
gvisor/pkg/tcpip/network/ipv6/ipv6.(*endpoint).handleValidatedPacket(0xc00045d000, {0xc0005b7ece, 0x28, 0x0}, 0xc000298e00, {0x18baf5d, 0x2})
	gvisor/pkg/tcpip/network/ipv6/ipv6.go:1191 +0x396
gvisor/pkg/tcpip/network/ipv6/ipv6.(*endpoint).HandlePacket(0xc00045d000, 0xc0003df610)
	gvisor/pkg/tcpip/network/ipv6/ipv6.go:1107 +0x538
gvisor/pkg/tcpip/stack/stack.(*nic).DeliverNetworkPacket(0xc0000f08c0, {0x0, 0xc000688838}, {0xc000663fea, 0x6}, 0x86dd, 0xc000298e00)
	gvisor/pkg/tcpip/stack/nic.go:779 +0x3fd
gvisor/pkg/tcpip/link/nested/nested.(*Endpoint).DeliverNetworkPacket(0xc0003d1f10, {0xc000663fda, 0x6}, {0xc000663fea, 0x6}, 0x62c985, 0x962610)
	gvisor/pkg/tcpip/link/nested/nested.go:59 +0xd1
gvisor/pkg/tcpip/link/sniffer/sniffer.(*endpoint).DeliverNetworkPacket(0xc0003d1f10, {0xc000663fda, 0x6}, {0xc000663fea, 0x6}, 0x610f56, 0x6)
	gvisor/pkg/tcpip/link/sniffer/sniffer.go:140 +0x87
gvisor/pkg/tcpip/link/nested/nested.(*Endpoint).DeliverNetworkPacket(0xc0005200f0, {0xc000663fda, 0x6}, {0xc000663fea, 0x6}, 0x397800, 0x200)
	gvisor/pkg/tcpip/link/nested/nested.go:59 +0xd1
gvisor/pkg/tcpip/link/ethernet/ethernet.(*Endpoint).DeliverNetworkPacket(0xc0005200f0, {0xc00003dec0, 0x2}, {0x2, 0x23e}, 0x60d600, 0x6)
	gvisor/pkg/tcpip/link/ethernet/ethernet.go:63 +0x1ad
gvisor/pkg/tcpip/link/loopback/loopback.(*endpoint).WriteRawPacket(0xc00019a540, 0xc000298d00)
	gvisor/pkg/tcpip/link/loopback/loopback.go:107 +0x191
gvisor/pkg/tcpip/link/loopback/loopback.(*endpoint).WritePacket(0x62c985, {{{0xc000663fa0, 0x10}, {0xc000378f40, 0x10}, {0x1bf6590, 0x6}, {0x0, 0x0}, 0x86dd, ...}, ...}, ...)
	gvisor/pkg/tcpip/link/loopback/loopback.go:80 +0x37
gvisor/pkg/tcpip/link/nested/nested.(*Endpoint).WritePacket(...)
	gvisor/pkg/tcpip/link/nested/nested.go:107
gvisor/pkg/tcpip/link/ethernet/ethernet.(*Endpoint).WritePacket(0xc0005200f0, {{{0xc000663fa0, 0x10}, {0xc000378f40, 0x10}, {0x1bf6590, 0x6}, {0x0, 0x0}, 0x86dd, ...}, ...}, ...)
	gvisor/pkg/tcpip/link/ethernet/ethernet.go:78 +0x142
gvisor/pkg/tcpip/link/nested/nested.(*Endpoint).WritePacket(...)
	gvisor/pkg/tcpip/link/nested/nested.go:107
gvisor/pkg/tcpip/link/sniffer/sniffer.(*endpoint).WritePacket(0xc0003d1f10, {{{0xc000663fa0, 0x10}, {0xc000378f40, 0x10}, {0x1bf6590, 0x6}, {0x0, 0x0}, 0x86dd, ...}, ...}, ...)
	gvisor/pkg/tcpip/link/sniffer/sniffer.go:169 +0x108
gvisor/pkg/tcpip/stack/stack.(*nic).writePacket(0xc0000f08c0, {{{0xc000663fa0, 0x10}, {0xc000378f40, 0x10}, {0x1bf6590, 0x6}, {0x0, 0x0}, 0x86dd, ...}, ...}, ...)
	gvisor/pkg/tcpip/stack/nic.go:380 +0x264
gvisor/pkg/tcpip/stack/stack.(*nic).writePacketBuffer(0xc0006c2fa0, {{{0xc000663fa0, 0x10}, {0xc000378f40, 0x10}, {0x1bf6590, 0x6}, {0x0, 0x0}, 0x86dd, ...}, ...}, ...)
	gvisor/pkg/tcpip/stack/nic.go:324 +0xec
gvisor/pkg/tcpip/stack/stack.(*nic).enqueuePacketBuffer(0xc0000f08c0, 0x62c985, 0xfc2c55, {0x1bfdac0, 0xc000298d00})
	gvisor/pkg/tcpip/stack/nic.go:339 +0x234
gvisor/pkg/tcpip/stack/stack.(*nic).WritePacket(0xc000298d00, 0xffd8, 0x41a000, 0x4)
	gvisor/pkg/tcpip/stack/nic.go:317 +0x50
gvisor/pkg/tcpip/network/ipv6/ipv6.(*endpoint).writePacket(0xc00045d000, 0xc0006c2fa0, 0xc000298d00, 0x3, 0x0)
	gvisor/pkg/tcpip/network/ipv6/ipv6.go:823 +0x427
gvisor/pkg/tcpip/network/ipv6/ipv6.(*endpoint).WritePacket(0xc00045d000, 0xc0006c2fa0, {0x86dd, 0x0, 0x0}, 0xc000298d00)
	gvisor/pkg/tcpip/network/ipv6/ipv6.go:774 +0x2db
gvisor/pkg/tcpip/stack/stack.(*Route).WritePacket(0xc0006c2fa0, {0x2080000, 0xea, 0xde}, 0x6)
	gvisor/pkg/tcpip/stack/route.go:462 +0xe4
gvisor/pkg/tcpip/transport/internal/network/network.(*WriteContext).WritePacket(0xc0003e05e0, 0xc000298d00, 0x0)
	gvisor/pkg/tcpip/transport/internal/network/endpoint.go:212 +0x154
gvisor/pkg/tcpip/transport/udp/udp.(*endpoint).write(0xc0006c4840, {0x1c23ad0, 0xc0006cfd60}, {0xc0002ecf00, 0xf0, 0xdb, 0x3})
	gvisor/pkg/tcpip/transport/udp/endpoint.go:457 +0x74c
gvisor/pkg/tcpip/transport/udp/udp.(*endpoint).Write(0xc0006c4840, {0x1c23ad0, 0xc0006cfd60}, {0xc0002ecf00, 0x85, 0xc9, 0x62})
	gvisor/pkg/tcpip/transport/udp/endpoint.go:323 +0x74

goroutine 133 [semacquire]:
sync.runtime_Semacquire(0xc00003dd70)
	go/gc/src/runtime/sema.go:56 +0x25
gvisor/pkg/sync/sync.(*CrossGoroutineRWMutex).Lock(0xc00003dd70)
	gvisor/pkg/sync/rwmutex_unsafe.go:151 +0x79
gvisor/pkg/sync/sync.(*RWMutex).Lock(...)
	gvisor/pkg/sync/rwmutex_unsafe.go:286
gvisor/pkg/tcpip/stack/stack.(*endpointsByNIC).unregisterEndpoint(0xc00003dd70, 0x37a300, {0x1c3a558, 0xc0006c4840}, {0x0, 0x0, 0x0})
	gvisor/pkg/tcpip/stack/transport_demuxer.go:246 +0x72
gvisor/pkg/tcpip/stack/stack.(*transportEndpoints).unregisterEndpoint(0xc0004b3f40, {0x75e1, {0x0, 0x0}, 0x0, {0x0, 0x0}}, {0x1c3a558, 0xc0006c4840}, {0x0, ...}, ...)
	gvisor/pkg/tcpip/stack/transport_demuxer.go:52 +0x193
gvisor/pkg/tcpip/stack/stack.(*transportDemuxer).unregisterEndpoint(0xc00047c588, {0xc000663fc8, 0x2, 0x0}, 0x11, {0x75e1, {0x0, 0x0}, 0x0, {0x0, ...}}, ...)
	gvisor/pkg/tcpip/stack/transport_demuxer.go:527 +0x1d4
gvisor/pkg/tcpip/stack/stack.(*Stack).UnregisterTransportEndpoint(...)
	gvisor/pkg/tcpip/stack/stack.go:1417
gvisor/pkg/tcpip/transport/udp/udp.(*endpoint).Connect.func1(0x86dd, {0x75e1, {0x0, 0x0}, 0x0, {0x0, 0x0}}, {0x75e1, {0x0, 0x0}, ...})
	gvisor/pkg/tcpip/transport/udp/endpoint.go:619 +0x433
gvisor/pkg/tcpip/transport/internal/network/network.(*Endpoint).ConnectAndThen(0xc0006c4858, {0x0, {0xc000144270, 0xa0000eade88c0}, 0xabc5}, 0xc000353518)
	gvisor/pkg/tcpip/transport/internal/network/endpoint.go:408 +0x3cc
gvisor/pkg/tcpip/transport/udp/udp.(*endpoint).Connect(0xc0006c4840, {0x37b9e0, {0xc000144270, 0xc000328a80}, 0xc1a0})
	gvisor/pkg/tcpip/transport/udp/endpoint.go:593 +0x149
```

PiperOrigin-RevId: 397412256
2021-09-17 15:32:04 -07:00
Ghanan Gowripalan b28bd31bb6 Allow creating packet socket bound to any protocol
...even protocols the stack is unaware of.

While I am here, annotate checklocks on stack.packetEndpointList.

PiperOrigin-RevId: 397226754
2021-09-16 20:06:26 -07:00
Ghanan Gowripalan 85bd3dd9b1 Annotate checklocks on mutex protected fields
...to catch lock-related bugs in nogo tests.

Checklocks also pointed out a locking violation which is fixed
in this change.

Updates #6566.

PiperOrigin-RevId: 397225322
2021-09-16 19:52:51 -07:00
Ghanan Gowripalan eccd46e67c Rename packet_socket to packet_socket_dgram
...so that a later change can add a new packet_socket syscall test
target that holds raw/dgram packet socket generic common tests. The
current packet_socket syscall test target holds tests specific to
dgram packet sockets.

While I am here, remove the defines for the packet_socket_raw_test
target as no code is guarded with `__linux__` in the target's sources.

PiperOrigin-RevId: 397217761
2021-09-16 18:56:08 -07:00
Jamie Liu 51b96514cd Limit most file mmaps to the range of an int64.
In the general case, files may have offsets between MaxInt64 and MaxUint64; in
Linux pgoff is consistently represented by an unsigned long, and in gVisor the
offset types in memmap.MappableRange are uint64. However, regular file mmap is
constrained to int64 offsets (on 64-bit systems) by
mm/mmap.c:file_mmap_size_max() => MAX_LFS_FILESIZE == LLONG_MAX.

As a related fix, check for chunkStart overflow in fsutil.HostFileMapper; chunk
offsets are uint64s, but as noted above some file types may use uint64 offsets
beyond MaxInt64.

Reported-by: syzbot+71342a1585aed97ed9f7@syzkaller.appspotmail.com
PiperOrigin-RevId: 397136751
2021-09-16 12:12:59 -07:00
Ghanan Gowripalan 282a4dd52b Don't allow binding to broadcast on ICMP sockets
...to match Linux behaviour.

Fixes #5711.

PiperOrigin-RevId: 397132671
2021-09-16 11:53:49 -07:00
gVisor bot eb07b91e61 Merge pull request #6579 from prattmic:runsc_do_profile
PiperOrigin-RevId: 397114051
2021-09-16 10:37:45 -07:00
Michael Pratt bd296e799b runsc: add global profile collection flags
Add global flags -profile-{block,cpu,heap,mutex} and -trace which
enable collection of the specified profile for the entire duration of a
container execution. This provides a way to definitively start profiling
before that application starts, rather than attempting to race with an
out-of-band `runsc debug`.

Note that only the main boot process is profiled.

This exposed a bug in Task.traceExecEvent: a crash when tracing and
-race are enabled. traceExecEvent is called off of the task goroutine,
but uses the Task as a context, which is a violation of the Task
contract. Switching to the AsyncContext fixes the issue.

Fixes #220
2021-09-16 11:20:37 -04:00
Ghanan Gowripalan 477d7e5e10 Annotate checklocks on mutex protected fields
...to catch lock-related bugs in nogo tests.

Also update the endpoint's state field to be accessed while the mutex is
held instead of requiring atomic operations as nothing needs to call the
State method while the mutex is held.

Updates #6566.

PiperOrigin-RevId: 397010316
2021-09-15 23:51:11 -07:00
Ghanan Gowripalan a8ad692fd3 Annotate checklocks on mutex protected fields
...to catch lock-related bugs in nogo tests.

This change also disables/enables packet reception before/after
save/restore with a flag that is protected by rcvMu instead of mu.

Updates #6566.

PiperOrigin-RevId: 396946187
2021-09-15 16:11:43 -07:00
gVisor bot 4e99f17178 Merge pull request #6581 from prattmic:runsc_rootless
PiperOrigin-RevId: 396938550
2021-09-15 15:34:00 -07:00
Tony Gong 8b56b6b83b Pass address properties in a single struct
Replaced the current AddAddressWithOptions method with
AddAddressWithProperties which passes all address properties in
a single AddressProperties type. More properties that need to be
configured in the future are expected, so adding a type makes adding
them easier.

PiperOrigin-RevId: 396930729
2021-09-15 15:00:01 -07:00
Ghanan Gowripalan 149ca00967 [bind] Return EINVAL for under sized address
...and EAFNOSUPPORT for unexpected address family.

To comply with Linux.

Updates #6021, #6575.

PiperOrigin-RevId: 396893590
2021-09-15 12:20:51 -07:00
Michael Pratt 2d9883e4f1 Remove extra newline
PiperOrigin-RevId: 396754242
2021-09-14 21:58:21 -07:00
Ghanan Gowripalan 0bec34a8e2 Compose raw IP with datagram-based endpoint
A raw IP endpoint's write and socket option get/set path can use the
datagram-based endpoint.

This change extracts tests from UDP that may also run on Raw IP sockets.

Updates #6565.
Test: Raw IP + datagram-based socket syscall tests.
PiperOrigin-RevId: 396729727
2021-09-14 18:38:46 -07:00
Ghanan Gowripalan 39470428dd Use a shared method to get loopback index
Code to get the loopback interface's index is scattered throughout the
syscall tests. Implement the code once and use that in tests (where
applicable).

While I am here, trim the dependencies/includes for network namespace
tests.

PiperOrigin-RevId: 396718124
2021-09-14 17:20:30 -07:00
Rahat Mahmood d6c99694bc Fix race on msgrcv(MSG_COPY).
Previously, we weren't making a copy when a sysv message queue was
receiving a message with the MSG_COPY flag. This flag indicates the
message being received should be left in the queue and a copy of the
message should be returned to userspace. Without the copy, a racing
process can modify the original message while it's being marshalled to
user memory.

Reported-by: syzbot+cb15e644698b20ff4e17@syzkaller.appspotmail.com
PiperOrigin-RevId: 396712856
2021-09-14 16:53:30 -07:00
Ghanan Gowripalan 8d14edb14b Explicitly bind endpoint to a NIC
Previously, any time a datagram-based network endpoint (e.g. UDP) was
bound, the bound NIC is always set based on the bound address (if
specified). However, we should only consider the endpoint bound to
an NIC if a NIC was explicitly bound to.

If an endpoint has been bound to an address and attempts to send packets
to an unconnected remote, the endpoint will default to sending packets
through the bound address' NIC if not explicitly bound to a NIC.

Updates #6565.

PiperOrigin-RevId: 396712415
2021-09-14 16:47:19 -07:00
Bhasker Hariharan 603f473ada Fix bug in RecvMMsgDispatcher.
Fixed a bug introduced in the following commit:
979d6e7d77

The commit introduced a bug which causes the recvmmsg dispatcher to never exit
as BlockingPoll is now called with two fds and poll will not return an error
anymore if one of the FD is closed. We need to explicitly check the events for
each FD to determine if the sentry FD is closed.

ReadV dispatcher does not have the same issue as Readv does not rely on sk_err
field of the underlying socket to determine if the socket is in an error
state. Recvmmsg OTOH seems to get confused and always returns EAGAIN if poll()
is called which queries the sk_err field and clears it.

PiperOrigin-RevId: 396676135
2021-09-14 14:09:09 -07:00
Ghanan Gowripalan 5593b8a7e6 Don't use SOL_UDP when creating sockets
SOL_UDP is used when get/set-ing socket options to specify the socket
level. When creating normal UDP sockets, the protocol need not be
specified. When creating RAW IP sockets for UDP, use IPPROTO_UDP.

PiperOrigin-RevId: 396675986
2021-09-14 14:03:53 -07:00
Ghanan Gowripalan 2b46e2d19e Defer mutex unlocking
PiperOrigin-RevId: 396670516
2021-09-14 13:37:33 -07:00
Michael Pratt 5ab2bdf332 runsc: allow rootless mode for runsc run
Rootless mode seems to work fine for simple containers with runsc run,
so allow its use.

Since runsc run is more widely used, require a workable --network option
is passed rather than automatically switching like runsc do does.

Fixes #3036
2021-09-14 16:20:25 -04:00
Ghanan Gowripalan 226e7d32cb Accept packets destined to bound address
...if bound to an address.

We previously checked the source of a packet instead of the destination
of a packet when bound to an address.

PiperOrigin-RevId: 396497647
2021-09-13 19:42:55 -07:00
Etienne Perot 4795e08359 Typo fix.
PiperOrigin-RevId: 396476303
2021-09-13 17:08:44 -07:00
Andrei Vagin 95fe4fea19 tools/show_paths.bzl: check that provider_map isn't None
Otherwise it can fail:
$ bazel cquery pkg/p9/... --output=starlark --starlark:file=tools/show_paths.bzl
...
ERROR: Starlark evaluation error for //pkg/p9/p9test:mockgen:
Traceback (most recent call last):
	File "tools/show_paths.bzl", line 8, column 32, in format
Error: 'NoneType' value has no field or method 'get'
PiperOrigin-RevId: 396457764
2021-09-13 15:35:22 -07:00
Ghanan Gowripalan e07fd058ec Set NICID before delivering packet to raw endpoint
...as raw endpoints expect the packet's NICID to be set.

PiperOrigin-RevId: 396446552
2021-09-13 14:42:49 -07:00
Michael Pratt 9bdeddd882 runsc/cmd: alphabetize runsc debug profiling options
Updates #220
2021-09-13 16:21:37 -04:00
Ghanan Gowripalan 79834ce16c Separate IPv4 ToS & IPv6 TClass in dgram endpoint
Setting the ToS for IPv4 packets (SOL_IP, IP_TOS) should not affect the
Traffic Class of IPv6 packets (SOL_IPV6, IPV6_TCLASS).

Also only return the ToS value XOR Traffic Class as a packet cannot be
both an IPv4 and an IPv6 packet; It is invalid to return both the IPv4
ToS and IPv6 Traffic Class control messages when reading packets.

Updates #6389.

PiperOrigin-RevId: 396399096
2021-09-13 11:15:36 -07:00
Adin Scannell 6bcacb2fd1 Support anonymous structs in checklocks.
Fixes #6558

PiperOrigin-RevId: 396393293
2021-09-13 10:54:24 -07:00
gVisor bot 63b1c736b3 Internal change.
PiperOrigin-RevId: 396155387
2021-09-11 18:04:15 -07:00
Etienne Perot 28853599c4 Typo fix.
PiperOrigin-RevId: 396042572
2021-09-10 17:53:52 -07:00