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`)
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
- Lĩnh vực
- computer-vision, performance
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ả
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):
- It computes
index_i = total / points.size == indices.sizeand readsindices.data[indices.size](4 bytes past the end ofindices.data). - Using that out-of-bounds index
i, it indexespoints.data[i]andnormals[i]. - It writes
output[total] = outpast the end ofoutput.
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:
masterHEAD (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
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PointCloudLibrary/pcl
-
[io] pcl::io::raw_open opens files in text mode on Windows, so raw_read alters binary dataCó thể đã có người làm @Aditya-stack-droid đã nhận 3 ngày trước. Đang mởkind: bug status: triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 82/100
PointCloudLibrary/pcl#6536 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
PointCloudLibrary/pcl#6509 · 1 bình luận ·
-
kind: bug status: triage
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
PointCloudLibrary/pcl#6544 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 45/100
PointCloudLibrary/pcl#6542 ·
-
kind: bug status: triage
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
PointCloudLibrary/pcl#6537 ·
Tất cả issue của PointCloudLibrary/pcl
Issue tương tự
-
Invalid-MissingHash/Commit/NotAC
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
azerothcore/azerothcore-wotlk#28636 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
(S1 - Need confirmation)
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
CleverRaven/Cataclysm-DDA#89829 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
comp-documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ClickHouse/ClickHouse#136277 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Flow Needs: Triage :mag:
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
react/react-native#60447 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
RecompLauncher supportĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày