diff options
Diffstat (limited to 'sys/openbsd')
| -rw-r--r-- | sys/openbsd/init.go | 77 |
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 { |
