Commit Graph

219 Commits

Author SHA1 Message Date
Adin Scannell 7926a9e28d Add nogo configuration.
This splits the nogo rules into a separate configuration yaml file, and
allows for multiple files to be provided.

Because attrs cannot be passed down to aspects, this required that all
findings are propagated up the aspect Provider. This doesn't mean that
any extra work must be done, just that this information must be carried
through the graph, and some additional starlark complexity is required.

PiperOrigin-RevId: 339076357
2020-10-26 11:11:46 -07:00
Zach Koopmans e2dce04603 Add parser for open source benchmarks.
Add a parser binary for parsing files containing
Benchmark output and sending data to BigQuery.

PiperOrigin-RevId: 339066396
2020-10-26 10:29:20 -07:00
Dean Deng 54d2d927ac Direct gvisor.dev/issues to the same place as gvisor.dev/issue.
Also let the Github bug reviver detect both in TODOs.

PiperOrigin-RevId: 338785089
2020-10-23 19:29:26 -07:00
Ting-Yu Wang 8dfbec28a4 Fix nogo tests in //pkg/sentry/socket/...
PiperOrigin-RevId: 338784921
2020-10-23 19:24:09 -07:00
Andrei Vagin d18346e790 tools/parsers: disable nogo checks
There are too many dependencies.

PiperOrigin-RevId: 338746264
2020-10-23 14:35:31 -07:00
Jamie Liu 227fd9f1b0 //pkg/state fixes for VFS2.
- When encodeState.resolve() determines that the resolved reflect.Value is
  contained by a previously-resolved object, set wire.Ref.Type to the
  containing object's type (existing.obj.Type()) rather than the contained
  value's type (obj.Type()).

- When encodeState.resolve() determines that the resolved reflect.Value
  contains a previously-resolved object, handle cases where the new object
  contains *multiple* previously-resolved objects. (This may cause
  previously-allocated object IDs to become unused; to facilitate this, change
  encodeState.pending to a map, and change the wire format to prefix each
  object with its object ID.)

- Add encodeState.encodedStructs to avoid redundant encoding of structs, since
  deduplication of objects via encodeState.resolve() doesn't work for objects
  instantiated by StateSave() and passed to SaveValue() (i.e. fields tagged
  `state:".(whatever)"`).

- Make unexported array fields deserializable via slices that refer to them by
  casting away their unexportedness in decodeState.decodeObject().

Updates #1663

PiperOrigin-RevId: 338727687
2020-10-23 12:53:20 -07:00
Dean Deng 9ca66ec598 Rewrite reference leak checker without finalizers.
Our current reference leak checker uses finalizers to verify whether an object
has reached zero references before it is garbage collected. There are multiple
problems with this mechanism, so a rewrite is in order.

With finalizers, there is no way to guarantee that a finalizer will run before
the program exits. When an unreachable object with a finalizer is garbage
collected, its finalizer will be added to a queue and run asynchronously. The
best we can do is run garbage collection upon sandbox exit to make sure that
all finalizers are enqueued.

Furthermore, if there is a chain of finalized objects, e.g. A points to B
points to C, garbage collection needs to run multiple times before all of the
finalizers are enqueued. The first GC run will register the finalizer for A but
not free it. It takes another GC run to free A, at which point B's finalizer
can be registered. As a result, we need to run GC as many times as the length
of the longest such chain to have a somewhat reliable leak checker.

Finally, a cyclical chain of structs pointing to one another will never be
garbage collected if a finalizer is set. This is a well-known issue with Go
finalizers (https://github.com/golang/go/issues/7358). Using leak checking on
filesystem objects that produce cycles will not work and even result in memory
leaks.

The new leak checker stores reference counted objects in a global map when
leak check is enabled and removes them once they are destroyed. At sandbox
exit, any remaining objects in the map are considered as leaked. This provides
a deterministic way of detecting leaks without relying on the complexities of
finalizers and garbage collection.

This approach has several benefits over the former, including:
- Always detects leaks of objects that should be destroyed very close to
  sandbox exit. The old checker very rarely detected these leaks, because it
  relied on garbage collection to be run in a short window of time.
- Panics if we forgot to enable leak check on a ref-counted object (we will try
  to remove it from the map when it is destroyed, but it will never have been
  added).
- Can store extra logging information in the map values without adding to the
  size of the ref count struct itself. With the size of just an int64, the ref
  count object remains compact, meaning frequent operations like IncRef/DecRef
  are more cache-efficient.
- Can aggregate leak results in a single report after the sandbox exits.
  Instead of having warnings littered in the log, which were
  non-deterministically triggered by garbage collection, we can print all
  warning messages at once. Note that this could also be a limitation--the
  sandbox must exit properly for leaks to be detected.

Some basic benchmarking indicates that this change does not significantly
affect performance when leak checking is enabled, which is understandable
since registering/unregistering is only done once for each filesystem object.

Updates #1486.

PiperOrigin-RevId: 338685972
2020-10-23 09:17:02 -07:00
Ting-Yu Wang 7dc108b41f Fix errors when the tagging GitHub releases
When the commit description contains "commit ", it will be wrongly identified
as commit hash.  This commit changes to take only lines begins with "commit "
as a fix, since the description is always indented by `git log`.

Copybara uses merge commit for external contributors, this causes that not all
commits contain a Piper ID. Adding `--first-parent` to `git log` so that it
only lists commits that contain a Piper ID.

PiperOrigin-RevId: 338183812
2020-10-20 19:30:14 -07:00
Ting-Yu Wang 16ba350314 Fix nogo test in //pkg/tcpip/...
PiperOrigin-RevId: 338168977
2020-10-20 17:22:28 -07:00
Adin Scannell 54e989ec3a Remove legacy bazel configurations.
Using the newer bazel rules necessitates a transition from proto1 to
proto2. In order to resolve the incompatibility between proto2 and
gogoproto, the cri runtimeoptions proto must be vendored.

Further, some of the semantics of bazel caching changed during the
transition. It is now necessary to:

- Ensure that :gopath depends only on pure library targets, as the
  propagation of go_binary build attributes (pure, static) will
  affected the generated files (though content remains the same,
  there are conflicts with respect to the gopath).
- Update bazel.mk to include the possibility of binaries in the
  bazel-out directory, as it will now put runsc and others there.
  This required some refinements to the mechanism of extracting
  paths, since some the existing regex resulted in false positives.
- Change nogo rules to prevent escape generation on binary targets.
  For some reason, the newer version of bazel attempted to run the
  nogo analysis on the binary targets, which fails due to the fact
  that objdump does not work on the final binary. This must be due
  to a change in the semantics of aspects in bazel3.

PiperOrigin-RevId: 337958324
2020-10-19 16:28:40 -07:00
Adin Scannell 9a3d8973c4 Refactor shared starlark files.
PiperOrigin-RevId: 337581114
2020-10-16 14:44:03 -07:00
Adin Scannell b0da31b921 Refactor nogo to better support ARM.
PiperOrigin-RevId: 337544107
2020-10-16 11:26:58 -07:00
Adin Scannell 14a003c60f Cache errors when processing stdlib with nogo.
PiperOrigin-RevId: 337515664
2020-10-16 09:05:18 -07:00
Zach Koopmans b576de907c Add parsers golang benchmarks.
Add parser and formatting for golang benchmarks for docker benchmarks.
Change adds a library for printing and parsing Test parameters and metrics.
Benchmarks use the library to print parameters in the Benchmark title
(e.g. the name field in b.Run()), and to report CustomMetrics. Parser
uses the library to parse printed data from benchmark output and
put it into BigQuery structs.

PiperOrigin-RevId: 336365628
2020-10-09 14:29:21 -07:00
Adin Scannell 6229be5e48 Minor nogo restructuring.
PiperOrigin-RevId: 336343819
2020-10-09 12:33:44 -07:00
Adin Scannell 743327817f Infer receiver name for stateify.
PiperOrigin-RevId: 336340035
2020-10-09 12:14:28 -07:00
Adin Scannell 5124ce579d Minor nogo cleanup.
PiperOrigin-RevId: 336126583
2020-10-08 11:24:21 -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 fcddfb0a71 Internal change.
PiperOrigin-RevId: 335960488
2020-10-07 15:04:13 -07:00
Dean Deng 7e55ee14eb Fix text processing in bazel build command.
The extraction of the build target was overfitted before, making build_cmd fail
in some environments.

PiperOrigin-RevId: 335916651
2020-10-07 11:45:26 -07:00
gVisor bot 5aa75653ab Internal change.
PiperOrigin-RevId: 335429072
2020-10-05 13:17:19 -07:00
Andrei Vagin 28ced626a3 tools/checkescape: trim the "(SB)" before searching it in the allowed list
Signed-off-by: Andrei Vagin <avagin@gmail.com>
2020-10-02 14:27:49 -07:00
Adin Scannell 0cea647218 Save addresses for "allowed" functions.
PiperOrigin-RevId: 335086850
2020-10-02 13:14:16 -07:00
Rahat Mahmood fee2c07728 go-marshal tests should respect build tags.
Previously, the go-marshal-generated tests did not respect build
tags. This can cause the test to unbuildable under some build
configurations, as the original types the tests refer to may not be
defined.

This CL copies the build tags from the input files to the test,
similar to the generated library; however test packages have an
additional constraint. A test package cannot be totally empty
(i.e. have no test/example/benchmark defined), otherwise the go
compiler returns an error. To ensure the generated test package always
contains a testable entity under all build configurations, we now emit
an extra test file with no build tags that contains a single no-op
example.

PiperOrigin-RevId: 334496821
2020-09-29 17:29:08 -07:00
Adin Scannell 994c90e2d2 Add nogo check annotations to GitHub.
When nogo checks are violated, they will automatically posted
as annotations on the specific GitHub commit. This allows us
to ensure analysis & style rules and have them called out.

PiperOrigin-RevId: 334447285
2020-09-29 13:16:54 -07:00
Rahat Mahmood 44c7d55074 Support embedded fields in go-marshal.
PiperOrigin-RevId: 334437990
2020-09-29 12:34:30 -07:00
Andrei Vagin 2111cba9ce make: specify /dev/null for the tail tool 2020-09-23 21:05:45 -07:00
gVisor bot d00207ff48 Internal change.
PiperOrigin-RevId: 333287864
2020-09-23 07:29:31 -07:00
Ayush Ranjan d796b100ec Provide testing container with docker config file.
This is needed by test/e2e/integration_test:TestCheckpointRestore to check for
filesystem versioning.

PiperOrigin-RevId: 332285566
2020-09-17 12:11:41 -07:00
Rahat Mahmood 9ef1c79922 Rename marshal.Task to marshal.CopyContext.
CopyContext is a better name for the interface because from
go-marshal's perspective, the interface has nothing to do with a
task. A kernel.Task happens to implement the interface, but so can
other things like MemoryManager and IO sequences.

PiperOrigin-RevId: 331959678
2020-09-16 02:10:12 -07:00
Rahat Mahmood d201feb8c5 Enable automated marshalling for the syscall package.
PiperOrigin-RevId: 331940975
2020-09-15 23:38:57 -07:00
Rahat Mahmood 3ca73841d7 Move the 'marshal' and 'primitive' packages to the 'pkg' directory.
PiperOrigin-RevId: 331256608
2020-09-11 17:42:49 -07:00
Michael Pratt 490e5c83bd Make nogo more robust to variety of stdlib layouts.
PiperOrigin-RevId: 331206424
2020-09-11 13:07:30 -07:00
Ayush Ranjan fada564c83 Fix make_apt script.
This change makes the following fixes:
- When creating a test repo.key, create a secret keyring as other workflows
  also use secret keyrings only.
- We should not be using both --keyring and --secret-keyring options. Just use
  --secret-keyring.
- Pass homedir to all gpg commands. dpkg-sig takes an arg -g which stands for
  gpgopts. So we need to pass the homedir there too.

PiperOrigin-RevId: 330443280
2020-09-07 21:18:22 -07:00
Ayush Ranjan b6d6a120d0 Fix the release workflow.
PiperOrigin-RevId: 330049242
2020-09-03 21:45:10 -07:00
Adin Scannell 101c97d6f8 Change nogo failures to test failures, instead of build failures.
PiperOrigin-RevId: 329408633
2020-08-31 17:09:20 -07:00
Adin Scannell 983a55aa06 Support stdlib analyzers with nogo.
This immediately revealed an escape analysis violation (!), where
the sync.Map was being used in a context that escapes were not
allowed. This is a relatively minor fix and is included.

PiperOrigin-RevId: 328611237
2020-08-26 14:42:35 -07:00
Adin Scannell e650890299 Provide --secret-keyring parameter (for newer gpg).
PiperOrigin-RevId: 328403914
2020-08-25 14:29:55 -07:00
Adin Scannell b0c53f8475 Add nogo support to go_binary and go_test targets.
Updates #3374

PiperOrigin-RevId: 328378700
2020-08-25 12:18:25 -07:00
Ayush Ranjan 46485f9d47 [go-marshal] Support marshalling for structs with names starting with W.
Due to how marshallable interface implementation was generated, we could not
marshal a struct whose named started with W because there was a naming
collision with parameter (w io.Writer) and type (w *StuctName).

Used "writer" as parameter name to avoid collision.

PiperOrigin-RevId: 328343930
2020-08-25 09:23:41 -07:00
Ian Lewis 3f523b3bbc Handle URLs better in issue reviver
- Handle urls ending in /
- Add some url parsing tests

PiperOrigin-RevId: 326750183
2020-08-14 16:23:34 -07:00
gVisor bot 977618c8e1 Merge pull request #3520 from boyuan-he:marshal-impl
PiperOrigin-RevId: 325546935
2020-08-07 18:43:12 -07:00
Zach Koopmans 80c80a1410 Remove old benchmark tools.
Remove the old benchmark-tools directory, including
imports in the WORKSPACE file and associated bazel rules.

The new Golang benchmark-tools can be found at //test/benchmarks
and it is functionally equivalent, excepting syscall_test
which can be found in //test/perf/linux.

PiperOrigin-RevId: 325529075
2020-08-07 16:18:51 -07:00
Boyuan He 92c0643587 add stub go marshallable implementation 2020-08-07 00:29:07 +00:00
Adin Scannell 90021e775a Add bzl_library rules for .bzl files without one.
PiperOrigin-RevId: 325280924
2020-08-06 12:10:49 -07:00
Adin Scannell c5f5806fe6 Enable "make packetimpact-tests" to work.
This required minor fixes to the bazel wrapper. The "dut_platform" is
also changed to "native" to line-up with the system call tests and
remove the hard-coded "linux" and "netstack" strings.
2020-08-04 20:49:00 -07:00
Adin Scannell 10f6c41bbd Include shim binaries in the Go branch.
PiperOrigin-RevId: 324615016
2020-08-03 09:09:51 -07:00
Adin Scannell 877fac4864 Allocate a pseudo-tty for exec.
Otherwise Ctrl-C will kill the 'docker exec' as opposed to killing
the bazel command being run inside the container.

PiperOrigin-RevId: 324079339
2020-07-30 14:11:09 -07:00
Adin Scannell 61b3e05f40 Drop complex awk step.
PiperOrigin-RevId: 324023425
2020-07-30 09:59:03 -07:00
gVisor bot 7c1c5917da Merge pull request #2797 from Rajpratik71:optimization/pip-no-cache
PiperOrigin-RevId: 323508910
2020-07-27 22:18:37 -07:00