25 Commits
Author SHA1 Message Date
Etienne PerotandgVisor bot e6979cb4d6 seccomp: Reorder generated syscall rules for better efficiency.
This subdivides all `RuleSet`s into single-syscall rulesets, and then
classifies them depending on:

- Whether they are "trivial" or not, where "trivial" means that the syscall
  rules do not perform any verification of the syscall arguments or RIP.
- Whether they are marked "hot" or not, where "hot" means "expected to be
  frequently called".

It then orders the program as follows:

- All hot non-trivial rules go first. This makes it so that the host kernel
  can clear the syscall faster for frequently-called syscalls. These are
  checked linearly, as they tend to follow a Pareto distribution in terms of
  frequency. If they need a vsyscall check, that check is added individually.
- All cold rules go next, and form a BST. This mimics the structure of the BST
  construction that existed prior to this change.
- Lastly, all the trivial syscalls are added as a last BST.

This speeds up rule evaluation because it maximizes the use of Linux's
seccomp cache for trivial syscalls. These are therefore only ever checked
once, so they can stay at the "bottom" of the program.
All remaining (non-trivial) syscalls are ordered such that hot syscalls
are checked first, and then cold syscalls are checked with a BST.

This is a complex and security-sensitive change, but fuzz testing with full
branch coverage has shown that this has the exact same behavior as a BPF
program taken from before any of my recent seccomp/BPF changes (other than
the one adding non-negative FD checks to all `ioctl(2)` system calls).

Some benchmark results ("orig" is the state before this change):

```
                                      │     orig      │                  reordered                   │
                                      │    sec/op     │    sec/op      vs base                       │
SentrySystrap/futex                      79.44n ±  2%    73.93n ±  2%   -6.93% (n=729+722)
SentrySystrap/nanosleep                  112.3n ± 12%    107.2n ± 12%        ~ (p=0.505 n=482+477)
SentrySystrap/sendmmsg                   88.50n ±  1%    81.62n ±  1%   -7.78% (n=729+722)
SentrySystrap/fstat                      30.80n ±  2%    30.63n ±  3%        ~ (p=0.903 n=722+712)
[...]
SentrySystrap/Postgres-48                64.30n ±  5%    61.74n ±  6%   -3.97% (p=0.039 n=376+377)
```

PiperOrigin-RevId: 582808055
2023-11-15 14:32:12 -08:00
Etienne PerotandgVisor bot 56be4a9921 seccomp: Add method to ValueMatcher to generate fuzz test cases.
This adds a method called `InterestingValues` to `ValueMatcher` and
`halfValueMatcher` that lists the values worth testing for this argument.

Then, the new `SyscallRules.UsefulTestCases` function aggregates all of
this into a set of useful test cases that can be used to seed the corpus
of a seccomp fuzz test.

PiperOrigin-RevId: 581148821
2023-11-10 00:35:41 -08:00
Etienne PerotandgVisor bot 260873b693 seccomp: Implement basic SyscallRule optimizer.
This doesn't introduce new optimizations, but creates a framework for
optimizations to be expressed over a `SyscallRule`. Such rules are
recursively applied across the tree of `SyscallRule`s in a similar manner
as the BPF optimizer is applied across BPF bytecode.

This also removes the need for a `merge` function that is aware of `Or` rule
semantics, as the current set of basic optimizers will achieve the same
result.

PiperOrigin-RevId: 578347984
2023-10-31 17:16:09 -07:00
Etienne PerotandgVisor bot 663e69bde4 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 d4973670c3 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
gVisor bot c98ccb40b8 Merge pull request #8670 from avagin:go_embed_data
PiperOrigin-RevId: 515200401
2023-03-08 18:42:04 -08:00
Andrei Vagin a95d591ab9 Stop using go_embed_data
It will be depricated in the next rules_go.
2023-03-08 15:05:58 -08:00
Adin ScannellandgVisor bot 1ceb814544 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Zach KoopmansandgVisor bot 8a2f7e716d [syserror] Split usermem package
Split usermem package to help remove syserror dependency in go_marshal.
New hostarch package contains code not dependent on syserror.

PiperOrigin-RevId: 365651233
2021-03-29 13:30:21 -07:00
Ayush RanjanandgVisor bot a9441aea27 [op] Replace syscall package usage with golang.org/x/sys/unix in pkg/.
The syscall package has been deprecated in favor of golang.org/x/sys.

Note that syscall is still used in the following places:
- pkg/sentry/socket/hostinet/stack.go: some netlink related functionalities
  are not yet available in golang.org/x/sys.
- syscall.Stat_t is still used in some places because os.FileInfo.Sys() still
  returns it and not unix.Stat_t.

Updates #214

PiperOrigin-RevId: 360701387
2021-03-03 10:25:58 -08:00
Rahat MahmoodandgVisor bot 4f462b0ed9 Convert uses of the binary package in kernel to go-marshal.
PiperOrigin-RevId: 335077195
2020-10-02 12:24:24 -07:00
Adin ScannellandgVisor bot b0c53f8475 Add nogo support to go_binary and go_test targets.
Updates #3374

PiperOrigin-RevId: 328378700
2020-08-25 12:18:25 -07:00
gVisor bot 20be1c0e63 Merge pull request #3476 from zhlhahaha:1930
PiperOrigin-RevId: 326563255
2020-08-13 17:59:00 -07:00
Howard Zhang cdef21c3d5 enable seccomp test on arm64
syscalls in ARM64 is different from that in X86_64, use
differen syscallrules for each arch.

The auditnumber are also different for different arch.
Use LINUX_AUDIT_ARCH to get correct auditnumber.

Signed-off-by: Howard Zhang <howard.zhang@arm.com>
2020-08-12 13:01:49 +08:00
Adin ScannellandgVisor bot 0efa8168c7 Update visibility.
PiperOrigin-RevId: 294265019
2020-02-10 11:30:21 -08:00
Adin ScannellandgVisor bot d29e59af9f Standardize on tools directory.
PiperOrigin-RevId: 291745021
2020-01-27 12:21:00 -08:00
Michael PrattandgVisor bot df5d377521 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
Bin LuandShentubot ebe2f78d9b Add arm64 support to pkg/seccomp
Signed-off-by: Bin Lu <bin.lu@arm.com>
PiperOrigin-RevId: 246622505
Change-Id: I803639a0c5b0f75959c64fee5385314214834d10
2019-05-03 22:03:59 -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
Adin ScannellandShentubot 75cd70ecc9 Track paths and provide a rename hook.
This change also adds extensive testing to the p9 package via mocks. The sanity
checks and type checks are moved from the gofer into the core package, where
they can be more easily validated.

PiperOrigin-RevId: 218296768
Change-Id: I4fc3c326e7bf1e0e140a454cbacbcc6fd617ab55
2018-10-23 00:20:15 -07:00
Adin ScannellandShentubot 463e73d46d Add seccomp filter configuration to ptrace stubs.
This is a defense-in-depth measure. If the sentry is compromised, this prevents
system call injection to the stubs. There is some complexity with respect to
ptrace and seccomp interactions, so this protection is not really available
for kernel versions < 4.8; this is detected dynamically.

Note that this also solves the vsyscall emulation issue by adding in
appropriate trapping for those system calls. It does mean that a compromised
sentry could theoretically inject these into the stub (ignoring the trap and
resume, thereby allowing execution), but they are harmless.

PiperOrigin-RevId: 216647581
Change-Id: Id06c232cbac1f9489b1803ec97f83097fcba8eb8
2018-10-10 22:40:28 -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
GooglerandAdin Scannell d02b74a5dc Check in gVisor.
PiperOrigin-RevId: 194583126
Change-Id: Ica1d8821a90f74e7e745962d71801c598c652463
2018-04-28 01:44:26 -04:00