Files
Kevin ZhaoandgVisor bot 51b87d918a sentry: use cryptographic PRNG for security-sensitive randomization
Replace `math/rand` with `gvisor.dev/gvisor/pkg/rand` (backed by `crypto/rand`
or `getrandom(2)`) in 5 security-sensitive code paths that currently use the
non-cryptographic `math/rand`:

| File | Usage | Risk |
|------|-------|------|
| `mm/syscalls.go` | Stack ASLR | Stack address prediction aids ROP |
| `systrap/stub_unsafe.go` | Stub code layout | Sentry code location prediction |
| `systrap/usertrap/usertrap_amd64.go` | Trap table layout | Syscall dispatch hijacking |
| `netlink/port/port.go` | Port allocation | Port collision/hijacking |
| `inet/abstract_socket_namespace.go` | Socket autobind | Socket name prediction |

`math/rand` is not cryptographically secure — its output is deterministic given
the internal state, which can be recovered from observed outputs (e.g., by
observing one's own stack address via `/proc/self/maps` and deducing future
randomization outputs for other processes in the same sandbox).

`gvisor.dev/gvisor/pkg/rand` already provides matching API (`Uint32`, `Uint64`,
`Int63n`) backed by `getrandom(2)` / `crypto/rand.Reader`.

**Related**: CVE-2024-10026 and CVE-2024-10603 fixed the same class of weakness
(`math/rand` for network identifiers) in the TCP/IP stack. These 5 files were
not addressed by those fixes.

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/gvisor/pull/12695 from KevinZhao:fix/weak-prng-security-sensitive d6428ea368fd34d95d395a06bf99879678db2ac7
PiperOrigin-RevId: 892755849
2026-04-01 00:16:04 -07:00

23 lines
393 B
Python

load("//tools:defs.bzl", "go_library", "go_test")
package(
default_applicable_licenses = ["//:license"],
licenses = ["notice"],
)
go_library(
name = "port",
srcs = ["port.go"],
visibility = ["//pkg/sentry:internal"],
deps = [
"//pkg/rand",
"//pkg/sync",
],
)
go_test(
name = "port_test",
srcs = ["port_test.go"],
library = ":port",
)