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`)

未关闭 适合新手
#6,543 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
88/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
cpp

调研方向

在 gpu/features/src/ppf.cu 中查看 issue 指出的两处 operator() 边界检查。修改每处检查,使 idx == total 的线程在访问输入数组或输出之前返回。验证两个 PPF 实现都会拒绝边界索引;issue 报告称,此情况会在 compute-sanitizer --tool memcheck 下触发越界访问。

由索引模型根据 Issue 内容生成。

描述

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).

主要语言
C++
星标
11.2k
派生
4.7k
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

PointCloudLibrary/pcl 的其他 Issue

查看 PointCloudLibrary/pcl 的全部 Issue

相似的 Issue

更多 C++ Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。