From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E627126B085; Tue, 8 Apr 2025 12:33:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744115600; cv=none; b=BLCLnMr6Au0TJzKuJvHa5VOCBAMBMzjTjQvmx5JAaHAxyzdmjWzbIvjd2hsJqvg01O39qtjmTg3OLpAJuPrMvcCXQ/nGdS2GkpOu9GdLvA001HHAvNqIkMtMGMPu0KOUOS3mC3lszaQpDeo5aLMaOC7Y5iUyQ/h1ZFqrUdIE0sc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744115600; c=relaxed/simple; bh=l1YPDezXzfI8SCCsIZE98u+TV6SbGEdgyhEzxK7QJ3Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BrnK/WTLGE7IiSdwYEtYA7GxQelncq8jPG+o5ZvDAJKrcVteBNF+++L4rFMHOuHC+hu3KiObnLB8AYkqIw/nhKW39gIGbvbxkEK8YJj8Uh53cNaa/IgzsoWohrLDbRPW09Gsbl1KEZRapQJXqqpOy1k8SghsogeAZV0r/ig0hLk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=bbc3trFV; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="bbc3trFV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76F04C4CEE5; Tue, 8 Apr 2025 12:33:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1744115599; bh=l1YPDezXzfI8SCCsIZE98u+TV6SbGEdgyhEzxK7QJ3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bbc3trFVokeWroBm4a6TlaWUPOwqT2ECJ9iwC2Egi5wLRfCxOzYUoZoSOpWMvQNSC HuDlqCdKjeRnpWmIgEaWFymdfxARXgypcDGx+lQW4WNF6CREMSGPG0F8sTXE7qWWxN QFpmqLRsEYyftldq48h8dMECDNycljDEwOMiwAsQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Benjamin Berg , Ingo Molnar , Andy Lutomirski , "H. Peter Anvin" , Oleg Nesterov , Sasha Levin Subject: [PATCH 6.1 007/204] x86/fpu: Avoid copying dynamic FP state from init_task in arch_dup_task_struct() Date: Tue, 8 Apr 2025 12:48:57 +0200 Message-ID: <20250408104820.509800270@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250408104820.266892317@linuxfoundation.org> References: <20250408104820.266892317@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Benjamin Berg [ Upstream commit 5d3b81d4d8520efe888536b6906dc10fd1a228a8 ] The init_task instance of struct task_struct is statically allocated and may not contain the full FP state for userspace. As such, limit the copy to the valid area of both init_task and 'dst' and ensure all memory is initialized. Note that the FP state is only needed for userspace, and as such it is entirely reasonable for init_task to not contain parts of it. Fixes: 5aaeb5c01c5b ("x86/fpu, sched: Introduce CONFIG_ARCH_WANTS_DYNAMIC_TASK_STRUCT and use it on x86") Signed-off-by: Benjamin Berg Signed-off-by: Ingo Molnar Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Oleg Nesterov Link: https://lore.kernel.org/r/20250226133136.816901-1-benjamin@sipsolutions.net ---- v2: - Fix code if arch_task_struct_size < sizeof(init_task) by using memcpy_and_pad. Signed-off-by: Sasha Levin --- arch/x86/kernel/process.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index acc83738bf5b4..24c237c571980 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -87,7 +87,12 @@ EXPORT_PER_CPU_SYMBOL_GPL(__tss_limit_invalid); */ int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) { - memcpy(dst, src, arch_task_struct_size); + /* init_task is not dynamically sized (incomplete FPU state) */ + if (unlikely(src == &init_task)) + memcpy_and_pad(dst, arch_task_struct_size, src, sizeof(init_task), 0); + else + memcpy(dst, src, arch_task_struct_size); + #ifdef CONFIG_VM86 dst->thread.vm86 = NULL; #endif -- 2.39.5