Commit Graph

2638 Commits

Author SHA1 Message Date
Ghanan Gowripalan dffa4c6690 Don't include link header when forwarding packets
Before this change, if a link header was included in an incoming packet
that is forwarded, the packet that gets sent out will take the original
packet and add a link header to it while keeping the old link header.
This would make the sent packet look like:

   OUTGOING LINK HDR | INCOMING LINK HDR | NETWORK HDR | ...

Obviously this is incorrect as we should drop the incoming link header
and only include the outgoing link header. This change fixes this bug.

Test: integration_test.TestForwarding
PiperOrigin-RevId: 337571447
2020-10-16 13:54:00 -07:00
Julian Elischer 4d27f33b09 Make IPv4 check the IP header checksum
The IPv4 header checksum has not been checked, at least in recent times,
so add code to do so. Fix all the tests that fail because they never
needed to set the checksum.

Fixes #4484

PiperOrigin-RevId: 337556243
2020-10-16 12:31:05 -07:00
Arthur Sfez edc1068244 Enable IPv4 fragmentation for every code path.
Currently, fragmentation can only occur during WritePacket(). This enables
it for WritePackets() and WriteIncludedHeaderPacket() as well.

IPv4 unit tests were refactored to be consistent with the IPv6 unit tests.

This removes the extraHeaderReserveLength field and the related
"prependable bytes" unit tests (for both IPv4 and IPv6) because it was only
testing a panic condition when the value was too low.

Fixes #3796

PiperOrigin-RevId: 337550061
2020-10-16 11:57:27 -07:00
gVisor bot b491712e11 Merge pull request #4387 from lubinszARM:pr_tls_host_sentry_1
PiperOrigin-RevId: 337544656
2020-10-16 11:32:38 -07:00
Ghanan Gowripalan fbfcf8144c Enable IPv6 WriteHeaderIncludedPacket
Allow writing an IPv6 packet where the IPv6 header is a provided by
the user.

* Introduce an error to let callers know a header is malformed.
We previously useed tcpip.ErrInvalidOptionValue but that did not seem
appropriate for generic malformed header errors.

* Populate network header in WriteHeaderIncludedPacket
IPv4's implementation of WriteHeaderIncludedPacket did not previously
populate the packet buffer's network header. This change fixes that.

Fixes #4527

Test: ip_test.TestWriteHeaderIncludedPacket
PiperOrigin-RevId: 337534548
2020-10-16 10:42:34 -07:00
Andrei Vagin c002fc36f9 sockets: ignore io.EOF from view.ReadAt
Reported-by: syzbot+5466463b7604c2902875@syzkaller.appspotmail.com
PiperOrigin-RevId: 337451896
2020-10-15 23:15:48 -07:00
Sam Balana 3269cefd6f Process NAs without target link-layer addresses
RFC 4861 section 4.4 comments the Target link-layer address option is sometimes
optional in a Neighbor Advertisement packet:

  "When responding to a unicast Neighbor Solicitation this option SHOULD be
  included."

Tests:
 pkg/tcpip/stack:stack_test
 - TestEntryStaleToReachableWhenSolicitedConfirmationWithoutAddress
 - TestEntryDelayToReachableWhenSolicitedConfirmationWithoutAddress
 - TestEntryProbeToReachableWhenSolicitedConfirmationWithoutAddress
 pkg/tcpip/network/ipv6:ipv6_test
 - TestCallsToNeighborCache
PiperOrigin-RevId: 337396493
2020-10-15 15:37:01 -07:00
Chong Cai f0f7431ea2 Change verity isEnable to be a member of dentry
PiperOrigin-RevId: 337384146
2020-10-15 14:35:15 -07:00
Arthur Sfez 8f70c6ef35 Refactor compareFragments to follow Go style
Test helpers should be used for test setup/teardown, not actual
testing. Use cmp.Diff instead of bytes.Equal to improve readability.

PiperOrigin-RevId: 337323242
2020-10-15 09:29:01 -07:00
Ghanan Gowripalan 6e6a9d3f3d Find route before sending NA response
This change also brings back the stack.Route.ResolveWith method so that
we can immediately resolve a route when sending an NA in response to a
a NS with a source link layer address option.

Test: ipv6_test.TestNeighorSolicitationResponse
PiperOrigin-RevId: 337185461
2020-10-14 15:29:47 -07:00
Dean Deng fc1e653973 Fix SCM Rights reference leaks.
Control messages should be released on Read (which ignores the control message)
or zero-byte Send. Otherwise, open fds sent through the control messages will
be leaked.

PiperOrigin-RevId: 337110774
2020-10-14 09:54:05 -07:00
Dean Deng a7b7b7b980 Fix shm reference leak.
All shm segments in an IPC namespace should be released once that namespace is
destroyed. Add reference counting to IPCNamespace so that once the last task
with a reference on it exits, we can trigger a destructor that will clean up
all shm segments that have not been explicitly freed by the application.

PiperOrigin-RevId: 337032977
2020-10-14 00:13:21 -07:00
gVisor bot 7eeeff4268 Merge pull request #4482 from lemin9538:lemin_arm64
PiperOrigin-RevId: 336976081
2020-10-13 16:12:20 -07:00
gVisor bot 443e3cad4a Merge pull request #4486 from patr0nus:master_udp_ep_fix
PiperOrigin-RevId: 336974095
2020-10-13 16:01:58 -07:00
gVisor bot dbe122c92f Merge pull request #4386 from lubinszARM:pr_testutil_tls_usr
PiperOrigin-RevId: 336970511
2020-10-13 15:42:24 -07:00
gVisor bot b99f15e06d Merge pull request #4374 from lubinszARM:pr_ffmpeg_kvm_01
PiperOrigin-RevId: 336962937
2020-10-13 15:02:57 -07:00
Sam Balana 51913ba400 Correct NA minimum size
Remove the duplicate NA size variable while I'm here.

See https://tools.ietf.org/html/rfc4861#section-4.4 for the packet format.

PiperOrigin-RevId: 336943206
2020-10-13 13:28:26 -07:00
Jamie Liu 1a69487373 Don't read beyond EOF when inserting into sentry page cache.
The sentry page cache stores file contents at page granularity; this is
necessary for memory mappings. Thus file offset ranges passed to
fsutil.FileRangeSet.Fill() must be page-aligned. If the read callback passed to
Fill() returns (partial read, nil error) when reading up to EOF (which is the
case for p9.ClientFile.ReadAt() since 9P's Rread cannot convey both a partial
read and EOF), Fill() will re-invoke the read callback to try to read from EOF
to the end of the containing page, which is harmless but needlessly expensive.
Fix this by handling file size explicitly in fsutil.FileRangeSet.Fill().

PiperOrigin-RevId: 336934075
2020-10-13 12:45:51 -07:00
Tamir Duberstein 7053f17859 Use NDP option serializer instead of handcrafting the NS
Use the correct constant (Solicit, not Advert) while I'm here.

PiperOrigin-RevId: 336924605
2020-10-13 12:00:20 -07:00
Dean Deng 432963dd2d [vfs2] Don't take reference in Task.MountNamespaceVFS2 and MountNamespace.Root.
This fixes reference leaks related to accidentally forgetting to DecRef()
after calling one or the other.

PiperOrigin-RevId: 336918922
2020-10-13 11:31:22 -07:00
Adin Scannell d9b32efb30 Avoid excessive Tgkill and wait operations.
The required states may simply not be observed by the thread running bounce, so
track guest and user generations to ensure that at least one of the desired
state transitions happens.

Fixes #3532

PiperOrigin-RevId: 336908216
2020-10-13 10:43:45 -07:00
Dean Deng 60f159b558 [vfs2] Destroy all tmpfs files when the filesystem is released.
In addition to fixing reference leaks, this change also releases memory used
by regular tmpfs files once the containing filesystem is released.

PiperOrigin-RevId: 336833111
2020-10-13 01:55:00 -07:00
Dean Deng 577c82f22c [vfs2] Add FilesystemType.Release to avoid reference leaks.
Singleton filesystem like devpts and devtmpfs have a single filesystem shared
among all mounts, so they acquire a "self-reference" when initialized that
must be released when the entire virtual filesystem is released at sandbox
exit.

PiperOrigin-RevId: 336828852
2020-10-13 01:13:22 -07:00
Dean Deng fc7df53222 Don't leak VDSO mappings.
PiperOrigin-RevId: 336822021
2020-10-13 00:14:15 -07:00
Chong Cai 4885931ac3 Change verity mu to be per file system
verity Mu should be per file system instead of global, so that enabling
and verifying in different file systems won't block each other.
Also Lock verity Mu in PRead.

PiperOrigin-RevId: 336779356
2020-10-12 17:35:22 -07:00
Chong Cai ef90fe1733 Change Merkle tree library to use ReaderAt
Merkle tree library was originally using Read/Seek to access data and
tree, since the parameters are io.ReadSeeker. This could cause race
conditions if multiple threads accesses the same fd to read. Here we
change to use ReaderAt, and implement it with PRead to make it thread
safe.

PiperOrigin-RevId: 336779260
2020-10-12 17:30:14 -07:00
Ayush Ranjan e7bbe70f79 [vfs] kernfs: Fix inode memory leak issue.
This change aims to fix the memory leak issue reported in #3933.

Background:
VFS2 kernfs kept accumulating invalid dentries if those dentries were not
walked on. After substantial consideration of the problem by our team, we
decided to have an LRU cache solution. This change is the first part to that
solution, where we don't cache anything. The LRU cache can be added on top of
this.

What has changed:
- Introduced the concept of an inode tree in kernfs.OrderedChildren.
  This is helpful is cases where the lifecycle of an inode is different from
  that of a dentry.
    - OrderedChildren now deals with initialized inodes instead of initialized
      dentries. It now implements Lookup() where it constructs a new dentry
      using the inode.
    - OrderedChildren holds a ref on all its children inodes. With this change,
      now an inode can "outlive" a dentry pointing to it. See comments in
      kernfs.OrderedChildren.
- The kernfs dentry tree is solely maintained by kernfs only. Inode
  implementations can not modify the dentry tree.
- Dentries that reach ref count 0 are removed from the dentry tree.
- revalidateChildLocked now defer-DecRefs the newly created dentry from
  Inode.Lookup(), limiting its life to the current filesystem operation. If
  refs are picked on the dentry during the FS op (via an FD or something),
  then it will stick around and will be removed when the FD is closed. So there
  is essentially _no caching_ for Look()ed up dentries.
- kernfs.DecRef does not have the precondition that fs.mu must be locked.

Fixes #3933

PiperOrigin-RevId: 336768576
2020-10-12 16:29:33 -07:00
gVisor bot 93bc0777be Merge pull request #4072 from adamliyi:droppt_fix
PiperOrigin-RevId: 336719900
2020-10-12 12:34:43 -07:00
Dean Deng d861cd5f14 [vfs2] Don't leak disconnected mounts.
PiperOrigin-RevId: 336694658
2020-10-12 10:41:04 -07:00
Bin Lu 1557153cad arm64 kvm: add tls-usr support
The tls of guest-el1-sentry and host-el0-sentry may be different on Arm64.
I added a solution for it.

Signed-off-by: Bin Lu <bin.lu@arm.com>
2020-10-11 23:32:54 -04:00
patr0nus d4413c31bd Assign ep.effectiveNetProtos in UDP forwarder's CreateEndpoint 2020-10-11 17:42:17 +08:00
Min Le 2ae97b27aa arm64: set DZE bit to make EL0 can use DC ZVA
Signed-off-by: Min Le <lemin.lm@antgroup.com>
2020-10-10 16:50:51 +08:00
Bhasker Hariharan db36d948fa TCP Receive window advertisement fixes.
The fix in commit 028e045da9 was incorrect as
it can cause the right edge of the window to shrink when we announce
a zero window due to receive buffer being full as its done before the check
for seeing if the window is being shrunk because of the selected window.

Further the window was calculated purely on available space but in cases where
we are getting full sized segments it makes more sense to use the actual bytes
being held. This CL changes to use the lower of the total available space vs
the available space in the maximal window we could advertise minus the actual
payload bytes being held.

This change also cleans up the code so that the window selection logic is
not duplicated between getSendParams() and windowCrossedACKThresholdLocked.

PiperOrigin-RevId: 336404827
2020-10-09 19:02:03 -07:00
Nayana Bidari d75fe7660a RACK: Detect packet reordering.
RACK detects packet reordering by checking if the sender received ACK for
the packet which has the sequence number less than the already acknowledged
packets.

PiperOrigin-RevId: 336397526
2020-10-09 17:47:23 -07:00
Chong Cai 5389e441a5 Include stat in Verity hash
PiperOrigin-RevId: 336395445
2020-10-09 17:29:34 -07:00
Andrei Vagin a0ffc84adf platform/kvm: remove the unused field
PiperOrigin-RevId: 336366624
2020-10-09 14:34:51 -07:00
gVisor bot 6df400dfb6 Merge pull request #4040 from lemin9538:lemin_arm64
PiperOrigin-RevId: 336362818
2020-10-09 14:14:03 -07:00
Jamie Liu 6bbf662271 Reduce the cost of sysinfo(2).
- sysinfo(2) does not actually require a fine-grained breakdown of memory
  usage. Accordingly, instead of calling pgalloc.MemoryFile.UpdateUsage() to
  update the sentry's fine-grained memory accounting snapshot, just use
  pgalloc.MemoryFile.TotalUsage() (which is a single fstat(), and therefore far
  cheaper).

- Use the number of threads in the root PID namespace (i.e. globally) rather
  than in the task's PID namespace for consistency with Linux (which just reads
  global variable nr_threads), and add a new method to kernel.PIDNamespace to
  allow this to be read directly from an underlying map rather than requiring
  the allocation and population of an intermediate slice.

PiperOrigin-RevId: 336353100
2020-10-09 13:23:30 -07:00
Ghanan Gowripalan 257703c050 Automated rollback of changelist 336304024
PiperOrigin-RevId: 336339194
2020-10-09 12:09:12 -07:00
Andrei Vagin 76a09f0cf5 syscalls: Don't leak a file on the error path
Reported-by: syzbot+bb82fb556d5d0a43f632@syzkaller.appspotmail.com
PiperOrigin-RevId: 336324720
2020-10-09 10:57:27 -07:00
Bhasker Hariharan 8566decab0 Automated rollback of changelist 336185457
PiperOrigin-RevId: 336304024
2020-10-09 09:11:18 -07:00
Ghanan Gowripalan 07b1d7413e Only block resolution when NUD is incomplete
When a completed entry exists for a neighbor, there is no need to block
while reachability is (re)confirmed. The stack should continue to use
the neighbor's link address while NUD is performed.

Test: stack_test.TestNeighborCacheReplace
PiperOrigin-RevId: 336199043
2020-10-08 17:34:28 -07:00
Jamie Liu 6bad4851d4 Implement MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ.
cf. 2a36ab717e8f "rseq/membarrier: Add MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ"

PiperOrigin-RevId: 336186795
2020-10-08 16:23:04 -07:00
Ghanan Gowripalan 6768e6c59e Do not resolve routes immediately
When a response needs to be sent to an incoming packet, the stack should
consult its neighbour table to determine the remote address's link
address.

When an entry does not exist in the stack's neighbor table, the stack
should queue the packet while link resolution completes. See comments.

PiperOrigin-RevId: 336185457
2020-10-08 16:15:59 -07:00
Ghanan Gowripalan 40269d0c24 Send unicast probes when link address is known
When the neighbor table already has link address for a neighbor but is
trying to confirm reachability, it may send unicast probes to the
neighbor.

PiperOrigin-RevId: 336166711
2020-10-08 14:36:14 -07:00
Min Le 190cf30e41 arm64: the mair_el1 value is wrong
the correct value needed is 0xbbff440c0400 but the const
defined is 0x000000000000ffc0 due to the operator error
in _MT_EL1_INIT, both kernel and user space memory
attribute should be Normal memory not DEVICE_nGnRE

Signed-off-by: Min Le <lemin.lm@antgroup.com>
2020-10-08 20:33:09 +08:00
Arthur Sfez 0c3134028d Change IPv6 reassembly timeout to 60s
It was originally set to 30s for IPv6 (same as IPv4) but this is not
what RFC 8200 prescibes. Linux also defaults to 60s [1].

[1] 47ec5303d7/include/net/ipv6.h (L456)

PiperOrigin-RevId: 336034636
2020-10-08 00:56:16 -07:00
Adin Scannell a55bd73d48 Add staticcheck and staticstyle analyzers.
This change also adds support to go_stateify for detecting an appropriate
receiver name, avoiding a large number of false positives.

PiperOrigin-RevId: 335994587
2020-10-07 18:29:05 -07:00
gVisor bot b89e43e200 Merge pull request #4376 from lubinszARM:pr_usr_tls_new
PiperOrigin-RevId: 335930035
2020-10-07 12:42:35 -07:00
Adin Scannell ecf9a7ef09 Add precise synchronization to KVM.
By using TSC scaling as a hack, we can trick the kernel into setting an offset
of exactly zero. Huzzah!

PiperOrigin-RevId: 335922019
2020-10-07 12:08:09 -07:00