-
Bug
-
Resolution: Unresolved
-
Medium
-
None
-
None
-
None
-
3
-
9223372036854775807
In lod_prep_md_striped_create(), when a create request has
LMV_HASH_FLAG_OVERSTRIPED set and stripe_count exceeds mdt_count *
lod_max_stripes_per_mdt, the code clamps the request down to that
limit — but only in the local variable stripe_count:
stripe_count = lo->ldo_dir_stripe_count;
if (lo->ldo_dir_hash_type & LMV_HASH_FLAG_OVERSTRIPED) {
if (stripe_count > mdt_count * lod->lod_max_stripes_per_mdt)
...
}
lo->ldo_dir_stripe_count itself is not updated at this point — it only
gets set to the final value after allocation succeeds. stripes[] and
idx_array[] are then allocated/sized using the clamped stripe_count:
OBD_ALLOC_PTR_ARRAY(stripes, stripe_count);
...
OBD_ALLOC_PTR_ARRAY(idx_array, stripe_count);
When lo->ldo_dir_stripe_offset != LMV_OFFSET_DEFAULT (an
explicit/specific MDT offset was requested), allocation goes through
lod_mdt_alloc_specific(). Unlike lod_mdt_alloc_qos() and
lod_mdt_alloc_rr(), which take the stripe count as an explicit
parameter, lod_mdt_alloc_specific() reads the loop bound from
lo->ldo_dir_stripe_count directly — the stale, pre-clamp value.
Result: whenever overstripe clamping actually shrinks the stripe count
(e.g. requested 8, clamped to 5) and the offset is non-default,
lod_mdt_alloc_specific() iterates up to the stale larger count (8)
while stripes[]/idx_array[] were only allocated for the clamped count
(5) — a heap buffer overflow writing past the end of both arrays.
This was caught directly by KASAN while writing a new KUnit test
(lod_prep_md_striped_create_test.c) that exercised this exact
combination (overstripe clamp + specific offset):
BUG: KASAN: slab-out-of-bounds in lod_mdt_alloc_specific
...
kasan: bad access detected
Fix direction: have lod_mdt_alloc_specific() take the
(already-clamped) stripe count as a parameter, the same way
lod_mdt_alloc_qos()/lod_mdt_alloc_rr() do, instead of re-reading
lo->ldo_dir_stripe_count. Alternatively, update
lo->ldo_dir_stripe_count to the clamped value immediately after
clamping, before any allocator is called — but passing it explicitly
is more consistent with the other two allocators and avoids relying on
object state being correct mid-function.