Skip to content

ext/lists: lists.range() unbounded memory allocation allows OOM DoS #1309

@marwan9696

Description

@marwan9696

lists.range(N) in ext/lists.go allocates N elements with no upper bound check. A large value causes OOM and crashes the process.

This is exploitable in Kubernetes ValidatingAdmissionPolicy where user-controlled fields feed into CEL expressions. For example:

validations:
  - expression: "lists.range(object.spec.replicas).all(i, i >= 0)"

An attacker sets replicas: 2147483647 and the API server allocates ~16 GB, gets OOM-killed.

The root cause is genRange() at line 406:

func genRange(n types.Int) (ref.Val, error) {
    var newList []ref.Val
    for i := types.Int(0); i < n; i++ {
        newList = append(newList, i)
    }
    return types.DefaultTypeAdapter.NativeToValue(newList), nil
}

The cost estimator doesn't help at Lists v1-v2 because cost estimators for lists.range are only registered at v3+ (line 354). CostLimit is also opt-in.

Confirmed: lists.range(10000000) allocates 865 MB in ~5 seconds.

I'll submit a PR with the fix — adding a maxRangeSize check and rejecting negative values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions