Skip to content

Copybara import of the project:#9836

Merged
copybara-service[bot] merged 4 commits intomasterfrom
test_892506695
Mar 31, 2026
Merged

Copybara import of the project:#9836
copybara-service[bot] merged 4 commits intomasterfrom
test_892506695

Conversation

@copybara-service
Copy link
Copy Markdown
Contributor

Copybara import of the project:

--
6cbdbc5 by mohammadmseet-hue mohammadmseet@gmail.com:

Fix OOB read in blockwise quantized tensor + missing bounds checks

Bug 1: xnn_define_blockwise_quantized_tensor_value_v2 accesses dims[1]
without checking num_dims >= 2. With num_dims=1, dims[1] reads past the
caller-provided array — heap buffer overflow (confirmed with ASAN).

Bug 2: reshape_resize_bilinear_operator reads dim[0..3] without
checking num_dims >= 4. Missed by commit d45f452 which added this
check to other operators.

Bug 3: reshape_rope_operator accesses dim[num_dims-3] without checking
num_dims >= 3. With num_dims < 3, unsigned underflow in index
calculation.

--
3d7a7d6 by mohammadmseet-hue mohammadmseet@gmail.com:

Fix stack buffer overflow in static_slice and missing bounds checks in copy ops

Bug 1 — Stack buffer overflow in xnn_define_static_slice (static-slice.c:275-277)

xnn_define_static_slice() uses a local int64_t signed_offsets[XNN_MAX_TENSOR_DIMS]
(6 elements) array but iterates num_dims times without checking num_dims <= 6.
With num_dims=10, the loop writes 80 bytes into a 48-byte stack buffer — 32 bytes
of attacker-controlled stack corruption. Same pattern as Bug 1 in PR #9778.

xnn_define_static_slice_v2() has the identical issue with ends[XNN_MAX_TENSOR_DIMS].

Bug 2 — Missing bounds check in xnn_define_static_slice_v3 (static-slice.c:257-258)

memcpy(node->params.slice.begins, begins, num_dims * sizeof(int64_t)) writes
num_dims*8 bytes into begins[6] (48 bytes) without bounds checking.

Bug 3 — Missing bounds check in define_copy_node (copy.c:477)

memcpy into node->params.static_reshape.new_shape.dim without checking num_dims.
Affects xnn_define_static_reshape, xnn_define_static_expand_dims,
xnn_define_fuse_dims, and xnn_define_split_dim.

--
28e1a13 by mohammadmseet-hue mohammadmseet@gmail.com:

Fix stack buffer overflow in batch matrix multiply reshape

reshape_batch_matrix_multiply_nc() uses local arrays
batch_dims_c[XNN_MAX_TENSOR_DIMS] (6 elements) and
batch_strides_c[XNN_MAX_TENSOR_DIMS] (6 elements) but iterates
num_batch_dims times without checking num_batch_dims <= 6.

With num_batch_dims=10, writes past both 48-byte stack buffers.
Attacker-controlled values from batch_dims_a/b are written to the
overflow region — controlled stack corruption.

Reachable from all public xnn_reshape_batch_matrix_multiply_nc_*
APIs (f16, f32, pf16, pf32, qs8, qd8_f32_qc8w, qp8_f32_qc8w,
qdu8_f32_qc8w, bf16_f32).

FUTURE_COPYBARA_INTEGRATE_REVIEW=#9833 from mohammadmseet-hue:fix/bmm-num-batch-dims-check 28e1a13

mohammadmseet-hue and others added 4 commits March 31, 2026 19:50
Bug 1: xnn_define_blockwise_quantized_tensor_value_v2 accesses dims[1]
without checking num_dims >= 2. With num_dims=1, dims[1] reads past the
caller-provided array — heap buffer overflow (confirmed with ASAN).

Bug 2: reshape_resize_bilinear_operator reads dim[0..3] without
checking num_dims >= 4. Missed by commit d45f452 which added this
check to other operators.

Bug 3: reshape_rope_operator accesses dim[num_dims-3] without checking
num_dims >= 3. With num_dims < 3, unsigned underflow in index
calculation.
…n copy ops

Bug 1 — Stack buffer overflow in xnn_define_static_slice (static-slice.c:275-277)

xnn_define_static_slice() uses a local int64_t signed_offsets[XNN_MAX_TENSOR_DIMS]
(6 elements) array but iterates num_dims times without checking num_dims <= 6.
With num_dims=10, the loop writes 80 bytes into a 48-byte stack buffer — 32 bytes
of attacker-controlled stack corruption. Same pattern as Bug 1 in PR #9778.

xnn_define_static_slice_v2() has the identical issue with ends[XNN_MAX_TENSOR_DIMS].

Bug 2 — Missing bounds check in xnn_define_static_slice_v3 (static-slice.c:257-258)

memcpy(node->params.slice.begins, begins, num_dims * sizeof(int64_t)) writes
num_dims*8 bytes into begins[6] (48 bytes) without bounds checking.

Bug 3 — Missing bounds check in define_copy_node (copy.c:477)

memcpy into node->params.static_reshape.new_shape.dim without checking num_dims.
Affects xnn_define_static_reshape, xnn_define_static_expand_dims,
xnn_define_fuse_dims, and xnn_define_split_dim.
reshape_batch_matrix_multiply_nc() uses local arrays
batch_dims_c[XNN_MAX_TENSOR_DIMS] (6 elements) and
batch_strides_c[XNN_MAX_TENSOR_DIMS] (6 elements) but iterates
num_batch_dims times without checking num_batch_dims <= 6.

With num_batch_dims=10, writes past both 48-byte stack buffers.
Attacker-controlled values from batch_dims_a/b are written to the
overflow region — controlled stack corruption.

Reachable from all public xnn_reshape_batch_matrix_multiply_nc_*
APIs (f16, f32, pf16, pf32, qs8, qd8_f32_qc8w, qp8_f32_qc8w,
qdu8_f32_qc8w, bf16_f32).
@copybara-service copybara-service bot merged commit 1812bbe into master Mar 31, 2026
@copybara-service copybara-service bot deleted the test_892506695 branch March 31, 2026 21:06
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.

2 participants