Skip to content

Commit

Permalink
Merge pull request opencontainers#106 from Mashimiao/runtime-test-no-…
Browse files Browse the repository at this point in the history
…new-priviledges-validation

runtimetest: add NoNewPriviledges validation
  • Loading branch information
Mrunal Patel authored Jun 10, 2016
2 parents bfaf033 + 70d39bd commit 0b5e2eb
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion cmd/runtimetest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
"github.com/urfave/cli"
)

// PR_GET_NO_NEW_PRIVS isn't exposed in Golang so we define it ourselves copying the value from
// the kernel
const PR_GET_NO_NEW_PRIVS = 39

type validation func(*rspec.Spec) error

func loadSpecConfig() (spec *rspec.Spec, err error) {
Expand Down Expand Up @@ -98,6 +102,17 @@ func validateProcess(spec *rspec.Spec) error {
}
}

ret, _, errno := syscall.Syscall6(syscall.SYS_PRCTL, PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0, 0)
if errno != 0 {
return errno
}
if spec.Process.NoNewPrivileges && ret != 1 {
return fmt.Errorf("NoNewPrivileges expected: true, actual: false")
}
if !spec.Process.NoNewPrivileges && ret != 0 {
return fmt.Errorf("NoNewPrivileges expected: false, actual: true")
}

return nil
}

Expand Down Expand Up @@ -334,7 +349,7 @@ func main() {
app.UsageText = "runtimetest [options]"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "log-level",
Name: "log-level",
Value: "error",
Usage: "Log level (panic, fatal, error, warn, info, or debug)",
},
Expand Down

0 comments on commit 0b5e2eb

Please sign in to comment.