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,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 {