Out-of-bounds global write in medianfilter-cuda/ckMedian for small images
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- cpp
- Ambito
- backend, performance
Direzione di ricerca
Leggi src/medianfilter-cuda/MedianFilter.cu intorno alla riga 252, dove il controllo dei limiti dell’output e la scrittura usano coordinate Y diverse. Inizia compilando ed eseguendo la riproduzione 1x1 PPM fornita con Compute Sanitizer. Il lavoro è terminato quando il kernel scrive solo all’interno dell’allocazione di output di larghezza per altezza e Compute Sanitizer non segnala errori.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Summary
The ckMedian kernel in src/medianfilter-cuda/MedianFilter.cu can write one row past the output allocation when the output buffer is allocated using the actual image dimensions (width * height * sizeof(unsigned int)).
A standard 1x1 binary P6 PPM image is sufficient to reproduce the issue. NVIDIA Compute Sanitizer reports an Invalid __global__ write of size 4 bytes at MedianFilter.cu:252.
The issue appears to be caused by an off-by-one error in the final output bounds check, rather than by the CUDA runtime or driver.
Confirmed versions
I originally reproduced the issue at:
af5d95689b3e5d83f6e50d1aae2787770e10569d
I also confirmed that it remains reproducible on the latest ORNL/HeCBench master available to me:
ffde18721e8c1090460e367c97b4af39240cc83e(2026-11-13)
The MedianFilter.cu file at both revisions has the same SHA-256:
38c557ed5810aaafc13f79c935c18e7746e3ec3fd91fac34a36f817b4615773e
Environment used for the latest-master confirmation
- GPU: NVIDIA GeForce RTX 4080 (
sm_89) - NVIDIA driver: 621.01
- CUDA toolkit: 12.9, V12.9.41
- NVIDIA Compute Sanitizer: 2025.2.0.0 (build 35692658)
- Platform: WSL/Docker on Windows, x86_64
- Build flags:
-arch=sm_89 -O3 -lineinfo -std=c++17
Minimal reproduction
The attached archive contains the unmodified pinned MedianFilter.cu, the small fuzzing host harness, the PPM parser, crash inputs, and Compute Sanitizer logs.
The kernel itself is unchanged. The custom host harness allows arbitrary input dimensions and allocates the input/output buffers using the actual image size. This is important because the original benchmark host allocates a fixed 1920x1080 buffer, which can mask the out-of-bounds write for smaller images.
From the extracted archive, build the uninstrumented binary with:
nvcc -arch=sm_89 -O3 -lineinfo -std=c++17 \
src/fuzz_main.cu src/MedianFilterHost.cpp -o medianfilter_repro
A minimal standard P6 PPM can also be generated independently:
python3 - <<'PY'
with open("minimal-1x1.ppm", "wb") as f:
f.write(b"P6\n1 1\n255\n\x00\x00\x00")
PY
Run it with Compute Sanitizer:
compute-sanitizer --tool=memcheck --report-api-errors=no --error-exitcode=99 \
./medianfilter_repro minimal-1x1.ppm
Expected behavior
The kernel should only write within the width * height output elements. Compute Sanitizer should report no errors.
Actual behavior
The process exits with code 99 because of --error-exitcode=99, and Compute Sanitizer reports:
========= COMPUTE-SANITIZER
========= Invalid __global__ write of size 4 bytes
========= at ckMedian(const uchar4 *, unsigned int *, int, int, int)+0x16a0 in MedianFilter.cu:252
========= by thread (0,1,0) in block (0,0,0)
========= Access at 0x711400204 is out of bounds
========= and is 1 bytes after the nearest allocation at 0x711400200 of size 4 bytes
========= Target application returned an error
========= ERROR SUMMARY: 1 error
The device address varies between runs; the instruction, source location, allocation size, and error type are consistent.
Root-cause analysis
The kernel shifts the Y coordinate up by one row while loading the apron:
int iDevYPrime = iGroupIdY * iBlockY + iLocalIdY - 1;
int iDevGMEMOffset = iDevYPrime * iImageX + iImagePosX;
The final store restores that one-row shift by adding iImageX, but the bounds check still uses the un-restored iDevYPrime:
if ((iDevYPrime < iDevImageHeight) && (iImagePosX < iImageWidth)) {
uiDest[iDevGMEMOffset + iImageX] = uiPackedPix;
}
The effective output row is therefore iDevYPrime + 1, not iDevYPrime.
When iDevYPrime == iDevImageHeight - 1, the current condition passes, but the store writes to output row iDevImageHeight, which is one row beyond the allocation. For a 1x1 image with a 4-byte output allocation, this becomes a 4-byte write immediately past that allocation.
Suggested fix
Check the restored output coordinates explicitly:
const int iDevYRestored = iDevYPrime + 1;
if (iDevYRestored >= 0 && iDevYRestored < iDevImageHeight &&
iImagePosX < iImageWidth) {
uiDest[iDevYRestored * iImageX + iImagePosX] = uiPackedPix;
}
This is a proposed source-level correction; the sanitizer results above were obtained with the unmodified kernel.
Additional evidence
The fuzzing campaign produced 15 distinct crash inputs:
- 10 from the baseline configuration
- 5 from the L2 configuration
All 15 files have distinct SHA-256 hashes. Every input was independently reproduced using an uninstrumented binary and standalone Compute Sanitizer, and all 15 returned rc=99 with the same MedianFilter.cu:252 invalid global write signature. They should therefore be treated as multiple triggers for one root-cause defect, not as separate vulnerabilities.
Observed triggering dimensions included:
1x1, 1x2, 1x6, 6x1, 6x2, 16x1, 26x1, and 96x1
The complete inputs and individual sanitizer logs are included in the attached archive. The separate minimal-1x1-memcheck.log file is the confirmation against ORNL/HeCBench master commit ffde18721e8c1090460e367c97b4af39240cc83e.
- Lingua principale
- C++
- Stelle
- 310
- Fork
- 125
- Merge medio
- 5g 1h
- PR unite (30g)
- 52
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ORNL/HeCBench
-
Unifying testing and V&VForse già presa @matthewc2003 l’ha presa 6 giorni fa. Aperta
ORNL/HeCBench#463 · 3 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
-
Reorganizing respository and front-pageForse già presa @keitaTN l’ha presa 6 giorni fa. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
ORNL/HeCBench#249 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
ORNL/HeCBench#238 · 10 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di ORNL/HeCBench
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
useless statementAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
grizzlypeak3d/DJV#962 ·
-
cognizant-backlog
Difficoltà 2/5 1-3 ore Idoneità per principianti 61/100
KhronosGroup/OpenCL-CTS#2882 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno