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=1796387586; b=xFot++z5kn6nIVo+V6k/TADmI8X8p1tdecK1IQ6+6P/cqDZR21Kgyt1KD7oen3Ky87nP Elyh2MtuQFc7b7nBIXo9iKA3ScoFHTgqVVb8s2/ZOP34sxfwVeTEa4l8LMiIkfT6btqR9 WkUYinWs8HZ0zdyQ+fnspMINSlt9/rsUYkA+EyqaSVt/hmFVL8Ga4a1dDt2iGiFWh6Ovz CKgs3FywM4LxUlwcTRMSaVK4RtBveO3rDIiZUC7jZKG5KDwXvf8+l3DHUb+rlZ3Ea4/e+ aFOvE8eQJNJq26pqgM2Nvg0Ez0iqdOpaERtHtHcRbOoDkSUet+nhu7AJLQksXPc9EDA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796387586; 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=6sqzQekUViC4WJAjRzkVwvwp+6V8OTo8NuhkKhFBCn8=; b=wnvjyW6AphFH1KQWFirpDk0AeC5Jwqj1xv9aB+j0whq/L+ScBdf+siw34lFQr2nyVRwz VYEkbU6HIxCMdm4hbFl7iTDrDiaiWdjXpEYQGN2kyaTrXrFc9Xk6rZNlLsZf781AFBC4I v53PO8Jyj4jzaK8m7upbf2XGQRQP9ZHxE6l9QgY3o5wJVNCX3FMugXacvJ7d6mW0ii7ws dpjHD5dtunXcQxM4jc+2JbAMT43D60UlyO4ZU/LMlonzdeQhCTQHQ5snbIYg9gYozTu/P 5jVoSUgJE3wjAFv2xSDTgNrYWo7W2go9YwLZzIJe2qiGxCk3kRkYdYAlzOilkB3iHSg== 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=m16FIbap; 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 0EDDF606A333; Fri, 4 Dec 2026 12:33:06 +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=m16FIbap Received: by smtp.kernel.org (Postfix) with ESMTPSA id 78FA31F00897; Fri, 4 Dec 2026 12:33:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796387585; bh=6sqzQekUViC4WJAjRzkVwvwp+6V8OTo8NuhkKhFBCn8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=m16FIbapPjlscLKHu45Nf6Tq4kzYZ79Y2WR4N7ygb96c/bNtRcBBdXJlBrdgkSudV /DbAmujgUbemd13YLnspkFDYS6/CQ16ME+mJ7NoLvM02JmuY6yJuf/O+W8cAlIGLH2 LrblaW9PoBPeoH3AaSIlryUbqGE6RX54CIRjwpQw= 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.1 0305/1059] x86/fpu: Fix potential underflow in xstate_calculate_size() Date: Fri, 4 Dec 2026 18:57:16 +0900 Message-ID: <20261204100652.174073862@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 d185943437453..96040a3af5e54 100644 --- a/arch/x86/kernel/fpu/xstate.c +++ b/arch/x86/kernel/fpu/xstate.c @@ -563,12 +563,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