From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.19 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796073559; b=AcAD42KD7/AqYh9qllo9PCiJyEbLdFDDLMMdypgGsnfnKLAGfBzekfFGpE7G8L95OD/q Jn81XMUZlyVdNSeE9f5zFREJAcoGXOobOeETBIyx9O743kLLOLq4SG2WaKZuHUzutKz8s DNqHgsCFCWA+F3k0R4hhJEdxBp14rHyKa5RRopsmYhOvwdtUg5zBsIS/mYvzDeXyenrWM N304AhSqhWfPKP9ekQCDiC2sgjkL9axpFUjFZWwihJTq2xKtGg1RG91y88JFK6evNzWJO lcRzUim9kqkXSGY9dW5fvNDCOKN5HEAB3hmIK4dzdg9Wc4VP1qCdUvH30Jx0k+J6ogg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796073559; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=KbpsupxyxdWQw/MX1cw0Xp1yDd+4i5f2il9YLg243A0=; b=UgHChAStzkdD2a7zh3aCN6RV07GKb0iezlcto5+QLYFXgNWXpu/Yt7xhCZLKs1MYDEEf Opcvh57Su/evs2yPRoqPSLV4BiBe48FRi2og6337yem52cw6S9YolxjU2LDynlW+Hx5K1 eNGS3fx8EIGRjiSSHogK9/TXEC2ITyC1ak7mhtUFBQxtP+ksuleLOlc2IU8KOdzLGF4cw lclQmyEjkIobUBHgm93bBri+aIXlqCbh3b6+piVREFBm1wp68tu58qSYxNmTh2bzwJtjI /VGs/pO9jwZjqz9IK7HcHmVR0RkNLgwwSoSfZSHKOo/UuPuLwqKlffKk63dIsaq4TLw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=kv6lnnRl; arc=none smtp.remote-ip=198.175.65.19 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9BC8D606A33A; Mon, 30 Nov 2026 21:19:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 9BC8D606A33A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=kv6lnnRl DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796073559; x=1827609559; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KbpsupxyxdWQw/MX1cw0Xp1yDd+4i5f2il9YLg243A0=; b=kv6lnnRl4d4cU/gUUWc/t/zyg4J1arHNorUTNQJsnvf37ZL3wrHM2e3s c1JBEN7ISH7vVCH6vV/8x5yTv5TaDu3MbZP+SxFO4JfnzhYSROulx0gQ8 tUByr5b34Ll4fVcFzgxE9zwjEHZgRXhR6tYV8OfmfAkJAOrlK+3l9/BbQ Go79P0+D+Z1WnY6Zibxj8iCl6WF+SeKTC/cNQ1NGcub0Tg9kvo8iHnzeb 6PkebQkQjZwB9TW35W8mZMF4x+AAVZWMxWX5wCVEYmnvg9CqRDaL3RnzA T2XZh/CNFcsWOl5E51/syYUYtfeL0GhBOqDq4FITQy8xtDwMoqIi7FGe2 A==; X-CSE-ConnectionGUID: 3t+lSTMDQn2t/6YyYWFR8Q== X-CSE-MsgGUID: iytl+DpDQZqvcML8HRGKyA== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4989778" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4989778" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 13:19:19 -0800 X-CSE-ConnectionGUID: /zX/Y026QdO6YHkrXVl+cQ== X-CSE-MsgGUID: kfxVHpKpQpe3ZQXr2LZd2A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13166776" Received: from chang-linux-3.sc.intel.com (HELO chang-linux-3) ([172.25.66.174]) by fmviesa005.fm.intel.com with ESMTP; 30 Nov 2026 13:19:18 -0800 From: "Chang S. Bae" To: linux-kernel@vger.kernel.org Cc: x86@kernel.org, tglx@kernel.org, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, weiguixiong@bytedance.com, omermetekaya0@gmail.com, chang.seok.bae@intel.com, stable@vger.kernel.org Subject: [PATCH 5/6] x86/fpu: Fix memory leak with dynamic fpstate and exec() Date: Mon, 30 Nov 2026 20:51:41 +0000 Message-ID: <20261130205143.1258369-6-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261130205143.1258369-1-chang.seok.bae@intel.com> References: <20261130205143.1258369-1-chang.seok.bae@intel.com> X-Mailing-List: linux-kernel@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 Using an XFD-controlled xfeature can allocate a larger fpstate. On exec(), fpstate_reset() replaces fpu->fpstate with the embedded buffer without freeing the dynamic allocation. Once the pointer is overwritten, the allocation cannot be freed on task exit. Free vmalloc'ed area from fpu_reset_fpstate(). Fixes: 500afbf645a0 ("x86/fpu/xstate: Add fpstate_realloc()/free()") Closes: https://lore.kernel.org/20260929151013.81562-2-weiguixiong@bytedance.com Reported-by: Guixiong Wei Originally-by: Guixiong Wei Signed-off-by: Chang S. Bae Cc: stable@vger.kernel.org --- arch/x86/kernel/fpu/core.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/fpu/core.c b/arch/x86/kernel/fpu/core.c index de746eedfe397..f088b1f8518ea 100644 --- a/arch/x86/kernel/fpu/core.c +++ b/arch/x86/kernel/fpu/core.c @@ -680,16 +680,28 @@ static int update_fpu_shstk(struct task_struct *dst, unsigned long ssp) * Reset fpstate metadata and register storage to the init values from: * - fpu_clone() for new task's FPU state * - fpu_flush_thread() for current + * + * Also, free up the expanded storage. */ static void fpu_reset_fpstate(struct task_struct *tsk, struct fpu *fpu, bool reset_regs) { + struct fpstate *oldfps = NULL; + /* Current must get its register storage reset. */ WARN_ON_ONCE(tsk == current && !reset_regs); - if (tsk == current) + /* New tasks must have a null pointer from arch_dup_task_struct() */ + WARN_ON_ONCE(tsk != current && fpu->fpstate != NULL); + + if (tsk == current) { + oldfps = fpu->fpstate; fpregs_lock(); + } - /* Reset the fpstate metadata: */ + /* + * Reset the fpstate metadata, including fpu->fpstate being + * reset to __fpstate. + */ fpstate_reset(fpu); /* @@ -719,8 +731,10 @@ static void fpu_reset_fpstate(struct task_struct *tsk, struct fpu *fpu, bool res */ set_tsk_thread_flag(tsk, TIF_NEED_FPU_LOAD); - if (tsk == current) + if (tsk == current) { fpregs_unlock(); + fpstate_free(oldfps); + } } /* Clone current's FPU state on fork */ -- 2.53.0