Repository navigation
Fix work buffer overflow in single-threaded lower POTRF for large N - #6295
Open
ChrisLundquist wants to merge 2 commits into
Open
ChrisLundquist wants to merge 2 commits into
ChrisLundquist wants to merge 2 commits into
Conversation
potrf_L_single packs the rows of the first tile of the trailing panel behind sb2 while it walks over all remaining rows GEMM_P at a time. The block of rows that starts inside the tile was copied whole, so up to GEMM_P - 1 rows more than the REAL_GEMM_R that sb2 has room for were written. Since REAL_GEMM_R is GEMM_R - GEMM_PQ instead of GEMM_R - 2 * GEMM_PQ (146beed) there is no room left for them, and for n - GEMM_Q > REAL_GEMM_R the driver wrote past the end of the BUFFER_SIZE work area: by 64 kB with the SKYLAKEX parameters (192, 384) and BUFFERSIZE=20, and by up to 12 kB with the Zen 4/5 parameters (512, 512), where the rows fit exactly and only the rounding of sb2 to GEMM_ALIGN is past the end. Pack only the rows of the tile. The SYRK kernel never read the others. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Calls dpotrf_L_single with a work area of its own, followed by memory that must stay zero, at the smallest size that packs a full first tile. The matrix is chosen so that the driver stops after one update of the trailing matrix. Skipped where that size needs more than 1 GB or more than OPENBLAS_UTEST_TIME_LIMIT seconds (the size grows with BUFFER_SIZE; with BUFFERSIZE=20 it is about 10^4 and the test takes under a second). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With one thread,
?potrfwithuplo = 'L'can write past the end of its work area oncen - GEMM_Q > REAL_GEMM_R. Inlapack/potrf/potrf_L_single.cthe "first tile" loop walks the remaining rowsGEMM_Pat a time and copies the block that starts inside the tile whole, so up toGEMM_P - 1rows more thansb2has room for are packed. Since #5988 (REAL_GEMM_R = GEMM_R - GEMM_PQ) there is no slack left behindsb2for them.potrf_U_single.cpacks only what fits and is not affected.It is easy to reach with
BUFFERSIZE=20builds such as the scipy-openblas wheels: with the Zen 4/5 AVX-512 parameters (P = Q = 512, R = 7664) from about n = 7680, and with the Intel SKYLAKEX parameters (192, 384, 10704) from about n = 10730. The symptom is a SIGSEGV indgemm_otcopy_SKYLAKEXcalled fromdpotrf_L_single, heap corruption, or silent corruption, depending on what is mapped behind the work area; it does not depend on the matrix. Seen withnumpy.linalg.choleskyon an 8008 x 8008 matrix withOPENBLAS_NUM_THREADS=1on a Zen 5 CPU. The v0.3.34 release is not affected;developis. (The threaded path had a separate overflow, fixed in #6235.)Fix: pack only the rows of the tile,
min(min_i, j + bk + min_j - is). The SYRK kernel that follows never reads the others.Test:
utest/test_potrf_workarea.ccalls the single-threaded driver with its own work area followed by a zero tail and checks that the tail stays untouched and the factor is right. It needs 0.5 to 1 GB onBUFFERSIZE=20builds and skips itself where the sizes would need more than 8 GB (default builds).Tested (
DYNAMIC_ARCH=1 INTERFACE64=1 BUFFERSIZE=20 NOFORTRAN=1, Zen 5): ondevelopedd6ae0 plus these two commits,make testspasses (utest 178/178 including the newpotrf:single_work_area_bound, utest_ext 1563/1563, and the BLAS/CBLAS tests). A standalone reproducer passes for n = 8008 and 11440 with 1 and 2 threads, lower and upper, and with the Intel block sizes (forced withOPENBLAS_L2_SIZE=2048) at n = 11000. Before the fix the reproducer faults with one thread at n = 8008 (Zen 4/5 sizes) and n = 11000 (Intel sizes), and the new test fails.Not tested: the Fortran LAPACK test suite (no Fortran compiler on the test host) and the CMake build of the new test (the CMake lines were written by analogy with
test_syrk_thread_workarea.c).This fix and test were prepared with AI assistance (Claude); both commits carry a
Co-Authored-Bytrailer. A self-contained C reproducer (synthetic matrix, anmmapinterposer that puts a guard region behind each work area so the overflow faults deterministically) is available if useful.🤖 Generated with Claude Code