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`)
还没有人认领这个 Issue。
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 88/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- cpp
调研方向
在 gpu/features/src/ppf.cu 中查看 issue 指出的两处 operator() 边界检查。修改每处检查,使 idx == total 的线程在访问输入数组或输出之前返回。验证两个 PPF 实现都会拒绝边界索引;issue 报告称,此情况会在 compute-sanitizer --tool memcheck 下触发越界访问。
由索引模型根据 Issue 内容生成。
描述
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).
- 主要语言
- C++
- 星标
- 11.2k
- 派生
- 4.7k
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
PointCloudLibrary/pcl 的其他 Issue
-
[io] pcl::io::raw_open opens files in text mode on Windows, so raw_read alters binary data可能已有人在做 @Aditya-stack-droid 于 3 天前认领。 未关闭kind: bug status: triage
难度 1/5 1 小时以内 新手友好度 82/100
PointCloudLibrary/pcl#6536 ·
-
难度 2/5 1-3 小时 新手友好度 67/100
PointCloudLibrary/pcl#6509 · 1 条评论 ·
-
kind: bug status: triage
难度 4/5 3-5 天 新手友好度 55/100
PointCloudLibrary/pcl#6544 ·
-
难度 4/5 3-5 天 新手友好度 45/100
PointCloudLibrary/pcl#6542 ·
-
kind: bug status: triage
难度 4/5 3-5 天 新手友好度 48/100
PointCloudLibrary/pcl#6537 ·
查看 PointCloudLibrary/pcl 的全部 Issue
相似的 Issue
-
Invalid-MissingHash/Commit/NotAC
难度 1/5 1-3 小时 新手友好度 88/100
azerothcore/azerothcore-wotlk#28636 ·
维护者通常 1 天内回复
-
(S1 - Need confirmation)
难度 2/5 1-3 小时 新手友好度 62/100
CleverRaven/Cataclysm-DDA#89829 ·
维护者通常 1 天内回复
-
comp-documentation
难度 2/5 1-3 小时 新手友好度 72/100
ClickHouse/ClickHouse#136277 ·
维护者通常 1 天内回复
-
Flow Needs: Triage :mag:
难度 2/5 1-3 小时 新手友好度 76/100
react/react-native#60447 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复