From nobody Thu Dec 18 08:12:11 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (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 379F71F943F; Tue, 17 Dec 2024 20:30:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734467406; cv=none; b=UCYePpQ/RbnkGOolBRzU5oZI9oZ9qJ58YgLOYYOSp3e1Q3Xzvxx56IAZkA2M5WD3rIeN6IQueMHpNnb8gOUcQtEv8+R2hBurtOZUgfMo8XxwFAaf2tTEvMS5UAp5IdQMP1SfZTi2gaB2V0jSlgOvJxeRUUAMjb2efG4es6cC5Ec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734467406; c=relaxed/simple; bh=Z80w1HgxIV3UI8galudFVxy177YA6OE8rE6J+pDqEOg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hnRmVMlq5ek/56xCL0q3Vq577Iog9mi1F+1TRezcYF05JlzXkBjAA6or3oJUT/QooWUVygWwLC/V7zpv5nG6VKolDWMDYZMkzuUnprCasmfkaLtyMJGNedpRhhWai5LK8ZQibeKlnUXujuj9mBTJTraStSQFZ3Hr1YbSleUAoi4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=remxbLmQ; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="remxbLmQ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=V7D68RzS3aDMea5rHMJVmyfJ9DYfvHvk9VNugqZY76I=; t=1734467405; x=1735677005; b=remxbLmQOOPXhoOQXNEnIKkIogH5ZUImZecEy6V4R9NyNKL UGWey/DE8fq7O5/X3nkt/xHoRPKleY98SW77skHZozrUcDjq5Qc4uMZdFjkyUbSGP/sDtj85D+cte n3HGfbM9/G0GLLy8OhMRz9BH9pl4NY7NuHixjafoLSBcaWxWj2zDPAjBK2wMwqABdioWpJEef9aU1 QK+T0k4TwsENU8Y05gp+oKg36ebn3Vr8eou2K2L6fl8Zjf/BRxt+Zu6xn35N53GAiVjHbIO2dJX4a jfAL86MSeOPq/qVq0185bsU0G7qFZciFjElUv6V+aJXY2grt0QXKso2eAGwVa7Pw==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98) (envelope-from ) id 1tNeCf-00000002NwX-1yDZ; Tue, 17 Dec 2024 21:30:01 +0100 From: Benjamin Berg To: linux-arch@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, briannorris@chromium.org Cc: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Benjamin Berg Subject: [PATCH 1/3] vmlinux.lds.h: remove entry to place init_task onto init_stack Date: Tue, 17 Dec 2024 21:27:43 +0100 Message-ID: <20241217202745.1402932-2-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241217202745.1402932-1-benjamin@sipsolutions.net> References: <20241217202745.1402932-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Benjamin Berg Since commit 0eb5085c3874 ("arch: remove ARCH_TASK_STRUCT_ON_STACK") there is no option that would allow placing task_struct on the stack. Remove the unused linker script entry. Signed-off-by: Benjamin Berg --- include/asm-generic/vmlinux.lds.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinu= x.lds.h index 54504013c749..8cd631a95084 100644 --- a/include/asm-generic/vmlinux.lds.h +++ b/include/asm-generic/vmlinux.lds.h @@ -404,7 +404,6 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELL= ER_CLANG) __start_init_stack =3D .; \ init_thread_union =3D .; \ init_stack =3D .; \ - KEEP(*(.data..init_task)) \ KEEP(*(.data..init_thread_info)) \ . =3D __start_init_stack + THREAD_SIZE; \ __end_init_stack =3D .; --=20 2.47.1 From nobody Thu Dec 18 08:12:11 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (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 1FAA31F9431; Tue, 17 Dec 2024 20:30:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734467409; cv=none; b=qz2LpYMaC3NRlDsLM/Q2KtV2dWbS5tOiXE811900tn7v0WyA/9ygJsIfDGFYcGWjlFpkBKZGH5tWMWOuHIxx7qI7kkn4FF4s1nxsR4Htywxymx3nMzgAWFVnJyWsDuMsSdDn+RT/j2dcTrijBG0NAc+UoWlbOTfjNQe6adEaJx0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734467409; c=relaxed/simple; bh=oSvxRtG8yd0aOUYBeKLnJlF2PXIbnGjHvP4nj8t7UXM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PfA4SV06IztJw4L4pDtQA3l8OP5FS7F0q/nl2NhjF4my1ku5+RHHbcF48EB70jwk6XnaSDnir221tQ9U41gmy9NT5i3SP407Z792sJT8nmpypQHo5LM3KIkI5sxBJn+igRNDptO7z1QBS1T3RcqHmOmeUBr407XKrKBAlSnfZDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=FdBz/X7i; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="FdBz/X7i" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=111IE7H4zmyUsr2adVE7p7sD/t82ixlQP2Vi9ldpbO4=; t=1734467408; x=1735677008; b=FdBz/X7iCetpt2oP9LthYNdDBo42VRFczGUxXOo5C5dSykA DhyQXRc22Bpa2plqqN5Sd1kqMHNMHTTfUNdM6nEz+MwXlfWtJvd0F3l26NQ4w5vbaBKiVrGnb75s7 aUYhhip8eoiGnFmlSfuQpKbXi98TejeKn30qcAT7UIgBTB8cLpmEVTWO/HIXoqbFbBjEyz5MYNa0d K7SQRSmaxlzAXkm7hzgv/GHsZFkGwGv4ys7krQY2o8oWCBDm6tPq7yltSBX2ADDpo0HPABiuueB64 DFO/OPqIgaWuhyGss/lobuQKsiOmDJQWGRjaVLSmJZpW1Oap6KF0vQE8gkEN/N9A==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98) (envelope-from ) id 1tNeCh-00000002NwX-3323; Tue, 17 Dec 2024 21:30:04 +0100 From: Benjamin Berg To: linux-arch@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, briannorris@chromium.org Cc: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Benjamin Berg Subject: [PATCH 2/3] um: avoid copying FP state from init_task Date: Tue, 17 Dec 2024 21:27:44 +0100 Message-ID: <20241217202745.1402932-3-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241217202745.1402932-1-benjamin@sipsolutions.net> References: <20241217202745.1402932-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Benjamin Berg The init_task instance of struct task_struct is statically allocated and does not contain the dynamic area for the userspace FP registers. As such, limit the copy to the valid area of init_task and fill the rest with zero. Note that the FP state is only needed for userspace, and as such it is entirely reasonable for init_task to not contain it. Reported-by: Brian Norris Closes: https://lore.kernel.org/Z1ySXmjZm-xOqk90@google.com Fixes: 3f17fed21491 ("um: switch to regset API and depend on XSTATE") Signed-off-by: Benjamin Berg Tested-by: Thomas Wei=C3=9Fschuh --- arch/um/kernel/process.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c index 30bdc0a87dc8..3a67ba8aa62d 100644 --- a/arch/um/kernel/process.c +++ b/arch/um/kernel/process.c @@ -191,7 +191,15 @@ void initial_thread_cb(void (*proc)(void *), void *arg) 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 (missing FPU state) */ + if (unlikely(src =3D=3D &init_task)) { + memcpy(dst, src, sizeof(init_task)); + memset((void *)dst + sizeof(init_task), 0, + arch_task_struct_size - sizeof(init_task)); + } else { + memcpy(dst, src, arch_task_struct_size); + } + return 0; } =20 --=20 2.47.1 From nobody Thu Dec 18 08:12:12 2025 Received: from sipsolutions.net (s3.sipsolutions.net [168.119.38.16]) (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 AC6911FA141; Tue, 17 Dec 2024 20:30:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=168.119.38.16 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734467411; cv=none; b=gG7h5UkfuFrmKpteXLbFRAOETIifzwvxhqYYeuOojCtbdBFpIV+aKdvb4BNJVsRHk9CoYi27TJU+5voR6SAMuKJEpGpS9kvP4GF7t/YLoCndm9v+hXey2A+JtkHIjl5eI1nN0HdS17FU1pFY3DWFKjNbohbrmI06sfiCjIHaz2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734467411; c=relaxed/simple; bh=GMDVzuQNflKsXt8Ams72LmA7hrTPf5xwTvnBqM8M5Hc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uzb3M+TuqUEsRTXemu07P/ZONPeXAhCYY7vttLym4zA3xkLu/PK5ZNY6J76TKf1bVO1FzkjvY8+4Ck6TOwt7i0vRlEuCoMyTUgPXP9ZEoik6V+oYJPsmYka3fLRasxenaN1kLffVcSmT0WJx243hAn/D7Z3KP1cb1pn0+GJZHVQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net; spf=pass smtp.mailfrom=sipsolutions.net; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b=jp5PCoEE; arc=none smtp.client-ip=168.119.38.16 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sipsolutions.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sipsolutions.net header.i=@sipsolutions.net header.b="jp5PCoEE" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=2AjmcsgTzx3TIo/NiPZF3pU4weuGY3iYJ3AIwf8Kn/s=; t=1734467409; x=1735677009; b=jp5PCoEEASrMQs9Kkq+XwReFaVtnPpsis17t4DsOKTbQeyq M6iCgj77uui6R6Ek9WO0Syvfcp5P70eFBru8O2Foj+gFbhVwA5WzeK+TEM781bAF2zORvQYlxrSsx NfVjVelGAlmNqS11omBh/ULkoYF8J2i1pORUNZTbEIgLIuICb9auNp5PNA8rk1aiEdMtMGTHeej9i x3Y6xPlNG5HqWeXBP33Cq9d4jRqM4BK4FzEQuzLwKpRBnih5fLzHochRu5dr8V3buZ2aGelt6FGS6 flkD4HGcxi2+8VYEGFOZc5Gf4V0jJD38YTCyAv3sSA3EZJTWT1HhLJuXkDTMT6FQ==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.98) (envelope-from ) id 1tNeCk-00000002NwX-3MTY; Tue, 17 Dec 2024 21:30:07 +0100 From: Benjamin Berg To: linux-arch@vger.kernel.org, linux-um@lists.infradead.org, x86@kernel.org, briannorris@chromium.org Cc: linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Benjamin Berg Subject: [PATCH 3/3] x86: avoid copying dynamic FP state from init_task Date: Tue, 17 Dec 2024 21:27:45 +0100 Message-ID: <20241217202745.1402932-4-benjamin@sipsolutions.net> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241217202745.1402932-1-benjamin@sipsolutions.net> References: <20241217202745.1402932-1-benjamin@sipsolutions.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Benjamin Berg 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 init_task and fill the rest with zero. 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. Signed-off-by: Benjamin Berg Fixes: 5aaeb5c01c5b ("x86/fpu, sched: Introduce CONFIG_ARCH_WANTS_DYNAMIC_T= ASK_STRUCT and use it on x86") --- arch/x86/kernel/process.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index f63f8fd00a91..1be45fe70cad 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -92,7 +92,15 @@ 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 =3D=3D &init_task)) { + memcpy(dst, src, sizeof(init_task)); + memset((void *)dst + sizeof(init_task), 0, + arch_task_struct_size - sizeof(init_task)); + } else { + memcpy(dst, src, arch_task_struct_size); + } + #ifdef CONFIG_VM86 dst->thread.vm86 =3D NULL; #endif --=20 2.47.1