Skip to content

Harden operator creation and reshape against null dereference and overflow - #11484

Open
anagnorisis2peripeteia wants to merge 1 commit into
google:masterfrom
anagnorisis2peripeteia:operator-lifecycle-validation-hardening
Open

anagnorisis2peripeteia wants to merge 1 commit into
google:masterfrom
anagnorisis2peripeteia:operator-lifecycle-validation-hardening

Conversation

@anagnorisis2peripeteia

Copy link
Copy Markdown
Contributor

Summary

This PR hardens operator creation and reshape routines across multiple
operators in src/operators/ against null pointer dereferences, integer
overflows in stride, workspace, and reduction calculations, and invalid or
unbounded parameters:

  1. constant-pad-nd:

    • Validate constant_pad_op_out and padding_value in
      xnn_create_constant_pad_nd_x8/x16/x32 before dereferencing.
    • Validate input_shape, pre_paddings, and post_paddings in
      reshape_constant_pad_nd when num_dims != 0.
  2. slice-nd:

    • Validate slice_op_out in create_slice_nd.
    • Validate input_shape, offsets, and sizes in reshape_slice_nd.
  3. transpose-nd:

    • Validate transpose_op_out in create_transpose_nd.
    • Validate perm and input_shape in reshape_transpose_nd.
    • Guard input_stride and output_stride multiplications and accumulation
      against integer overflow using xnn_safe_mul.
  4. reduce-nd:

    • Validate reduce_op_out, params, and cvt_params in create_reduce_nd.
    • Validate num_input_dims, input_shape, num_reduction_axes, and
      reduction_axes in reshape_reduce_nd.
    • Bounds-check negative reduction axes against [-num_input_dims, 0).
    • Guard num_output_elements, workspace_size, num_reduction_elements,
      and zero_size against integer overflow using xnn_safe_mul and
      xnn_safe_add.
  5. Pooling Operators:

    • Validate operator output pointers in argmax-pooling-nhwc,
      average-pooling-nhwc, max-pooling-nhwc, and unpooling-nhwc.
    • Validate params pointer when params_size != 0 in max-pooling-nhwc.
  6. Unit Tests:

    • Added regression test cases covering null operator output pointers,
      null argument pointers, invalid axes, and stride/workspace overflows
      across test/operators/*-test.cc.

Testing

  • Built and verified tests in clean build (build/): 53/53 tests passed.
  • Built and verified with UBSan (build-ubsan/): 53/53 tests passed with zero
    sanitizer warnings.
  • Verified all static and subgraph integration tests passed cleanly.
  • Strict 80-character line length limit maintained throughout.

@anagnorisis2peripeteia
anagnorisis2peripeteia force-pushed the operator-lifecycle-validation-hardening branch from 7b7c7b4 to 6c32319 Compare October 2, 2026 17:23
anagnorisis2peripeteia added a commit to anagnorisis2peripeteia/XNNPACK that referenced this pull request Oct 7, 2026
…erflow

Split from google#11484 (operator-lifecycle-validation-hardening) for
independent review and landing: google#11459 touches the same reshape function
and the hunks interleave.
…verflow

reduce-nd split into google#11514: google#11459 touches the same reshape function with interleaving hunks.
@anagnorisis2peripeteia
anagnorisis2peripeteia force-pushed the operator-lifecycle-validation-hardening branch from 6c32319 to 315a68c Compare October 12, 2026 12:51
anagnorisis2peripeteia added a commit to anagnorisis2peripeteia/XNNPACK that referenced this pull request Oct 12, 2026
…erflow

Split from google#11484 (operator-lifecycle-validation-hardening) for
independent review and landing: google#11459 touches the same reshape function
and the hunks interleave.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant