Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GPU] fix out-of-bounds read in convolution f16 1x1 kernel (#36921)

Mikolaj Roszczyk63aa78679123
diff --git a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_f16_1x1.cl b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_f16_1x1.cl
index f1a5da9b9ea..2abf6a45bd2 100644
--- a/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_f16_1x1.cl
+++ b/src/plugins/intel_gpu/src/kernel_selector/cl_kernels/convolution_gpu_bfyx_f16_1x1.cl
@@ -162,7 +162,21 @@ KERNEL(convolution_b_fs_yx_fsv16_1x1)(
#else // PADDED_INPUT
#if X_BLOCK_SIZE > 1
- src = UNIT_BLOCK_READ_VEC(input, input_offset + k * input_fs_pitch + input_y * input_y_pitch + input_x * input_x_pitch);
+ if (xy * X_BLOCK_SIZE + X_BLOCK_SIZE <= INPUT0_SIZE_X * INPUT0_SIZE_Y) {
+ src = UNIT_BLOCK_READ_VEC(input, input_offset + k * input_fs_pitch + input_y * input_y_pitch + input_x * input_x_pitch);
+ } else {
+ __attribute__((opencl_unroll_hint(X_BLOCK_SIZE)))
+ for (int i = 0; i < X_BLOCK_SIZE; i++) {
+ if (xy * X_BLOCK_SIZE + i >= INPUT0_SIZE_X * INPUT0_SIZE_Y)
+ break;
+
+ const uint xb = (input_x + i) % INPUT0_SIZE_X;
+ const uint yb = input_y + (input_x + i) / INPUT0_SIZE_X;
+ const uint input_idx = input_offset + k * input_fs_pitch + yb * input_y_pitch + xb * input_x_pitch;
+
+ src[i] = UNIT_BLOCK_READ(input, input_idx);
+ }
+ }
#else
src = UNIT_BLOCK_READ(input, input_offset + k * input_fs_pitch);
#endif // X_BLOCK_SIZE > 1
@@ -298,4 +312,4 @@ KERNEL(convolution_b_fs_yx_fsv16_1x1)(
#undef GET_SRC
#undef FEATURE_SLICE_SIZE
#undef UNIT_BLOCK_READ_VEC
-#undef UNIT_BLOCK_WRITE_VEC
\ No newline at end of file
+#undef UNIT_BLOCK_WRITE_VEC