From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796384915; b=LLoaVY26y52lDoBuFp8KRXnccfxTymNJRJxsRogaWs6IOVf37ovKjMdB+hGfy1ZU/+mX A9RjNxo+jLTJ9iZV5E2Kr5qKify0j+9YFKgwmOQ0Sd7XHkgMb0BbukoSsRd55o7VZGe3A 0X3PxNtdc8pJcZ9mVLNV7lg5UgEqWByq9Hiqgbj3eqhpAMel3qYj7vBEOZ4QdkRSRvqao 3XVEuHUcF+ug202/fPt+2tKp1aZZIlosXc2GsvzQrvsUCiC9Oon1fl4KK4reo+iP7Yjpq yEfExvsxLaM2F59Pns+ZZofgCAs1dnt079gR3H0SPRsnyK5ZOLWQkEwfgURyGdj0JdA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796384915; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=IPFId8DMkhgFLgifHV8dDslkMvNH6iCIJcJLSz4Kh6E=; b=QEmSUQdn+y461Dp4eRsYdEJqh+ViT422ESIV4uxhgD6edJiomDq774rKZGRLDqDxtvHT OC1qfhaMNdjsR8EfZkiilWXLfEYi5uF/b+GC5cx/mfJ8O6fLdhKJnZSQ7Rsd9lHuXfiOl 2ddsrZo4uIGBrpcd7TPYSBhfthDLEYe1WmoCAMCHSHh2YmzvnlDRwpbEdHaiciDlqYYzc c1JxPURgFJB8VFdQxmVjS0+qgkN9wZB23rRlC+e0ceEC6syUa242F0nq52AXQEa20wYPm mtGcstxIRrReuZwOGKFvQ573C9pPVoVRHzENTcixRMskOFG9FK4zoDxlpRxyFv2fA0g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=xrQPIrGh; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E947C606A322; Fri, 4 Dec 2026 11:48:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=xrQPIrGh Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D6331F000CE; Fri, 4 Dec 2026 11:48:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796384914; bh=IPFId8DMkhgFLgifHV8dDslkMvNH6iCIJcJLSz4Kh6E=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=xrQPIrGhKkipATYDcmf0DUlcYUVdtwyYqFif9ZFGBWHxmetGGKws6bB0MCH7MCJge o6j3DvaaxozlI4D3hs1gj4a0sfGQIBGPwfgsfT7N2DAgyyjjrr2lRCJiaEvG5RQ+A1 BQ4qUHrgWjx3RiHOTeYFI6Zc4bqlPkGrWIXTjsCU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Andrei Vagin , "Borislav Petkov (AMD)" , Alexander Mikhalitsyn , "Chang S. Bae" , Sasha Levin Subject: [PATCH 6.6 0346/1167] x86/fpu: Fix potential underflow in xstate_calculate_size() Date: Fri, 4 Dec 2026 18:56:13 +0900 Message-ID: <20261204100711.003281729@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100702.047403948@linuxfoundation.org> References: <20261204100702.047403948@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrei Vagin [ Upstream commit f1751b220bc8a9bd2dc38ecf61f5c29f3826ace0 ] xstate_calculate_size() calculates the size required for a given set of 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. [ bp: Remove text explaining what the patch does. ] Fixes: d6d6d50f1e80 ("x86/fpu/xstate: Consolidate size calculations") Signed-off-by: Andrei Vagin Signed-off-by: Borislav Petkov (AMD) Reviewed-by: Alexander Mikhalitsyn Reviewed-by: Chang S. Bae Link: https://patch.msgid.link/20260925162454.1403405-6-avagin@google.com Signed-off-by: Sasha Levin --- arch/x86/kernel/fpu/xstate.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/fpu/xstate.c b/arch/x86/kernel/fpu/xstate.c index 255ff8f6c5270..e0bcbbf7267a3 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -559,12 +559,14 @@ static bool __init check_xstate_against_struct(int nr) static unsigned int xstate_calculate_size(u64 xfeatures, bool compacted) { - unsigned int topmost = fls64(xfeatures) - 1; - unsigned int offset = xstate_offsets[topmost]; + unsigned int topmost, offset; - if (topmost <= XFEATURE_SSE) + if (!(xfeatures & ~XFEATURE_MASK_FPSSE)) return sizeof(struct xregs_state); + topmost = fls64(xfeatures) - 1; + offset = xstate_offsets[topmost]; + if (compacted) offset = xfeature_get_offset(xfeatures, topmost); return offset + xstate_sizes[topmost]; -- 2.53.0