Skip to content

Commit 83ec58a

Browse files
authored
Use unveil(2) on OpenBSD (#1194)
After #1175 removed ioctl(2) fallback code shelling out to ifconfig(8), there is no code left (compiled on OpenBSD) that would fork(2) or execve(2). Drop the ability to run any executable file to double down on this, thus reducing the attack surface of this this experimental, internet facing daemon running as root. pledge(2) is doable, but needs more polish. unveil(2), however, is as simple as it gets. On other systems, this code is a NOOP, but can still help to implement similar safety belts.
1 parent b436052 commit 83ec58a

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

cmd/yggdrasil/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"strings"
1515
"syscall"
1616

17+
"suah.dev/protect"
18+
1719
"github.com/gologme/log"
1820
gsyslog "github.com/hashicorp/go-syslog"
1921
"github.com/hjson/hjson-go/v4"
@@ -39,6 +41,20 @@ type node struct {
3941

4042
// The main function is responsible for configuring and starting Yggdrasil.
4143
func main() {
44+
// Not all operations are coverable with pledge(2), so immediately
45+
// limit file system access with unveil(2), effectively preventing
46+
// "proc exec" promises right from the start:
47+
//
48+
// - read arbitrary config file
49+
// - create/write arbitrary log file
50+
// - read/write/chmod/remove admin socket, if at all
51+
if err := protect.Unveil("/", "rwc"); err != nil {
52+
panic(fmt.Sprintf("unveil: / rwc: %v", err))
53+
}
54+
if err := protect.UnveilBlock(); err != nil {
55+
panic(fmt.Sprintf("unveil: %v", err))
56+
}
57+
4258
genconf := flag.Bool("genconf", false, "print a new config to stdout")
4359
useconf := flag.Bool("useconf", false, "read HJSON/JSON config from stdin")
4460
useconffile := flag.String("useconffile", "", "read HJSON/JSON config from specified file path")

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ require (
4545
github.com/mattn/go-runewidth v0.0.15 // indirect
4646
github.com/olekukonko/tablewriter v0.0.5
4747
github.com/vishvananda/netns v0.0.4 // indirect
48+
suah.dev/protect v1.2.4
4849
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
112112
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
113113
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259 h1:TbRPT0HtzFP3Cno1zZo7yPzEEnfu8EjLfl6IU9VfqkQ=
114114
gvisor.dev/gvisor v0.0.0-20230927004350-cbd86285d259/go.mod h1:AVgIgHMwK63XvmAzWG9vLQ41YnVHN0du0tEC46fI7yY=
115+
suah.dev/protect v1.2.4 h1:iVZG/zQB63FKNpITDYM/cXoAeCTIjCiXHuFVByJFDzg=
116+
suah.dev/protect v1.2.4/go.mod h1:vVrquYO3u1Ep9Ez2z8x+6N6/czm+TBmWKZfiXU2tb54=

0 commit comments

Comments
 (0)