Repository navigation
Description
Severity: high · Category: memory-ub · Fix order: 2 of 25 — fix this 2nd.
Filenames are numbered in reverse fix order: 001 = fix last, 025 = fix first. This file is 024.
Locations: Source/CAMR.H:459, Source/CAMR.H:465
Based on commit 8f87fa8 (line numbers refer to that tree).
The defect
What is wrong — numGrow() has no branch for redistribution_type=="NoRedist" (an accepted value, validated in CAMR.cpp:192-195) and returns 4 in EB builds, though construct_hydro_source still uses bxg_i=grow(bx,2) for NoRedist and the EB kernels need 6 (Godunov) / 5 (MOL) ghost cells per the code's own table. Reported independently at this same line by F009, F014, F016; each reviewer's own wording and evidence is under Verification evidence below.
Why it matters
USE_EB=TRUE with CAMR.redistribution_type=NoRedist: Sborder/q/qaux are allocated with 4 ghost cells, but Godunov_umeth_eb works on grow(bx,2) (bxg2=grow 2 more, plus slope/flattening stencils), reading the q FArrayBox up to 2 cells out of bounds -> garbage face states or crash. NoRedist discards the garbage halo (ApplyMLRedistribution copies bx only), so the harm is the out-of-bounds read itself (crash / ASAN / GPU fault), not decomposition-dependent answers.
How to reach it
- Build Exec/SodPlusSphere (ships USE_EB=TRUE, 3D); run its inputs with CAMR.do_mol=0 and CAMR.redistribution_type=NoRedist (both validated-legal; ppm_type defaults to 0). Any tile within 2 cells of the sphere reaches Godunov_umeth_eb with numGrow()=4.
- Exec/SodPlusSphere built as shipped (USE_EB=TRUE, DIM=2); inputs edited to CAMR.do_mol=0 and CAMR.redistribution_type=NoRedist (both accepted by read_params). Sphere cut cells route tiles into Godunov_umeth_eb.
- Exec/SodPlusSphere (USE_EB=TRUE, DIM=2 as shipped -- GNUmakefile:5): run its inputs with CAMR.redistribution_type=NoRedist AND CAMR.do_mol=0 appended (the deck sets do_mol=1 at inputs:23; last ParmParse occurrence wins). ppm_type default 0 then passes the EB-Godunov check at CAMR.cpp:187-189; cut cells near the sphere execute Godunov_umeth_eb with 4-ghost Sborder.
- Exec/SodPlusSphere (USE_EB=TRUE, 2D): set CAMR.redistribution_type=NoRedist, remove CAMR.do_mol=1 (default 0, ppm_type default 0). Any box with cut cells within grow(bx,2) triggers the OOB reads.
Note from the audit
F003: Four findings fold here (F003, F009, F014, F016) because four reviewers independently found the same missing NoRedist branch in CAMR::numGrow(); F016 shares this anchor line exactly, F009 and F014 anchor six lines earlier. One patch resolves all four.
Suggested fix
Give NoRedist the FluxRedist ghost budget (5 for MOL, 6 for Godunov). Both take ngrow_bx = 2 in CAMR_construct_hydro_source.cpp:146-152, so both trace on grow(bx,4) and slope on grow(bx,6); that pair is already the right answer for this box. The fall-through to 4 is an artifact of #55, which replaced an uninitialized int ng; with int ng = 4; — the non-EB value — instead of adding the missing case; the comment table above the function still omits NoRedist, so update it too. One line covers the whole chain: Sborder and the EB flag/area/centroid ghosts (SetEBMaxGrowCells, main.cpp:112) both derive from numGrow(). Decision for you: the cheaper alternative — shrinking bxg_i, since amrex::ApplyMLRedistribution's NoRedist branch reads dUdt_in only on bx — also shrinks the flagfab.getType(bxg_i) test radius and would silently send near-EB boxes down the non-EB path. Nothing else must land with this one.
For Source/CAMR.H:465 (F003):
--- a/Source/CAMR.H
+++ b/Source/CAMR.H
@@ -462,7 +462,7 @@
// IF Godunov + FRD then 6
// IF MOL + SRD then 6
// IF Godunov + SRD then 7
- if (redistribution_type == "FluxRedist")
+ if (redistribution_type == "FluxRedist" || redistribution_type == "NoRedist")
{
if (do_mol) {
ng = 5;One patch, applied once, resolves all four ids at this site: F003, F009, F014 and F016 are the same missing NoRedist branch in CAMR::numGrow(). None of the other three carries a separate diff.
Diff(s) are against 8f87fa8, written from the current source and verified only with git apply --check — never compiled, never run, never applied to the tree. Treat them as precise intent, not tested patches.
Verification evidence
F009 — confirmed (two independent verifier lenses)
Reported as: numGrow() has no case for redistribution_type=="NoRedist" (an explicitly allowed value, CAMR.cpp:192-195) and returns 4 in EB builds, but the EB Godunov PLM kernels read q up to 6 cells outside the tile box, causing out-of-bounds Array4 reads.
Failure scenario: USE_EB=TRUE, camr.redistribution_type=NoRedist, do_mol=0: q/qaux/srcQ are allocated on grow(bx,4) (CAMR_construct_hydro_source.cpp:82,95), Godunov_umeth_eb is called with bxg_i=grow(bx,2), loops over bxg2=grow(bx,4), and plm_slope_eb/plm_slope read q at iv+-1 and iv+-2, i.e. up to grow(bx,6): heap over-read by 2 cells -> garbage slopes/fluxes or segfault (abort with AMReX bound checking). FluxRedist (ng=6) and StateRedist (ng=7) fit exactly; only NoRedist is broken (MOL+NoRedist over-reads by 1 similarly).
Lens 1 (refutation attempt): numGrow(): 'int ng = 4;' with branches only for FluxRedist/StateRedist — no NoRedist case (CAMR.H:459-482). q/qaux/src_q allocated on grow(bx,4) (CAMR_construct_hydro_source.cpp:82,95-97); Godunov_3D_eb.cpp:70 'bxg2 = grow(bx_to_fill,2)' = grow(bx,4) with bx_to_fill=bxg_i=grow(bx,2) for NoRedist; PLM_eb.H:31-43 reads flags(iv±2*dvec) and, with default plm_iorder=4, q at ±2 → grow(bx,6). Over-read by 2 confirmed; FRD(6)/SRD(7) fit exactly.
Lens 2 (reachability/intent): CAMR.H:459 leaves ng=4 for NoRedist (EB branches cover only FluxRedist/StateRedist). NoRedist takes the ngrow_bx=2 branch (CAMR_construct_hydro_source.cpp:149); q is allocated on grow(bx,4) (line 95) but Godunov_umeth_eb loops bxg2=grow(bx,4) (Godunov_3D_eb.cpp:70,96) and plm_slope reads q(iv±2) unconditionally for order>=2 (PLM.H:43,46) — reads at grow(bx,6): 2-cell heap over-read. FluxRedist(6)/StateRedist(7) fit exactly. git -L shows the fall-through came from refactor 1e77ccc, not intent; AMReX ApplyMLRedistribution accepts NoRedist (RedistributionApply.cpp:218), so no abort intervenes.
F014 — confirmed (two independent verifier lenses)
Reported as: numGrow() returns 4 for EB builds when redistribution_type=="NoRedist" (an accepted option, validated at CAMR.cpp:192-195), but the EB Godunov path needs 6 ghost cells: bxg_i=grow(bx,2), bxg2=grow(bxg_i,2), and plm_slope_eb/plm_pslope_eb read q and flags at +/-2 from bxg2.
Failure scenario: USE_EB=TRUE, do_mol=0, camr.redistribution_type=NoRedist: Godunov_umeth_eb's PLM kernel over bxg2=grow(bx,4) reads q(i+/-2) and flag(i+/-2) at grow(bx,6), but q/qaux/Sborder and EB flag fabs have only 4 ghost cells -> out-of-bounds Array4 reads (garbage slopes or segfault). Order-2 PLM still overreads by 1.
Lens 1 (refutation attempt): Same defect as F009, independently confirmed: plm_slope_eb/plm_pslope_eb unconditionally test flags(ivm2)/flags(ivp2) (PLM_eb.H:38-43,85-90) and call plm_slope at order 4 reading q(i±2), over bxg2=grow(bx,4) in both Godunov_2D_eb.cpp:62 and Godunov_3D_eb.cpp:70. EB flag ghost count is also numGrow() via SetEBMaxGrowCells (main.cpp:112), so flag reads at grow(bx,6) are OOB too. Order-2 fallback still reads ±1 = grow(bx,5) > 4 ghosts.
Lens 2 (reachability/intent): CAMR.H:459-481: NoRedist falls through, ng=4. CAMR_construct_hydro_source.cpp:146-152 sets ngrow_bx=2 for NoRedist; q/qaux/src_q sized grow(bx,4) (:82,95). Hydro_umdrv_eb.cpp:89,125 passes bxg_i as bx_to_fill; Godunov_3D_eb.cpp:70,96 kernels run on bxg2=grow(bx,4); PLM_eb.H:31-54 reads flags/q at iv±2 with no contains() guard (flatten_eb at flatten.H:118 guards, PLM does not). main.cpp:112 gives EB flag fabs the same 4 ghosts. git -L: ng=7 originally; 1e77ccc left NoRedist at the non-EB default 4, undocumented.
F003 — confirmed (two independent verifier lenses)
Lens 1 (refutation attempt): Same missing-NoRedist-branch defect: 'if (redistribution_type == "FluxRedist")' at CAMR.H:465, no NoRedist branch, ng stays 4. Sborder defined with numGrow() ghosts (CAMR_advance.cpp:157) and AMREX_ASSERT(S.nGrow()==numGrow()) at CAMR_construct_hydro_source.cpp:26; NoRedist takes ngrow_bx=2 (line 149-150) so hydro_umdrv_eb/Godunov_umeth_eb traces over grow(bx,4) reading q up to grow(bx,6) — 2 cells out of the exactly-grow(bx,4) q FAB. git log shows no fix on CAMR.H since #55.
Lens 2 (reachability/intent): CAMR.H:459-481 returns ng=4 for NoRedist (only FRD/SRD branches); CAMR.cpp:194 accepts NoRedist. construct_hydro_source.cpp:150 sets ngrow_bx=2; Godunov_3D_eb.cpp:70 iterates bxg2=grow(bx,4); PLM_eb.H:31-43 plm_slope_eb reads flags/q at iv±2 (grow(bx,6)) with no contains guard, 2 cells past the grow(bx,4) q fab. Git -L: EB ng was unconditionally 7 pre-#54; #55 left NoRedist falling to the non-EB 4. Caveat: NoRedist discards the garbage halo (ApplyMLRedistribution copies bx only), so it is OOB-read UB (crash/ASAN/GPU fault), not decomposition-dependent answers.
F016 — confirmed (two independent verifier lenses)
Reported as: CAMR::numGrow() has no branch for redistribution_type="NoRedist" in EB builds, returning 4, but the EB Godunov path needs 6: kernels trace on grow(bx, ngrow_bx+2)=grow(bx,4) and plm_slope_eb reads q/flags at +/-2, i.e. grow(bx,6).
Failure scenario: EB build, do_mol=0 (default), CAMR.redistribution_type=NoRedist (accepted by read_params), box with cut cells within 2 cells: Godunov_umeth_eb's trace loop over bxg2=grow(bx,4) calls plm_slope_eb which reads the q/qaux/src_q FABs (allocated exactly on grow(bx,4)) and the flag array (4 ghosts) at grow(bx,6) — out-of-bounds reads, garbage slopes/face states or segfault.
Lens 1 (refutation attempt): Confirmed duplicate of the same defect: hydro_umdrv_eb passes Box(divc_arr)=bxg_i=grow(bx,2) (Hydro_umdrv_eb.cpp:89,125); Godunov_umeth_eb forms bxg2=grow(bx_to_fill,2)=grow(bx,4) and the ppm_type==0 trace loop calls plm_slope_eb over bxg2 (Godunov_3D_eb.cpp:96-141) reading q/flags at ±2 → grow(bx,6), while q/qaux/src_q FABs are on grow(bx,numGrow())=grow(bx,4) and flags have 4 ghosts. ppm_type must be 0 with EB (else amrex::Error), so the PLM path is the only EB Godunov path.
Lens 2 (reachability/intent): CAMR.H:459-482 branches only on FluxRedist/StateRedist; NoRedist falls through to ng=4. read_params (CAMR.cpp:192-196) accepts NoRedist; no guard blocks EB+do_mol=0. ngrow_bx=2 (construct_hydro_source:150) makes Godunov_umeth_eb's bxg2=grow(bx,4), the exact q/qaux/src_q allocation box; plm_slope_eb (PLM_eb.H:31-43, plm_iorder=4 default) reads flags/q at +/-2 = grow(bx,6). git show 49b0125 shows original safe ng=7 "for now"; commit 127b1d2 dropped the NoRedist case — oversight, not intent.
Based on commit 8f87fa8, which is also the tree the audit verified against. From an automated audit of Source/, Tutorials/ and Util/. Audit finding ids: F009, F014, F003, F016. Reviewer unit(s): Driver+Header+Sources, PPM+PLM, theme:box-bounds-args, theme:ghost-fillpatch. Nothing here was compiled or run — the failure scenarios are code reasoning, so the reaching configuration above is the cheapest way to confirm or refute it.
Activity
fixes issue 91 92 93 94 95 (AMReX-Fluids#108)