Skip to content

Commit df13fe5

Browse files
committed
prevent unveil from being called on <=6.3
1 parent 6063f10 commit df13fe5

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

unix/unveil_openbsd.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44

55
package unix
66

7+
import "fmt"
8+
79
// Unveil implements the unveil syscall.
810
// For more information see unveil(2).
911
// Note that the special case of blocking further
1012
// unveil calls is handled by UnveilBlock.
13+
//
14+
// Unveil requires OpenBSD 6.4 or later.
1115
func Unveil(path string, flags string) error {
16+
err := supportsUnveil()
17+
if err != nil {
18+
return err
19+
}
1220
pathBytes, err := BytePtrFromString(path)
1321
if err != nil {
1422
return err
@@ -22,6 +30,28 @@ func Unveil(path string, flags string) error {
2230

2331
// UnveilBlock blocks future unveil calls.
2432
// For more information see unveil(2).
33+
//
34+
// Unveil requires OpenBSD 6.4 or later.
2535
func UnveilBlock() error {
36+
err := supportsUnveil()
37+
if err != nil {
38+
return err
39+
}
2640
return unveil(nil, nil)
2741
}
42+
43+
// supportsUnveil checks for availability of the unveil(2) system call based
44+
// on the running OpenBSD version.
45+
func supportsUnveil() error {
46+
maj, min, err := majmin()
47+
if err != nil {
48+
return err
49+
}
50+
51+
// unveil is not available before 6.4
52+
if maj < 6 || (maj == 6 && min <= 3) {
53+
return fmt.Errorf("cannot use execpromises on OpenBSD %d.%d", maj, min)
54+
}
55+
56+
return nil
57+
}

0 commit comments

Comments
 (0)