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

Aperta Adatta ai principianti
#6,543 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp

Direzione di ricerca

Leggi gpu/features/src/ppf.cu in corrispondenza dei due controlli dei limiti di operator() indicati nell’issue. Modifica ciascun controllo affinché i thread con idx == total ritornino prima di accedere agli array di input o all’output. Verifica che entrambe le implementazioni PPF rifiutino l’indice limite; l’issue segnala che questo caso provoca un accesso fuori dai limiti con compute-sanitizer --tool memcheck.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

Lingua principale
C++
Stelle
11.2k
Fork
4.7k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PointCloudLibrary/pcl

Tutte le issue di PointCloudLibrary/pcl

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.