Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f93e047

Browse files
author
octeep
committed
add pledge call on OpenBSD
1 parent 863440f commit f93e047

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

cmd/wireproxy/main.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,29 @@ import (
88

99
"github.com/akamensky/argparse"
1010
"github.com/octeep/wireproxy"
11+
"suah.dev/protect"
1112
)
1213

1314
const daemonProcess = "daemon-process"
1415

16+
func pledgeOrPanic(promises string) {
17+
err := protect.Pledge(promises)
18+
if err != nil {
19+
log.Panic(err)
20+
}
21+
}
22+
1523
func main() {
24+
pledgeOrPanic("stdio rpath inet dns proc exec")
25+
1626
isDaemonProcess := len(os.Args) > 1 && os.Args[1] == daemonProcess
1727
args := os.Args
1828
if isDaemonProcess {
29+
// remove proc and exec if they are not needed
30+
pledgeOrPanic("stdio rpath inet dns")
1931
args = []string{args[0]}
2032
args = append(args, os.Args[2:]...)
2133
}
22-
2334
parser := argparse.NewParser("wireproxy", "Userspace wireguard client for proxying")
2435

2536
config := parser.String("c", "config", &argparse.Options{Required: true, Help: "Path of configuration file"})
@@ -32,6 +43,11 @@ func main() {
3243
return
3344
}
3445

46+
if !*daemon {
47+
// remove proc and exec if they are not needed
48+
pledgeOrPanic("stdio rpath inet dns")
49+
}
50+
3551
conf, err := wireproxy.ParseConfig(*config)
3652
if err != nil {
3753
log.Panic(err)
@@ -64,6 +80,9 @@ func main() {
6480
return
6581
}
6682

83+
// no file access is allowed from now on
84+
pledgeOrPanic("stdio inet dns")
85+
6786
tnet, err := wireproxy.StartWireguard(conf.Device)
6887
if err != nil {
6988
log.Panic(err)

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ require (
2121
golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9 // indirect
2222
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba // indirect
2323
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
24+
suah.dev/protect v1.2.0 // indirect
2425
)

go.sum

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,7 @@ golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7w
744744
golang.org/x/sys v0.0.0-20210314195730-07df6a141424/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
745745
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
746746
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
747+
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
747748
golang.org/x/sys v0.0.0-20211103235746-7861aae1554b/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
748749
golang.org/x/sys v0.0.0-20211110154304-99a53858aa08/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
749750
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
@@ -999,3 +1000,5 @@ sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:w
9991000
sigs.k8s.io/structured-merge-diff/v4 v4.0.3/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
10001001
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
10011002
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
1003+
suah.dev/protect v1.2.0 h1:4G4V43yVYXCjLFzaE9QJR0fLo3rf5vNBS9YxyoI19DU=
1004+
suah.dev/protect v1.2.0/go.mod h1:Ocn1yqUskqe/is6N2bxQxtT+fegbvQsOFyHbJAQu9XE=

0 commit comments

Comments
 (0)