gpu/features: Off-by-one bounds check (`idx > total` instead of `idx >= total`) causes global memory out-of-bounds read/write in `PpfImpl` and `PpfRgbImpl` (`ppf.cu`)

Đang mở Phù hợp với người mới
#6,543 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
88/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cpp

Hướng nghiên cứu

Đọc gpu/features/src/ppf.cu tại hai kiểm tra giới hạn của operator() được nêu trong issue. Sửa từng kiểm tra để các luồng có idx == total trả về trước khi truy cập các mảng đầu vào hoặc đầu ra. Xác minh cả hai cách triển khai PPF đều từ chối chỉ số biên; issue cho biết trường hợp này gây ra truy cập ngoài giới hạn khi chạy compute-sanitizer --tool memcheck.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

kind: bug status: triage

Describe the bug

In gpu/features/src/ppf.cu, both PpfImpl::operator() (L65-L95) and PpfRgbImpl::operator() (L125-L157) use > instead of >= in their thread bounds check:

// PpfImpl::operator() — gpu/features/src/ppf.cu:65-75
int total = points.size * indices.size;
int idx = blockIdx.x * CTA_SIZE + threadIdx.x;

if (idx > total)          // <-- BUG: should be `if (idx >= total)`
    return;

int index_i = idx / points.size; // when idx == total, index_i == indices.size (OOB)
int j = idx % points.size;
int i = indices.data[index_i];   // <-- 1-element out-of-bounds global read
...
output[idx] = out;               // <-- 1-element out-of-bounds global write

The exact same off-by-one check is duplicated in PpfRgbImpl::operator() at line 128 (if (idx > total) return;).

Expected behavior

Valid linear indices are 0 .. total - 1. Threads with idx >= total should return immediately without accessing indices.data, points.data, normals, or output.

Current Behavior

Whenever total = points.size * indices.size is not an exact multiple of CTA_SIZE (256), the thread with idx == total passes if (idx > total):

  1. It computes index_i = total / points.size == indices.size and reads indices.data[indices.size] (4 bytes past the end of indices.data).
  2. Using that out-of-bounds index i, it indexes points.data[i] and normals[i].
  3. It writes output[total] = out past the end of output.

Under compute-sanitizer --tool memcheck, this fails with an invalid global read and cudaErrorLaunchFailure (719).

To Reproduce

// nvcc -O2 -arch=sm_89 -lineinfo repro.cu -o repro
// compute-sanitizer --tool memcheck ./repro
#include <cuda_runtime.h>
#include <cstdio>

__global__ void ppf_oob_repro(const int* indices, float* output, int n_points, int n_indices) {
    int total = n_points * n_indices;
    int idx = blockIdx.x * 256 + threadIdx.x;
    if (idx > total) return; // off-by-one from gpu/features/src/ppf.cu:68,128
    int index_i = idx / n_points;
    int i = indices[index_i];
    output[idx] = (float)i;
}

int main() {
    int *d_idx; float *d_out;
    cudaMalloc(&d_idx, 10 * sizeof(int));
    cudaMalloc(&d_out, 100 * sizeof(float));
    cudaMemset(d_idx, 0, 10 * sizeof(int));
    ppf_oob_repro<<<1, 256>>>(d_idx, d_out, 10, 10);
    cudaError_t err = cudaDeviceSynchronize();
    printf("CUDA_ERR=%d (%s)\n", (int)err, cudaGetErrorString(err));
    return err == cudaSuccess ? 0 : 1;
}

Observed output on NVIDIA L40 (sm_89, CUDA 12.8):

========= COMPUTE-SANITIZER
========= Invalid __global__ read of size 4 bytes
=========     by thread (100,0,0) in block (0,0,0)
=========     Address 0x77d54e280028 is out of bounds
=========     and is 1 bytes after the nearest allocation at 0x77d54e280000 of size 40 bytes
=========
========= Program hit cudaErrorLaunchFailure (error 719) due to "unspecified launch failure" on CUDA API call to cudaDeviceSynchronize.
========= ERROR SUMMARY: 5 errors

Your Environment

  • OS: Ubuntu 24.04 Linux x86_64
  • Compiler: NVCC 12.8 (sm_89, NVIDIA L40)
  • PCL Version: master HEAD (fd39f32af932d50e033dba17b29e6d5fa4f64255)

Possible Solution

Change > to >= at lines 68 and 128 in gpu/features/src/ppf.cu:

-                if (idx > total)
+                if (idx >= total)
                     return;

(at both L68 in PpfImpl and L128 in PpfRgbImpl).

Ngôn ngữ chính
C++
Star
11.2k
Fork
4.7k
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của PointCloudLibrary/pcl

Tất cả issue của PointCloudLibrary/pcl

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.