45 Commits
Author SHA1 Message Date
Konstantin BogomolovandgVisor bot 4dfcd5e1ae nogo: Fix more analyzer findings.
PiperOrigin-RevId: 875246522
2026-02-25 11:07:15 -08:00
Tamir Duberstein 1f12a0d388 Fix QF1012 violations and drop suppression 2026-02-10 11:56:10 -08:00
Etienne PerotandgVisor bot 056a85f39d Mark all ABI structs with structs.HostLayout; verify this remains true.
This change marks all ABI-related structs with `structs.HostLayout`, which was
introduced in Go 1.23: https://pkg.go.dev/[email protected]#HostLayout
This is intended to force the Go compiler to preserve the layout of the
struct, removing it from the liberty of reordering fields as it sees fit.

Adds a check automatically generated by our `go_library` rule wrapper which
verifies this recursively for all exported structs in a package.

Fixes issue #10693.

PiperOrigin-RevId: 860238103
2026-01-23 13:45:28 -08:00
Jing Chen 9f93f73009 Simplify and format gVisor codebase.
The changes are just output of `gofmt -s -w .`.
2024-10-13 00:50:32 -07:00
Etienne PerotandgVisor bot 25bb687541 Avoid redundant work in bpf.optimizeJumpsToSmallestSetOfReturns.
Yes, this is a one-line change.

Once we've rewritten all jumps that went to instruction X to go to instruction
Y instead, we don't need to then check if we can also rewrite them to go to
instruction Z.

Tested with `--config=race` and Coverage enabled, which is the worst case
as far as performance goes:

```
$ make test BAZEL_TEST_OUTPUT=all BAZEL_OPTIONS='--config=race --collect_code_coverage --instrumentation_filter=//pkg/..,-//pkg/sentry/platform,-//pkg/ring0,-//pkg/coverage:coverage,-//pkg/sleep:sleep,-//pkg/sync:sync,-//pkg/syncevent:syncevent --test_arg=-test.bench=BenchmarkSentrySystrap/Postgres --test_arg=-test.benchtime=1x' TARGETS=//runsc/boot/filter:filter_bench_test
```

... with some extra timing code to check the time spent in
`optimizeJumpsToSmallestSetOfReturns` which reduced from ~750ms to ~120ms on
my machine.

PiperOrigin-RevId: 644195759
2024-06-17 18:21:04 -07:00
Jing ChenandgVisor bot d56b30b38a Replace reflect.DeepEqual with [slices/maps].Equal.
They are faster on slice/map comparisons.

PiperOrigin-RevId: 633080355
2024-05-12 21:20:18 -07:00
Etienne PerotandgVisor bot 1cd47805c3 BPF optimizer: Refactor removal operations across optimizers.
This introduces a `codeRemoval` type which acts as a tracker for removal of
instructions during execution of an optimizer.

This simplifies optimizers that use it, notably to avoid having to do
backwards iterations in all of them.

No heap allocations are performed unless code is actually removed, and only
one allocation is performed when code is to be removed.

PiperOrigin-RevId: 595575409
2024-01-03 20:32:49 -08:00
Etienne PerotandgVisor bot f7a1a45315 BPF optimizer: Optimize redundant loads.
This is useful in conjunction cases when a single argument is compared
against multiple values, e.g. for `fcntl(2)` where `args[1]` may be `F_GETFL`,
`F_SETFL`, or `F_GETFD`. There is no need to reload the value of `args[1]`
into the register if it is already the same as the one that was loaded from
the previous check.

This helps with syscall rules where one specific argument may be one of many
specific values, especially `ioctl` rules (critical for KVM and `nvproxy`
performance), and the benchmarks seem to agree:

```
# Time to evaluate seccomp filter for a syscall:
# (Many syscalls for which the rules are not "this argument must be one of
# these values" show no change and are omitted from this list)
                                      │    before    │                   after                   │
                                      │    sec/op    │     sec/op      vs base                   │
SentrySystrap/Postgres/futex            62.39n ± 13%    53.06n ±  39%        ~ (p=0.184 n=19+20)
SentrySystrap/Postgres/nanosleep        237.7n ± 33%    119.3n ± 142%        ~ (p=0.089 n=12)
[...]
SentryKVM/Postgres/ioctl                60.88n ± 17%    56.63n ±  12%   -6.98% (p=0.026 n=20+19)
SentryKVM/Postgres/rt_sigreturn         34.67n ± 32%    29.33n ±  49%        ~ (p=0.443 n=20+18)
[...]
NVProxyIoctl/nvproxy/ioctl_3222292175   58.81n ±  8%    54.85n ±   8%   -6.73% (p=0.015 n=29+30)
NVProxyIoctl/nvproxy/ioctl_3221767894   58.22n ±  5%    54.06n ±   6%   -7.14% (p=0.022 n=29+30)
NVProxyIoctl/nvproxy/ioctl_3222292009   58.33n ±  8%    55.67n ±   3%        ~ (p=0.070 n=28+30)
NVProxyIoctl/nvproxy/ioctl_3223340586   61.57n ±  7%    58.56n ±   7%        ~ (p=0.059 n=27+29)
NVProxyIoctl/nvproxy/ioctl_3223340587   63.10n ±  9%    58.78n ±   7%        ~ (p=0.140 n=29+30)
NVProxyIoctl/nvproxy/ioctl_3223864875   63.66n ±  7%    58.25n ±   3%   -8.50% (p=0.030 n=29)
NVProxyIoctl/nvproxy/ioctl_3224389163   64.12n ±  5%    60.96n ±   4%        ~ (p=0.114 n=29+30)
NVProxyIoctl/nvproxy/ioctl_3223078452   63.90n ±  9%    58.25n ±   6%   -8.84% (p=0.014 n=29)
NVProxyIoctl/nvproxy/ioctl_3222816309   66.07n ± 10%    58.08n ±   5%  -12.10% (p=0.003 n=29+30)
NVProxyIoctl/nvproxy/ioctl_3233302090   65.55n ±  7%    58.88n ±   8%  -10.17% (p=0.000 n=29+30)
NVProxyIoctl/nvproxy/ioctl_3224913486   65.62n ±  6%    61.10n ±   7%        ~ (p=0.072 n=28+29)
NVProxyIoctl/nvproxy/ioctl_3223340623   63.45n ±  7%    59.47n ±   6%   -6.26% (p=0.018 n=29+30)
NVProxyIoctl/nvproxy/ioctl_3223864926   66.35n ±  8%    59.45n ±   5%  -10.41% (p=0.000 n=29+30)
NVProxyIoctl/nvproxy/ioctl_805306369    62.98n ±  6%    56.26n ±   7%  -10.66% (p=0.006 n=29+30)
NVProxyIoctl/nvproxy/ioctl_75           69.09n ±  7%    64.87n ±   8%        ~ (p=0.083 n=29+28)
NVProxyIoctl/nvproxy/ioctl_805306370    72.30n ±  8%    57.81n ±   7%  -20.04% (p=0.000 n=29+30)
NVProxyIoctl/nvproxy/ioctl_23           79.59n ±  5%    73.65n ±   4%   -7.46% (p=0.001 n=29)
NVProxyIoctl/nvproxy/ioctl_24           79.70n ±  4%    73.86n ±   3%   -7.33% (p=0.014 n=29+30)
NVProxyIoctl/nvproxy/ioctl_25           79.32n ±  4%    77.69n ±   6%        ~ (p=0.468 n=29)
NVProxyIoctl/nvproxy/ioctl_26           80.15n ±  5%    76.61n ±   6%        ~ (p=0.140 n=29+30)
NVProxyIoctl/nvproxy/ioctl_27           80.02n ±  5%    75.77n ±   7%   -5.31% (p=0.003 n=29+30)
NVProxyIoctl/nvproxy/ioctl_28           80.52n ±  6%    76.79n ±   3%   -4.63% (p=0.028 n=29+30)
NVProxyIoctl/nvproxy/ioctl_33           85.05n ±  8%    78.23n ±   5%   -8.02% (p=0.028 n=29+30)
NVProxyIoctl/nvproxy/ioctl_34           83.57n ±  7%    78.74n ±   4%   -5.77% (p=0.035 n=29+30)
NVProxyIoctl/nvproxy/ioctl_37           82.20n ±  6%    79.85n ±   7%        ~ (p=0.474 n=29+30)
NVProxyIoctl/nvproxy/ioctl_38           85.38n ±  6%    78.23n ±   6%   -8.38% (p=0.001 n=29+30)
NVProxyIoctl/nvproxy/ioctl_39           85.53n ±  4%    79.87n ±   6%   -6.62% (p=0.007 n=29+30)
NVProxyIoctl/nvproxy/ioctl_45           86.29n ±  4%    83.78n ±   8%        ~ (p=0.176 n=29+30)
NVProxyIoctl/nvproxy/ioctl_65           86.89n ±  4%    82.06n ±   5%   -5.56% (p=0.028 n=29+30)
NVProxyIoctl/nvproxy/ioctl_68           88.80n ±  6%    80.78n ±   7%   -9.03% (p=0.000 n=29+30)
NVProxyIoctl/nvproxy/ioctl_72           90.13n ±  3%    82.77n ±   6%   -8.17% (p=0.005 n=29+30)
NVProxyIoctl/nvproxy/ioctl_73           87.23n ±  6%    81.86n ±   4%   -6.16% (p=0.039 n=29+30)
NVProxyIoctl/nvproxy/ioctl_21506        55.90n ±  7%    56.20n ±   6%        ~ (p=0.728 n=28+30)
NVProxyIoctl/nvproxy/ioctl_3224913447   57.26n ±  9%    55.15n ±   7%   -3.68% (p=0.028 n=27+30)
NVProxyIoctl/nvproxy-48                 69.44n ±  7%    64.64n ±   6%   -6.91% (p=0.002 n=10)
geomean                                 61.27n          56.73n          -7.41%

# Number of BPF instructions before optimizations:
                          │   before    │                after                 │
                          │  gen-instr  │  gen-instr   vs base                 │
SentrySystrap/Postgres-48   1.487k ± 0%   1.487k ± 0%       ~ (p=1.000 n=10) ¹
SentryKVM/Postgres-48       1.345k ± 0%   1.345k ± 0%       ~ (p=1.000 n=10) ¹
NVProxyIoctl/nvproxy-48     1.931k ± 0%   1.931k ± 0%       ~ (p=1.000 n=10) ¹
geomean                     1.569k        1.569k       +0.00%
¹ all samples are equal

# Number of BPF instructions after optimizations:
                          │   before   │               after                │
                          │ opt-instr  │ opt-instr   vs base                │
SentrySystrap/Postgres-48   382.0 ± 0%   355.0 ± 0%   -7.07% (p=0.000 n=10)
SentryKVM/Postgres-48       322.0 ± 0%   297.0 ± 0%   -7.76% (p=0.000 n=10)
NVProxyIoctl/nvproxy-48     473.0 ± 0%   409.0 ± 0%  -13.53% (p=0.000 n=10)
geomean                     387.5        350.7        -9.50%

# Ratio of post-optimizer #instructions vs pre-optimizer #instructions:
                          │      before       │                   after                   │
                          │ compression-ratio │ compression-ratio  vs base                │
SentrySystrap/Postgres-48          3.893 ± 0%          4.189 ± 0%   +7.60% (p=0.000 n=10)
SentryKVM/Postgres-48              4.177 ± 0%          4.529 ± 0%   +8.43% (p=0.000 n=10)
NVProxyIoctl/nvproxy-48            4.082 ± 0%          4.721 ± 0%  +15.65% (p=0.000 n=10)
geomean                            4.049               4.474       +10.50%

# Time to run optimizer:
                          │   before    │                after                │
                          │   opt-sec   │   opt-sec    vs base                │
SentrySystrap/Postgres-48   4.699m ± 3%   5.327m ± 4%  +13.34% (p=0.000 n=10)
SentryKVM/Postgres-48       4.130m ± 3%   4.651m ± 3%  +12.60% (p=0.000 n=10)
NVProxyIoctl/nvproxy-48     10.19m ± 3%   10.42m ± 1%   +2.26% (p=0.023 n=10)
geomean                     5.826m        6.367m        +9.28%
```

Note that this only applies in practice because we extract each 32-bit "half"
of each syscall argument into its own matcher rule. So the conjunction that
this optimizes for isn't exactly over a single argument, but over a single
32-bit half of an argument.

PiperOrigin-RevId: 595563115
2024-01-03 19:26:03 -08:00
Etienne PerotandgVisor bot 3495c7e7d5 Use clear on map types wherever possible.
This is similar as pull request #9749 but for maps rather than slices.

PiperOrigin-RevId: 586504320
2023-11-29 18:00:07 -08:00
Etienne PerotandgVisor bot 3e4ab0a8f1 BPF optimizer: Make fewer passes when reducing return instructions.
This changes one of the tradeoffs that this optimization pass used to do
to be more greedy when removing `return` instructions between passes.

Also change `rewriteAllJumpsToReturn` to not use closures.

Together, these changes save a whole **30 seconds** on e.g.
`socket_ip_udp_loopback_non_blocking_test`
with `gotsan` enabled (which really doesn't like repeatedly calling
functions like these, especially those with embedded closures).

PiperOrigin-RevId: 586053438
2023-11-28 11:39:36 -08:00
Etienne PerotandgVisor bot 8dbde7c4cc Add equality function for BPF instructions.
Use it when checking that instructions are equivalent in
`rewriteAllJumpsToReturn`.

Reported-by: [email protected]
PiperOrigin-RevId: 585802467
2023-11-27 17:18:02 -08:00
Etienne PerotandgVisor bot 50f20bf2f6 BPF optimizer: Coalesce jumps to identical return statements to minimize size.
This adds an optimization pass which looks for jumps that go to return
statements that return the same value, and looks for opportunities to
make them jump to as few of these return statements as possible. This makes
the other return statements safely removable, which in turn minimizes the
program and allows more unconditional => conditional jump translations.

This optimization is particularly useful in syscall filter programs, which
tend to have a structure like follows (either through linear or binary
search):

```
	.. if (foo) goto A else goto B
	A: return rejected
	B: if (bar) goto C else goto D
	C: return rejected
	D: if (baz) goto E else goto F
	E: return rejected
	F: return accepted
	...
	(Another set of rules in the program):
	.. if (foo2) goto G else goto H
	G: return accepted
	H: if (bar2) goto I else goto J
	I: return accepted
	J: return rejected
```

After this optimization pass, this can be reduced to:

```
	.. if (foo) goto J else goto B
	B: if (bar) goto J else goto D
	D: if (baz) goto J else goto I
	...
	.. if (foo2) goto I else goto H
	H: if (bar2) goto I else goto J
	I: return accepted
	J: return rejected
```

Benchmarks:

```
              │   before    │                  after                  │
              │   sec/op    │   sec/op     vs base                    │
SentrySystrap   71.28n ± 5%   68.35n ± 9%       ~ (p=0.222 n=140+141)
SentryKVM       59.31n ± 7%   57.93n ± 5%       ~ (p=0.454 n=141)
NVProxyIoctl    97.63n ± 1%   97.13n ± 1%       ~ (p=0.104 n=141+142)

              │   before    │                  after                  │
              │  build-sec  │  build-sec   vs base                    │
SentrySystrap   13.65m ± 0%   13.67m ± 0%       ~ (p=0.144 n=142)
SentryKVM       16.26m ± 0%   16.31m ± 0%  +0.29% (p=0.004 n=141+142)
NVProxyIoctl    42.50m ± 0%   42.55m ± 0%       ~ (p=0.113 n=141+142)

              │      before       │                     after                      │
              │ compression-ratio │ compression-ratio  vs base                     │
SentrySystrap          2.165 ± 0%          2.678 ± 0%  +23.70% (p=0.000 n=142)
SentryKVM              2.132 ± 0%          2.630 ± 0%  +23.36% (p=0.000 n=141+142)
NVProxyIoctl           1.958 ± 0%          2.275 ± 0%  +16.19% (p=0.000 n=141+142)

              │   before    │                   after                   │
              │  gen-instr  │  gen-instr   vs base                      │
SentrySystrap   1.288k ± 0%   1.288k ± 0%       ~ (p=1.000 n=142)     ¹
SentryKVM       1.373k ± 0%   1.373k ± 0%       ~ (p=1.000 n=141+142) ¹
NVProxyIoctl    2.250k ± 0%   2.250k ± 0%       ~ (p=1.000 n=141+142) ¹
¹ all samples are equal

              │   before    │              after              │
              │  opt-instr  │ opt-instr   vs base             │
SentrySystrap    595.0 ± 0%   481.0 ± 0%  -19.16% (n=142)
SentryKVM        644.0 ± 0%   522.0 ± 0%  -18.94% (n=141+142)
NVProxyIoctl    1149.0 ± 0%   989.0 ± 0%  -13.93% (n=141+142)

              │   before    │                     after                      │
              │   opt-sec   │    opt-sec      vs base                        │
SentrySystrap   845.6µ ± 0%   107267.0µ ± 0%  +12584.84% (p=0.000 n=142)
SentryKVM       927.2µ ± 0%   100663.4µ ± 1%  +10756.86% (p=0.000 n=141+142)
NVProxyIoctl    2.118m ± 0%    399.395m ± 1%  +18755.80% (p=0.000 n=141+142)
```

PiperOrigin-RevId: 584484054
2023-11-21 18:54:50 -08:00
Etienne PerotandgVisor bot f784ea5b93 Add tooling to compile seccomp-bpf programs at bazel build time.
This adds a `precompiledseccomp` library which provides tooling to compile
`seccomp-bpf` programs and generate Go source code that contains the
resulting bytecode embedded into it. In turn, this bytecode can be used in
Go libraries.

This avoids spending time compiling and optimizing `seccomp-bpf` programs
at runsc container creation time.

This library also contains support for "variables", which are `uint32`s whose
values are part of the seccomp filters but only known at runtime. To support
this, the program is compiled twice with placeholder values for these
variables, and we verify that the offsets at which these values show up in the
bytecode is consistent across these two compilation attempts.

PiperOrigin-RevId: 583117683
2023-11-16 12:00:44 -08:00
Etienne PerotandgVisor bot 7dd0a20c1d seccomp: Enforce that Sentry filters match against reference program.
This change adds a `filter_fuzz_golden.bpf` BPF program that was generated
manually prior to my recent set of changes to seccomp bytecode and rule
optimization changes. It represents the "reference logic"; the new test
verifies that the current seccomp-bpf library produces BPF bytecode that
has the same behavior, using fuzz testing with full line-based coverage.

PiperOrigin-RevId: 582914572
2023-11-15 22:38:00 -08:00
Etienne PerotandgVisor bot 59bf3fef5f BPF program builder: Cache map of label sources.
This speeds up BPF program generation by 10x, due to the large
amount of time otherwise spent scanning labels linearly.

PiperOrigin-RevId: 582759289
2023-11-15 12:08:28 -08:00
Etienne PerotandgVisor bot d2a2a260a1 bpf program fragment: Add support for checking possible return values.
This records the precise behavior of "return" instructions in the fragment,
rather than simply recording whether there was a "return" instruction at
all. In turn, this allows a caller to verify which return value is returned.

This is useful in an upcoming change to the BST struct, where the fragment
being recorded now has the potential to return (not just jump), and so it
becomes useful to check that the return values it can return are those we
expect.

PiperOrigin-RevId: 581422796
2023-11-10 18:27:26 -08:00
Etienne PerotandgVisor bot a4ee815bd3 bpf: Add logic for verifying whether a program fragment modifies register A.
This is useful for value matching rules which look for the value of the `A`
register. If they do not modify this value, then we do not need to reload it
between sequential matchers over the same data.

PiperOrigin-RevId: 577266390
2023-10-27 12:02:57 -07:00
Etienne PerotandgVisor bot 54a976dce3 bpf: Do not use interfaces to define byte ordering in BPF evaluation.
This speeds up BPF evaluation by avoiding interface call overhead.

```
            │   initial   │         hey_look_no_interfaces         │         even_fewer_interfaces          │
            │   sec/op    │   sec/op     vs base                   │   sec/op     vs base                   │
Interpreter   26.31n ± 0%   21.87n ± 0%  -16.88% (p=0.000 n=21+20)   14.26n ± 0%  -45.80% (p=0.000 n=21+20)
```

PiperOrigin-RevId: 576591719
2023-10-25 11:32:34 -07:00
Etienne PerotandgVisor bot beba05ce32 BPF: Add "instrumented execution" mode.
This creates a duplicate BPF interpreter which keeps track of the
instructions and input bytes it accesses.

Having such a mode is useful for the following reasons:

  - For seccomp-bpf programs that the Sentry enforces from the sandboxed
    application, this allows it to check whether the program is
    deterministic based solely on the syscall number. For such syscalls,
    we can cache the result of executing the program, and never run the
    interpreter during syscall execution. (This optimization is not yet
    implemented, but this change enables it to be.)
  - For verification of correctness, coverage-based fuzzing is necessary.
    I plan to implement a fuzz-based test which verifies that the
    optimized and unoptimized versions of the same seccomp-bpf programs
    have the same behavior, and ensuring that the corpus achieves full
    coverage is necessary to ensure a good degree of correctness.

However, this mode is slower than it needs to when evaluating the
program in an application syscall (which is a very hot path), so this
has to live in a separate (sadly duplicated) function. The tests are
expanded to verify the for instrumented output, but also verify that
the "fast" version (aka the previous implementation) behaves the exact
same way, so this prevents the risk that code from one will drift away
behavior-wise.

To illustrate how much slower (not to mention it does allocations):

```
                        │ with_binary_order_removed │
                        │          sec/op           │
Interpreter                             14.26n ± 0%
InstrumentedInterpreter                 98.37n ± 3%
```

PiperOrigin-RevId: 576562506
2023-10-25 10:03:26 -07:00
Etienne PerotandgVisor bot 80ef8a68d9 bpf: Remove Input interface and simply use bytes as the input.
This removes the interface indirection from BPF evaluation, which is
a very hot path (runs for every application syscall for seccomp'd containers)
and simplifies the code in general.

```
            │   initial   │         hey_look_no_interfaces         │
            │   sec/op    │   sec/op     vs base                   │
Interpreter   26.31n ± 0%   21.12n ± 0%  -19.73% (p=0.000 n=21+20)
```

PiperOrigin-RevId: 576375947
2023-10-24 20:47:59 -07:00
Etienne PerotandgVisor bot b29a502a27 bpf: Add benchmark for interpreter speed.
This is a very hot path, as it is used for packet filtering and all syscalls
of applications that set a seccomp-bpf filter on themselves.

This is useful to quantify the benefit of removing its use of interfaces,
and in the future if anything else can be done to improve it further.

Initial data:

```
            │   initial   │
            │   sec/op    │
Interpreter   26.31n ± 0%
```

PiperOrigin-RevId: 574201377
2023-10-17 10:54:31 -07:00
Etienne PerotandgVisor bot 5b2aa3d40e BPF program builder: Add support for recording/analyzing fragment outcomes.
This adds a new `Record` function to `bpf.ProgramBuilder`, which returns a
function to stop recording that returns the "fragment" of the program made
of the instructions that were added between the time `Record` was called and
the time the stop function was called.

This fragment can in turn be interrogated for which `Outcomes` may happen
from executing it: returning a value, jumping to a label, jumping away from
the fragment, falling through.

This is useful while building complex BPF programs with nested rules. By
recording instructions added by a possibly-nested set of rules (the final
outcome of which is to jump to a known set of labels), we can now actually
verify the assertion that the instructions that were added indeed end up
jumping to one of the expected labels, and nothing else.

This is useful not just for safety but also optimization purposes. In an
upcoming refactor to argument matching code, I plan to add a "value matcher"
interface that renders rules that verify the value of the `A` register. Some
matchers may need to modify the `A` register in order to work, but others
don't. By checking whether the set of instructions modifies `A` or not, the
higher-level code can determine whether or not it needs to add code to reload
the value of the `A` register or not before moving on to the next matcher.

PiperOrigin-RevId: 571087694
2023-10-05 11:53:26 -07:00
Etienne PerotandgVisor bot fbd320a249 bpf: Use optimizer for seccomp-bpf programs.
This speeds up:

- The Sentry and the Gofer's seccomp-bpf programs
- User application seccomp-bpf programs
- Systrap and ptrace seccomp-bpf rules

Some benchmark results with Postgres:

```
                                   │    before     │                    opt                    │
                                   │    sec/op     │    sec/op     vs base                     │
SentrySystrap/Postgres/futex          88.82n ±  2%   81.29n ±  2%   -8.48% (p=0.000 n=519+510)
SentrySystrap/Postgres/nanosleep      116.9n ± 19%   115.9n ± 17%        ~ (p=0.859 n=350+317)
SentrySystrap/Postgres/sendmmsg       88.68n ±  1%   81.56n ±  1%   -8.04% (n=519+510)
SentrySystrap/Postgres/fstat          24.47n ±  3%   24.31n ±  6%        ~ (p=0.832 n=514+502)
[...]
SentrySystrap/Postgres-48             71.00n ±  8%   63.00n ±  6%  -11.27% (p=0.002 n=183+181)
```

PiperOrigin-RevId: 570931073
2023-10-05 00:51:48 -07:00
Etienne PerotandgVisor bot 67bb063c8f bpf: Implement BPF optimizer.
This performs a few lossless optimizations passes over BPF programs.

This change does minimal testing and does not test for correctness.
The next change incorporates this optimizer in the program builder which *is*
tested for correctness.

It is not used anywhere yet, but when putting it on the Sentry filters:

```
                                   │    before     │                    opt                    │
                                   │    sec/op     │    sec/op     vs base                     │
SentrySystrap/Postgres/futex          88.82n ±  2%   81.29n ±  2%   -8.48% (p=0.000 n=519+510)
SentrySystrap/Postgres/nanosleep      116.9n ± 19%   115.9n ± 17%        ~ (p=0.859 n=350+317)
SentrySystrap/Postgres/sendmmsg       88.68n ±  1%   81.56n ±  1%   -8.04% (n=519+510)
SentrySystrap/Postgres/fstat          24.47n ±  3%   24.31n ±  6%        ~ (p=0.832 n=514+502)
[...]
SentrySystrap/Postgres-48             71.00n ±  8%   63.00n ±  6%  -11.27% (p=0.002 n=183+181)
```

PiperOrigin-RevId: 570900358
2023-10-04 21:48:35 -07:00
Etienne PerotandgVisor bot aa8a460e02 bpf: Replace most uses of linux.BPFInstruction with bpf.Instruction.
`bpf.Instruction` is the same type as `linux.BPFInstruction`, except that it
uses the BPF instruction-to-string decoder to give a nice human-readable
stringification.

PiperOrigin-RevId: 570499020
2023-10-03 14:34:53 -07:00
Adin ScannellandgVisor bot 2911d8c3b8 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Ayush RanjanandgVisor bot 2026e1f078 Reformat codebase.
PiperOrigin-RevId: 449358041
2022-05-17 17:48:35 -07:00
Rahat MahmoodandgVisor bot 2b3172f385 Remove uses of the binary package from the rest of the sentry.
PiperOrigin-RevId: 372020696
2021-05-04 16:41:08 -07:00
Ting-Yu WangandgVisor bot ec5fb69513 Fix more nogo tests
PiperOrigin-RevId: 340536306
2020-11-03 15:23:32 -08:00
Ian LewisandgVisor bot 3a8953921e Add support for OCI seccomp filters in the sandbox.
OCI configuration includes support for specifying seccomp filters. In runc,
these filter configurations are converted into seccomp BPF programs and loaded
into the kernel via libseccomp. runsc needs to be a static binary so, for
runsc, we cannot rely on a C library and need to implement the functionality
in Go.

The generator added here implements basic support for taking OCI seccomp
configuration and converting it into a seccomp BPF program with the same
behavior as a program generated by libseccomp.

- New conditional operations were added to pkg/seccomp to support operations
  available in OCI.
- AllowAny and AllowValue were renamed to MatchAny and EqualTo to better reflect
  that syscalls matching the conditionals result in the provided action not
  simply SCMP_RET_ALLOW.
- BuildProgram in pkg/seccomp no longer panics if provided an empty list of
  rules. It now builds a program with the architecture sanity check only.
- ProgramBuilder now allows adding labels that are unused. However, backwards
  jumps are still not permitted.

Fixes #510

PiperOrigin-RevId: 331938697
2020-09-15 23:19:17 -07:00
Michael PrattandgVisor bot 458dbc511d Remove various uses of 'whitelist'
Updates #2972

PiperOrigin-RevId: 317113059
2020-06-18 09:03:39 -07:00
Adin ScannellandgVisor bot 5cd5c2536a Standardize on tools directory.
PiperOrigin-RevId: 291745021
2020-01-27 12:21:00 -08:00
Kevin KrakauerandgVisor bot 4da30beb39 Reorder BUILD license and load functions in gvisor.
PiperOrigin-RevId: 275139066
2019-10-16 16:40:30 -07:00
Michael PrattandgVisor bot c1ace9a854 Remove go_test from go_stateify and go_marshal
They are no-ops, so the standard rule works fine.

PiperOrigin-RevId: 268776264
2019-09-12 15:10:17 -07:00
Adin ScannellandShentubot add40fd6ad Update canonical repository.
This can be merged after:
https://github.com/google/gvisor-website/pull/77
  or
https://github.com/google/gvisor-website/pull/78

PiperOrigin-RevId: 253132620
2019-06-13 16:50:15 -07:00
Michael PrattandShentubot 4d52a55201 Change copyright notice to "The gVisor Authors"
Based on the guidelines at
https://opensource.google.com/docs/releasing/authors/.

1. $ rg -l "Google LLC" | xargs sed -i 's/Google LLC.*/The gVisor Authors./'
2. Manual fixup of "Google Inc" references.
3. Add AUTHORS file. Authors may request to be added to this file.
4. Point netstack AUTHORS to gVisor AUTHORS. Drop CONTRIBUTORS.

Fixes #209

PiperOrigin-RevId: 245823212
Change-Id: I64530b24ad021a7d683137459cafc510f5ee1de9
2019-04-29 14:26:23 -07:00
Michael PrattandShentubot 2a0c69b19f Remove license comments
Nothing reads them and they can simply get stale.

Generated with:
$ sed -i "s/licenses(\(.*\)).*/licenses(\1)/" **/BUILD

PiperOrigin-RevId: 231818945
Change-Id: Ibc3f9838546b7e94f13f217060d31f4ada9d4bf0
2019-01-31 11:12:53 -08:00
Ian GudgerandShentubot 8fce67af24 Use correct company name in copyright header
PiperOrigin-RevId: 217951017
Change-Id: Ie08bf6987f98467d07457bcf35b5f1ff6e43c035
2018-10-19 16:35:11 -07:00
Zhaozhong NiandShentubot 57d0fcbdbf Automated rollback of changelist 207037226
PiperOrigin-RevId: 207125440
Change-Id: I6c572afb4d693ee72a0c458a988b0e96d191cd49
2018-08-02 10:42:48 -07:00
Michael PrattandShentubot 60add78980 Automated rollback of changelist 207007153
PiperOrigin-RevId: 207037226
Change-Id: I8b5f1a056d4f3eab17846f2e0193bb737ecb5428
2018-08-01 19:57:32 -07:00
Zhaozhong NiandShentubot b9e1cf8404 stateify: convert all packages to use explicit mode.
PiperOrigin-RevId: 207007153
Change-Id: Ifedf1cc3758dc18be16647a4ece9c840c1c636c9
2018-08-01 15:43:24 -07:00
Zhaozhong NiandShentubot be7fcbc558 stateify: support explicit annotation mode; convert refs and stack packages.
We have been unnecessarily creating too many savable types implicitly.

PiperOrigin-RevId: 206334201
Change-Id: Idc5a3a14bfb7ee125c4f2bb2b1c53164e46f29a8
2018-07-27 10:17:21 -07:00
Zhengyu HeandShentubot d1ca50d49e Add SyscallRules that supports argument filtering
PiperOrigin-RevId: 198919043
Change-Id: I7f1f0a3b3430cd0936a4ee4fc6859aab71820bdf
2018-06-01 13:40:52 -07:00
Ian GudgerandShentubot b4765f782d Fix warning: redundant if ...; err != nil check, just return error instead.
This warning is produced by golint.

PiperOrigin-RevId: 195833381
Change-Id: Idd6a7e57e3cfdf00819f2374b19fc113585dc1e1
2018-05-08 09:51:56 -07:00
GooglerandAdin Scannell d02b74a5dc Check in gVisor.
PiperOrigin-RevId: 194583126
Change-Id: Ica1d8821a90f74e7e745962d71801c598c652463
2018-04-28 01:44:26 -04:00