sys/openbsd: break out rlimit

In the hopes of lowering the cyclomatic complexity.
This commit is contained in:
Anton Lindqvist 2020-07-21 10:36:08 +02:00 committed by Dmitry Vyukov
parent 0d540696af
commit 328906f3da

View File

@ -137,29 +137,40 @@ func (arch *arch) neutralize(c *prog.Call) {
flags := c.Args[0].(*prog.ConstArg)
flags.Val &= ^arch.MCL_FUTURE
case "setrlimit":
arch.neutralizeRlimit(c)
case "sysctl":
arch.neutralizeSysctl(c)
default:
arch.unix.Neutralize(c)
}
}
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.
// 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.
// 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
return
}
ptr := c.Args[1].(*prog.PointerArg)
if ptr.Res != nil {
if ptr.Res == nil {
return
}
args := ptr.Res.(*prog.GroupArg).Inner
for _, arg := range args {
switch v := arg.(type) {
@ -173,12 +184,6 @@ func (arch *arch) neutralize(c *prog.Call) {
}
}
}
case "sysctl":
arch.neutralizeSysctl(c)
default:
arch.unix.Neutralize(c)
}
}
func (arch *arch) neutralizeSysctl(c *prog.Call) {
ptr := c.Args[0].(*prog.PointerArg)