Re: [PATCH 6/8] x86/fpu: Fix potential underflow in xstate_calculate_size()
From: Chang S. Bae
Date: Wed Sep 02 2026 - 17:32:12 EST
On 8/16/2026 9:20 PM, Andrei Vagin wrote:
xstate_calculate_size() calculates the size required for a given set ofI think this fix makes sense before applying it to something that user-space provides via the sigframe:
xfeatures. It determines the topmost feature by finding the most
significant bit in xfeatures using fls64(xfeatures) - 1.
If xfeatures is 0, fls64(0) returns 0, and topmost becomes -1.
Previously, topmost was unsigned int, so -1 underflowed to UINT_MAX.
This caused the subsequent check `topmost <= XFEATURE_SSE` to fail, and
the code proceeded to access xstate arrays using topmost (UINT_MAX) as
an index, leading to an out-of-bounds access.
Fix this by checking if xfeatures only contains legacy features (FP/SSE)
or is empty (xfeatures <= XFEATURE_MASK_FPSSE) before calculating
topmost.
Reviewed-by: Chang S. Bae <chang.seok.bae@xxxxxxxxx>
Thanks,
Chang