Skip to content

Commit 2dcdcab

Browse files
shailend-ggvisor-bot
authored andcommitted
Make --allow-packet-socket-write a public flag.
This flag is now required for Docker versions 28 and beyond to function inside gVisor, as dockerd sends unsolicited ARP/NA requests using AF_PACKET sockets. The flag is no longer test-only. The docker behavior to send the ARP/NA pkts was introduced in eaa84bc [1]. Failure to send was made a hard error in 422e056 [2], and in bc130f36 [3], docker evolved to rely on these packets being sent. [1] moby/moby@eaa84bc8f4 [2] moby/moby@422e056b0f [3] moby/moby@bc130f367d PiperOrigin-RevId: 838942720
1 parent 86e78c1 commit 2dcdcab

File tree

6 files changed

+24
-13
lines changed

6 files changed

+24
-13
lines changed

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ INTEGRATION_TARGETS := //test/image:image_test //test/e2e:integration_test
369369

370370
docker-tests: load-basic $(RUNTIME_BIN)
371371
@$(call install_runtime,$(RUNTIME),) # Clear flags.
372-
@$(call install_runtime,$(RUNTIME)-docker,--net-raw) # Used by TestDocker*.
372+
@$(call install_runtime,$(RUNTIME)-docker,--net-raw --allow-packet-socket-write) # Used by TestDocker*.
373373
@$(call install_runtime,$(RUNTIME)-fdlimit,--fdlimit=2000) # Used by TestRlimitNoFile.
374374
@$(call install_runtime,$(RUNTIME)-dcache,--fdlimit=2000 --dcache=100) # Used by TestDentryCacheLimit.
375375
@$(call install_runtime,$(RUNTIME)-host-uds,--host-uds=all) # Used by TestHostSocketConnect.
@@ -386,13 +386,13 @@ plugin-network-tests: RUNSC_TARGET=--config plugin-tldk //runsc:runsc-plugin-sta
386386

387387
overlay-tests: load-basic $(RUNTIME_BIN)
388388
@$(call install_runtime,$(RUNTIME)-overlay,--overlay2=all:dir=/tmp)
389-
@$(call install_runtime,$(RUNTIME)-overlay-docker,--net-raw --overlay2=all:dir=/tmp)
389+
@$(call install_runtime,$(RUNTIME)-overlay-docker,--net-raw --allow-packet-socket-write --overlay2=all:dir=/tmp)
390390
@$(call test_runtime_cached,$(RUNTIME)-overlay,--test_env=TEST_OVERLAY=true $(INTEGRATION_TARGETS))
391391
.PHONY: overlay-tests
392392

393393
swgso-tests: load-basic $(RUNTIME_BIN)
394394
@$(call install_runtime,$(RUNTIME)-swgso,--software-gso=true --gso=false)
395-
@$(call install_runtime,$(RUNTIME)-swgso-docker,--net-raw --software-gso=true --gso=false)
395+
@$(call install_runtime,$(RUNTIME)-swgso-docker,--net-raw --allow-packet-socket-write --software-gso=true --gso=false)
396396
@$(call test_runtime_cached,$(RUNTIME)-swgso,$(INTEGRATION_TARGETS))
397397
.PHONY: swgso-tests
398398

@@ -406,13 +406,13 @@ kvm-tests: load-basic $(RUNTIME_BIN)
406406
@if ! test -w /dev/kvm; then sudo chmod a+rw /dev/kvm; fi
407407
@$(call test,//pkg/sentry/platform/kvm:kvm_test)
408408
@$(call install_runtime,$(RUNTIME)-kvm,--platform=kvm)
409-
@$(call install_runtime,$(RUNTIME)-kvm-docker,--net-raw --platform=kvm)
409+
@$(call install_runtime,$(RUNTIME)-kvm-docker,--net-raw --allow-packet-socket-write --platform=kvm)
410410
@$(call test_runtime_cached,$(RUNTIME)-kvm,$(INTEGRATION_TARGETS))
411411
.PHONY: kvm-tests
412412

413413
systrap-tests: load-basic $(RUNTIME_BIN)
414414
@$(call install_runtime,$(RUNTIME)-systrap,--platform=systrap)
415-
@$(call install_runtime,$(RUNTIME)-systrap-docker,--net-raw --platform=systrap)
415+
@$(call install_runtime,$(RUNTIME)-systrap-docker,--net-raw --allow-packet-socket-write --platform=systrap)
416416
@$(call test_runtime_cached,$(RUNTIME)-systrap,$(INTEGRATION_TARGETS))
417417
.PHONY: systrap-tests
418418

g3doc/user_guide/tutorials/docker-in-gvisor.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,28 @@ network driver and the bridge network driver are tested and supported.
99
### NOTE on runsc setup
1010

1111
To run docker within gvisor, runsc must be enabled to allow raw sockets. This is
12-
not the default, `--net-raw` must be passed to runsc. To use the following
13-
tutorial, that means having the following runtimes configuration in
14-
`/etc/docker/daemon.json`:
12+
not the default, `--net-raw` must be passed to runsc.
13+
14+
In addition, Docker versions 28 and beyond need the ability to write to
15+
AF_PACKET sockets. This is because dockerd sends unsolicited ARP/NA requests
16+
when bringing up interfaces. To allow this, the `--allow-packet-socket-write` is
17+
also to be supplied (the default behavior is to disallow writes to AF_PACKET
18+
sockets).
19+
20+
To use the following tutorial, that means having the following runtimes
21+
configuration in `/etc/docker/daemon.json`:
22+
23+
> **Note:** `--allow-packet-socket-write` allows sandboxed code to craft
24+
> arbitrary packets. It is only needed for Docker versions 28 and beyond.
1525
1626
```json
1727
{
1828
"runtimes": {
1929
"runsc": {
2030
"path": "/usr/local/bin/runsc",
2131
"runtimeArgs": [
22-
"--net-raw"
32+
"--net-raw",
33+
"--allow-packet-socket-write"
2334
]
2435
}
2536
}

images/basic/docker/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ RUN curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings
88
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
99
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" > /etc/apt/sources.list.d/docker.list && \
1010
apt-get update && \
11-
apt-get install -qqy docker-ce=5:27.5.1-1~ubuntu.24.04~noble docker-ce-cli=5:27.5.1-1~ubuntu.24.04~noble containerd.io docker-buildx-plugin docker-compose-plugin iproute2
11+
apt-get install -qqy docker-ce=5:28.5.2-1~ubuntu.24.04~noble docker-ce-cli=5:28.5.2-1~ubuntu.24.04~noble containerd.io docker-buildx-plugin docker-compose-plugin iproute2
1212

1313
COPY start-dockerd.sh .
1414
CMD /start-dockerd.sh

runsc/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ type Config struct {
120120
EnableRaw bool `flag:"net-raw"`
121121

122122
// AllowPacketEndpointWrite enables write operations on packet endpoints.
123-
AllowPacketEndpointWrite bool `flag:"TESTONLY-allow-packet-endpoint-write"`
123+
AllowPacketEndpointWrite bool `flag:"allow-packet-socket-write"`
124124

125125
// HostGSO indicates that host segmentation offload is enabled.
126126
HostGSO bool `flag:"gso"`

runsc/config/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func RegisterFlags(flagSet *flag.FlagSet) {
145145
// Flags that control sandbox runtime behavior: network related.
146146
flagSet.Var(networkTypePtr(NetworkSandbox), "network", "specifies which network to use: sandbox (default), host, none. Using network inside the sandbox is more secure because it's isolated from the host network.")
147147
flagSet.Bool("net-raw", false, "enable raw sockets. When false, raw sockets are disabled by removing CAP_NET_RAW from containers (`runsc exec` will still be able to utilize raw sockets). Raw sockets allow malicious containers to craft packets and potentially attack the network.")
148+
flagSet.Bool("allow-packet-socket-write", false, "allow writes on AF_PACKET sockets. When false, writes on AF_PACKET sockets will fail. When turned on, untrusted workloads may potentially attack the network because of the ability to craft arbitrary packets.")
148149
flagSet.Bool("gso", true, "enable host segmentation offload if it is supported by a network device.")
149150
flagSet.Bool("software-gso", true, "enable gVisor segmentation offload when host offload can't be enabled.")
150151
flagSet.Bool("gvisor-gro", false, "enable gVisor generic receive offload")
@@ -171,7 +172,6 @@ func RegisterFlags(flagSet *flag.FlagSet) {
171172
// Test flags, not to be used outside tests, ever.
172173
flagSet.Bool("TESTONLY-unsafe-nonroot", false, "TEST ONLY; do not ever use! This skips many security measures that isolate the host from the sandbox.")
173174
flagSet.String("TESTONLY-test-name-env", "", "TEST ONLY; do not ever use! Used for automated tests to improve logging.")
174-
flagSet.Bool("TESTONLY-allow-packet-endpoint-write", false, "TEST ONLY; do not ever use! Used for tests to allow writes on packet sockets.")
175175
flagSet.Bool("TESTONLY-afs-syscall-panic", false, "TEST ONLY; do not ever use! Used for tests exercising gVisor panic reporting.")
176176
flagSet.String("TESTONLY-autosave-image-path", "", "TEST ONLY; enable auto save for syscall tests and set path for state file.")
177177
flagSet.Bool("TESTONLY-autosave-resume", false, "TEST ONLY; enable auto save and resume for syscall tests and set path for state file.")

test/runner/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ func runRunsc(tc *gtest.TestCase, spec *specs.Spec) error {
320320
"-network", *network,
321321
"-log-format=text",
322322
"-TESTONLY-unsafe-nonroot=true",
323-
"-TESTONLY-allow-packet-endpoint-write=true",
323+
"-allow-packet-socket-write=true",
324324
fmt.Sprintf("-panic-signal=%d", unix.SIGTERM),
325325
fmt.Sprintf("-iouring=%t", *ioUring),
326326
"-watchdog-action=panic",

0 commit comments

Comments
 (0)