Commit Graph

2121 Commits

Author SHA1 Message Date
Dean Deng 822d847cca Check for valid nfds before copying in an fd set.
Otherwise, CopyInFDSet will try to allocate a negative-length slice.

PiperOrigin-RevId: 286584907
2019-12-20 08:44:53 -08:00
Andrei Vagin 29955a4797 futex: wake one waiter if futex_wake is called with a non-positive value
This change is needed to be compatible with the Linux kernel.

There is no glibc wrapper for the futex system call, so it is easy to
make a mistake and call syscall(__NR_futex, FUTEX_WAKE, addr) without
the fourth argument. This works on Linux, because it wakes one waiter
even if val is nonpositive.

PiperOrigin-RevId: 286494396
2019-12-19 17:26:44 -08:00
Dean Deng 7419e0e5d7 Parameterize mmap tests.
This test suite has existed for quite a while and has become kind of messy.
Various tests can be joined together by parameterizing.

PiperOrigin-RevId: 286482240
2019-12-19 16:07:04 -08:00
Brad Burlage 80c8aecd51 Install python2 in the Dockerfile.
Without it, we get a build failure (inside the container) when trying to build
//runsc.

PiperOrigin-RevId: 286474518
2019-12-19 15:26:00 -08:00
Nicolas Lacasse bb00438f36 Make masterInodeOperations.Truncate take a pointer receiver.
Otherwise a copy happens, which triggers a data race when reading
masterInodeOperations.SimpleFileOperations.uattr, which must be accessed with a
lock held.

PiperOrigin-RevId: 286464473
2019-12-19 14:34:53 -08:00
Andrei Vagin 57ce26c0b4 net/tcp: allow to call listen without bind
When listen(2) is called on an unbound socket, the socket is
automatically bound to a random free port with the local address
set to INADDR_ANY.

PiperOrigin-RevId: 286305906
2019-12-18 18:24:17 -08:00
gVisor bot 98e8246ad1 Merge pull request #890 from lubinszARM:pr_phyap
PiperOrigin-RevId: 286299056
2019-12-18 17:37:30 -08:00
Fabricio Voznika 0d475cdb01 Increase waitForProcessList timeout
It can take more than 10 seconds when running under --race.

PiperOrigin-RevId: 286296060
2019-12-18 17:10:44 -08:00
Jamie Liu 744401297a Add VFS2 plumbing for extended attributes.
PiperOrigin-RevId: 286281274
2019-12-18 15:48:45 -08:00
Ghanan Gowripalan 8e6e87f8e8 Allow 'out-of-line' routing table updates for Router and Prefix discovery events
This change removes the requirement that a new routing table be provided when a
router or prefix discovery event happens so that an updated routing table may
be provided to the stack at a later time from the event.

This change is to address the use case where the netstack integrator may need to
obtain a lock before providing updated routes in response to the events above.

As an example, say we have an integrator that performs the below two operations
operations as described:
A. Normal route update:
  1. Obtain integrator lock
  2. Update routes in the integrator
  3. Call Stack.SetRouteTable with the updated routes
    3.1. Obtain Stack lock
    3.2. Update routes in Stack
    3.3. Release Stack lock
  4. Release integrator lock
B. NDP event triggered route update:
  1. Obtain Stack lock
  2. Call event handler
    2.1. Obtain integrator lock
    2.2. Update routes in the integrator
    2.3. Release integrator lock
    2.4. Return updated routes to update Stack
  3. Update routes in Stack
  4. Release Stack lock

A deadlock may occur if a Normal route update was attemped at the same time an
NDP event triggered route update was attempted. With threads T1 and T2:
1) T1 -> A.1, A.2
2) T2 -> B.1
3) T1 -> A.3 (hangs at A.3.1 since Stack lock is taken in step 2)
4) T2 -> B.2 (hangs at B.2.1 since integrator lock is taken in step 1)

Test: Existing tests were modified to not provide or expect routing table
changes in response to Router and Prefix discovery events.
PiperOrigin-RevId: 286274712
2019-12-18 15:18:33 -08:00
gVisor bot ac3b3bb40e Merge pull request #1322 from lubinszARM:pr_vfp_ring0
PiperOrigin-RevId: 286259750
2019-12-18 14:52:35 -08:00
Ghanan Gowripalan 628948b1e1 Cleanup NDP Tests
This change makes sure that test variables are captured before running tests
in parallel, and removes unneeded buffered channel allocations. This change also
removes unnecessary timeouts.

PiperOrigin-RevId: 286255066
2019-12-18 14:24:39 -08:00
Jay Zhuang 18d6e59b45 Switch to netinet/tcp.h and poll.h to for better platform portability.
PiperOrigin-RevId: 286249699
2019-12-18 13:58:38 -08:00
Michael Pratt 334a513f11 Add Mems_allowed to /proc/PID/status
PiperOrigin-RevId: 286248378
2019-12-18 13:16:28 -08:00
Jay Zhuang 65f53c5833 Put GetSocketPairs() in unnamed namespace
This avoids conflicting definitions of GetSocketPairs() in outer namespace when
multiple such cc files are complied for one binary.

PiperOrigin-RevId: 286243045
2019-12-18 12:50:04 -08:00
Michael Pratt 803437c96b Upgrade to Python 3
Python 3 tools must be listed in exec_tools for genrules.

PiperOrigin-RevId: 286241702
2019-12-18 12:23:03 -08:00
Bin Lu eb868be743 supporting lazy-fpsimd in guest on Arm64
Several jobs were finished in this patch:
1, provide functions to get/set fpcr/fpsr/vregs
2, support lazy-fpsimd-context-switch in el1

Signed-off-by: Bin Lu <bin.lu@arm.com>
2019-12-18 16:45:15 +08:00
Kevin Krakauer 64d00cc63d Internal change.
PiperOrigin-RevId: 286083614
2019-12-17 16:21:48 -08:00
gVisor bot 725e73eed0 Merge pull request #1393 from ernado:cpu-num-from-quota
PiperOrigin-RevId: 286068605
2019-12-17 15:07:45 -08:00
Michael Pratt 91f1ac7319 Mark enableCpuidFault nosplit
This is called after fork, so it must be nosplit.

Updates #1408

PiperOrigin-RevId: 286053054
2019-12-17 14:18:54 -08:00
gVisor bot 3ab90ecf25 Merge pull request #1394 from zhuangel:bindlock
PiperOrigin-RevId: 286051631
2019-12-17 13:53:16 -08:00
gVisor bot e416724fb3 Merge pull request #1321 from lubinszARM:pr_testutils_vfp
PiperOrigin-RevId: 286042427
2019-12-17 13:10:50 -08:00
gVisor bot 3f4d8fefb4 Internal change.
PiperOrigin-RevId: 286003946
2019-12-17 10:10:06 -08:00
Aleksandr Razumov 67f678be27
Leave minimum CPU number as a constant
Remove introduced CPUNumMin config and hard-code it as 2.
2019-12-17 20:41:02 +03:00
gVisor bot 67000b929b Explicitly export files needed by other packages
PiperOrigin-RevId: 285968611
2019-12-17 06:33:08 -08:00
Aleksandr Razumov b661434202
Add minimum CPU number and only lower CPUs on --cpu-num-from-quota
* Add `--cpu-num-min` flag to control minimum CPUs
* Only lower CPU count
* Fix comments
2019-12-17 13:27:13 +03:00
Nicolas Lacasse 0881abdfdd Remove useless comments from p9/handlers.go.
These comments provided nothing, and have been copy-pasted into all
implementations. The code is clear without them.

I considered also removing the "handle implements handler.handle" comments, but
will let those stay for now.

PiperOrigin-RevId: 285876428
2019-12-16 16:32:59 -08:00
gVisor bot 2e2545b458 Merge pull request #1392 from zhuangel:bindleak
PiperOrigin-RevId: 285874181
2019-12-16 16:21:17 -08:00
Dean Deng 3193b2fff8 Drop unnecessary cast.
Bitshift operators with signed int is supported in Go 1.13.

PiperOrigin-RevId: 285853622
2019-12-16 14:41:20 -08:00
Dean Deng e6f4124afd Implement checks for get/setxattr at the syscall layer.
Add checks for input arguments, file type, permissions, etc. that match
the Linux implementation. A call to get/setxattr that passes all the
checks will still currently return EOPNOTSUPP. Actual support will be
added in following commits.

Only allow user.* extended attributes for the time being.

PiperOrigin-RevId: 285835159
2019-12-16 13:20:07 -08:00
Yong He bd5c7bf58d Fix deadlock in overlay bind
Copy up parent when binding UDS on overlayfs is supported in commit
02ab1f187c.
But the using of copyUp in overlayBind will cause sentry stuck, reason
is dead lock in renameMu.

1 [Process A] Invoke a Unix socket bind operation
  renameMu is hold in fs.(*Dirent).genericCreate by process A
2 [Process B] Invoke a read syscall on /proc/task/mounts
  waitng on Lock of renameMu in fs.(*MountNamespace).FindMount
3 [Process A] Continue Unix socket bind operation
  wating on RLock of renameMu in fs.copyUp

Root cause is recursive reading lock of reanmeMu in bind call trace,
if there are writing lock between the two reading lock, then deadlock
occured.

Fixes #1397
2019-12-16 18:37:35 +08:00
Yong He 8a46e83111 Fix UDS bind cause fd leak in gofer
After the finalizer optimize in 76039f8959
commit, clientFile needs to closed before finalizer release it.
The clientFile is not closed if it is created via
gofer.(*inodeOperations).Bind, this will cause fd leak which is hold
by gofer process.

Fixes #1396

Signed-off-by: Yong He <chenglang.hy@antfin.com>
Signed-off-by: Jianfeng Tan <henry.tjf@antfin.com>
2019-12-16 18:28:10 +08:00
Aleksandr Razumov 8782f0e287
Set CPU number to CPU quota
When application is not cgroups-aware, it can spawn excessive threads
which often defaults to CPU number.
Introduce a opt-in flag that will set CPU number accordingly to CPU
quota (if available).

Fixes #1391
2019-12-15 21:12:43 +03:00
lubinszARM 6b42453039 enable kvm to support arm64
There are 4 jobs were finished in this package:
  	1, Virtual machine initialization.
	2, Bluepill implementation.
	3, Move ring0.Vectors() into the address with 11-bits alignment.
	4, Basic support for "SwitchToUser".
Signed-off-by: Bin Lu <bin.lu@arm.com>
COPYBARA_INTEGRATE_REVIEW=https://github.com/google/gvisor/pull/919 from lubinszARM:pr_kvm eedea52db451bf62722759009a9f14c54a69c55f
PiperOrigin-RevId: 285501256
2019-12-13 17:11:23 -08:00
Ghanan Gowripalan ad80dcf470 Properly generate the EUI64 interface identifier from an Ethernet address
Fixed a bug where the interface identifier was not properly generated from an
Ethernet address.

Tests: Unittests to make sure the functions generating the EUI64 interface
identifier are correct.
PiperOrigin-RevId: 285494562
2019-12-13 16:41:41 -08:00
Kevin Krakauer be2754a4b9 Add iptables testing framework.
It would be preferrable to test iptables via syscall tests, but there are some
problems with that approach:

* We're limited to loopback-only, as syscall tests involve only a single
  container. Other link interfaces (e.g. fdbased) should be tested.
* We'd have to shell out to call iptables anyways, as the iptables syscall
  interface itself is too large and complex to work with alone.
* Running the Linux/native version of the syscall test will require root, which
  is a pain to configure, is inherently unsafe, and could leave host iptables
  misconfigured.

Using the go_test target allows there to be no new test runner.

PiperOrigin-RevId: 285274275
2019-12-12 14:42:11 -08:00
Jamie Liu 93d429d5b1 Implement memmap.MappingIdentity for vfs.FileDescription.
PiperOrigin-RevId: 285255855
2019-12-12 13:19:33 -08:00
Rahat Mahmood 007707a072 Implement kernfs.
PiperOrigin-RevId: 285231002
2019-12-12 11:20:47 -08:00
Andrei Vagin 378d6c1f36 unix: allow to bind unix sockets only to AF_UNIX addresses
Reported-by: syzbot+2c0bcfd87fb4e8b7b009@syzkaller.appspotmail.com
PiperOrigin-RevId: 285228312
2019-12-12 11:08:56 -08:00
Bhasker Hariharan b9aa62b9f9 Enable IPv6 in runsc
Fixes #1341

PiperOrigin-RevId: 285108973
2019-12-11 19:14:26 -08:00
Bhasker Hariharan 6fc9f0aefd Add support for TCP_USER_TIMEOUT option.
The implementation follows the linux behavior where specifying
a TCP_USER_TIMEOUT will cause the resend timer to honor the
user specified timeout rather than the default rto based timeout.

Further it alters when connections are timedout due to keepalive
failures. It does not alter the behavior of when keepalives are
sent. This is as per the linux behavior.

PiperOrigin-RevId: 285099795
2019-12-11 17:52:53 -08:00
Dean Deng 1601e78a52 Add syscall tests for getxattr and setxattr.
Support for getxattr and setxattr are in subsequent commits.

PiperOrigin-RevId: 285088817
2019-12-11 16:41:17 -08:00
Zach Koopmans e2e3b38460 GCloudProducer: tunnel_dispatch, mock_recorder, and machine.
Work to import GCloudProducer, written in gerrit, which is
too large to do in one CL. GCloudProducer sets up gcloud
instances to run benchmark workloads.

Included are:
- gcloud_mock_recorder - used to Mock GCloudProducer
- tunnel_dispatcher - updates to this module to bring it in line
with the style guide
- machine - updates to this module to bring it in line with the
 style guide

All changes are independent of the rest of the changes, and
should "just build".

PiperOrigin-RevId: 285076423
2019-12-11 15:51:41 -08:00
Brad Burlage e690651c67 Run kythe build with -std=c++17
We seem to be getting some compiler errors when using the Kythe
extractors.bazelrc.

I'm not able to reproduce this on my local machine, so I'm hoping copying the
cxxopt from gvisor.dev/pr/1350 will fix the build.

PiperOrigin-RevId: 285054258
2019-12-11 14:48:11 -08:00
Jamie Liu 481dbfa5ab Add vfs.Pathname{WithDeleted,ForGetcwd}.
The former is needed for vfs.FileDescription to implement
memmap.MappingIdentity, and the latter is needed to implement getcwd(2).

PiperOrigin-RevId: 285051855
2019-12-11 14:26:32 -08:00
Michael Pratt 0d027262e0 Add additional packages to go branch
We're missing several packages that runsc doesn't depend on. Most notable are
several tcpip link packages.

To find packages, I looked at a diff of directories on master vs go:

$ bazel build //:gopath
$ find bazel-bin/gopath/src/gvisor.dev/gvisor/ -type d > /tmp/gopath.txt
$ find . -type d > /tmp/master.txt
$ sed 's|bazel-bin/gopath/src/gvisor.dev/gvisor/||' < /tmp/gopath.txt > /tmp/gopath.trunc.txt
$ sed 's|./||' < /tmp/master.txt > /tmp/master.trunc.txt
$ vimdiff /tmp/gopath.trunc.txt /tmp/master.trunc.txt

Testing packages are still left out because :gopath can't depend on testonly
targets...

PiperOrigin-RevId: 285049029
2019-12-11 14:22:36 -08:00
gVisor bot b80cba6126 Merge pull request #1248 from xiaobo55x:ptrace
PiperOrigin-RevId: 285038987
2019-12-11 13:52:24 -08:00
Andrei Vagin f8c5ad061b runsc/debug: add an option to list all processes
runsc debug --ps list all processes with all threads. This option is added to
the debug command but not to the ps command, because it is going to be used for
debug purposes and we want to add any useful information without thinking about
backward compatibility.

This will help to investigate syzkaller issues.

PiperOrigin-RevId: 285013668
2019-12-11 11:05:41 -08:00
Dean Deng 1643224af0 Finish incomplete comment.
PiperOrigin-RevId: 285012278
2019-12-11 10:37:35 -08:00
Dean Deng 2e3b9b0a68 Deduplicate and simplify control message processing for recvmsg and sendmsg.
Also, improve performance by calculating how much space is needed before making
an allocation for sendmsg in hostinet.

PiperOrigin-RevId: 284898581
2019-12-10 19:27:42 -08:00