aboutsummaryrefslogtreecommitdiffstats
path: root/sys/openbsd/init.go
diff options
context:
space:
mode:
authorAnton Lindqvist <anton@basename.se>2020-07-21 10:36:08 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-07-21 12:15:13 +0200
commit328906f3daa5e8e120f92e4d6418d1a5e7e8e19c (patch)
treeb2793abf8fd2c437984ba5a5196ec508fe78b107 /sys/openbsd/init.go
parent0d540696afbf8581369be2617aa05582bd5e0ba5 (diff)
sys/openbsd: break out rlimit
In the hopes of lowering the cyclomatic complexity.
Diffstat (limited to 'sys/openbsd/init.go')
-rw-r--r--sys/openbsd/init.go77
1 files changed, 41 insertions, 36 deletions
diff --git a/sys/openbsd/init.go b/sys/openbsd/init.go
index 78c69cc1a..67fa06f59 100644
--- a/sys/openbsd/init.go
+++ b/sys/openbsd/init.go
@@ -137,42 +137,7 @@ func (arch *arch) neutralize(c *prog.Call) {
flags := c.Args[0].(*prog.ConstArg)
flags.Val &= ^arch.MCL_FUTURE
case "setrlimit":
- rlimitMin := uint64(0)
- rlimitMax := uint64(math.MaxUint64)
- resource := c.Args[0].(*prog.ConstArg).Val & rlimitMask
- if resource == arch.RLIMIT_DATA {
- // OpenBSD performs a strict validation of the
- // RLIMIT_DATA soft limit during memory allocation.
- // Lowering the same limit could cause syz-executor to
- // run out of memory quickly. Therefore make sure to not
- // go lower than the default soft limit for the staff
- // group.
- rlimitMin = 1536 * 1024 * 1024
- } else if resource == arch.RLIMIT_STACK {
- // Do not allow the stack to grow beyond the initial
- // soft limit chosen by syz-executor. Otherwise,
- // syz-executor will most likely not be able to perform
- // any more heap allocations since they majority of
- // memory is reserved for the stack.
- rlimitMax = 1 * 1024 * 1024
- } else {
- break
- }
- ptr := c.Args[1].(*prog.PointerArg)
- if ptr.Res != nil {
- args := ptr.Res.(*prog.GroupArg).Inner
- for _, arg := range args {
- switch v := arg.(type) {
- case *prog.ConstArg:
- if v.Val < rlimitMin {
- v.Val = rlimitMin
- }
- if v.Val > rlimitMax {
- v.Val = rlimitMax
- }
- }
- }
- }
+ arch.neutralizeRlimit(c)
case "sysctl":
arch.neutralizeSysctl(c)
default:
@@ -180,6 +145,46 @@ func (arch *arch) neutralize(c *prog.Call) {
}
}
+func (arch *arch) neutralizeRlimit(c *prog.Call) {
+ rlimitMin := uint64(0)
+ rlimitMax := uint64(math.MaxUint64)
+ resource := c.Args[0].(*prog.ConstArg).Val & rlimitMask
+ if resource == arch.RLIMIT_DATA {
+ // OpenBSD performs a strict validation of the RLIMIT_DATA soft
+ // limit during memory allocation. Lowering the same limit could
+ // cause syz-executor to run out of memory quickly. Therefore
+ // make sure to not go lower than the default soft limit for the
+ // staff group.
+ rlimitMin = 1536 * 1024 * 1024
+ } else if resource == arch.RLIMIT_STACK {
+ // Do not allow the stack to grow beyond the initial soft limit
+ // chosen by syz-executor. Otherwise, syz-executor will most
+ // likely not be able to perform any more heap allocations since
+ // they majority of memory is reserved for the stack.
+ rlimitMax = 1 * 1024 * 1024
+ } else {
+ return
+ }
+
+ ptr := c.Args[1].(*prog.PointerArg)
+ if ptr.Res == nil {
+ return
+ }
+
+ args := ptr.Res.(*prog.GroupArg).Inner
+ for _, arg := range args {
+ switch v := arg.(type) {
+ case *prog.ConstArg:
+ if v.Val < rlimitMin {
+ v.Val = rlimitMin
+ }
+ if v.Val > rlimitMax {
+ v.Val = rlimitMax
+ }
+ }
+ }
+}
+
func (arch *arch) neutralizeSysctl(c *prog.Call) {
ptr := c.Args[0].(*prog.PointerArg)
if ptr.Res == nil {