From nobody Mon Sep 28 13:18:32 2026 Received: from oss.cyber.gouv.fr (oss.cyber.gouv.fr [51.159.188.251]) (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 D1FA039E176 for ; Fri, 21 Aug 2026 10:22:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=51.159.188.251 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787307780; cv=none; b=VfUfybFaKU8YZk3J5fY/LBsQut5nAuejrVUYpH5UCL54JC5B0le2K2ueU4sG21GmrXTwYfF+JEnWePIfTyvPp4Row9A9aaFhT1HeEXpACrOcLCK3fwbsTDHQF+DdAUOlvI/2+xblZ76+arip6kF7oD6Fboo+4vWDFgftN5s775E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787307780; c=relaxed/simple; bh=v5yaetC2iNbsaCNuEYQ4Vn80DVMORvndOUmIh2FUnjk=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=AJLXomLkw6W1Al20HycwkNGzRzhpDy9AHJxltJucy7izPPBYBAeMZm8WE2uvQWhc0jhEAz75C3POqkapfI4JxZQiSgAo54ubca4gt6WPXs/3BL/1WD1S64qoHWvmmoKa0Ykx/R++i50/AYRvBnZ0cyjtMfFViJT/ctM6a6VQQSk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.cyber.gouv.fr; spf=pass smtp.mailfrom=oss.cyber.gouv.fr; dkim=pass (2048-bit key) header.d=oss.cyber.gouv.fr header.i=@oss.cyber.gouv.fr header.b=lthBTzfx; arc=none smtp.client-ip=51.159.188.251 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.cyber.gouv.fr Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.cyber.gouv.fr Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oss.cyber.gouv.fr header.i=@oss.cyber.gouv.fr header.b="lthBTzfx" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=oss.cyber.gouv.fr; s=default; h=Content-Transfer-Encoding:Content-Type: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JEr8w4nR21pzOukAyhBhhXDwo5ooGu0VwxUIJYQuB9g=; b=lthBTzfxbAaZnvwdXTpDEjEvDb b0MDMHOKvzWsMTxkkRzamBEfAaWQwI7uM2/4bH1ZlNm5FVT7HOhKnOQr9QmakA6c4mgdxDAWsLkfd aYc3dGEvP+sF/BsJ0czbqqRp9V8+JhDSv3bQ5bdh9VRd59kI16tOVR/NDs2kDDweSRKltXNN/Fks5 5LrLMYAQ9iPICSNzqBOPirLDcrjgF7si6CZ7BdkVXaV11FDy+2CEUAa15aIQqkTolfnOuCuvUCS0s W1ShV1poidagoCTmJ9aHbQ4vMBgVln0njDGClV8tCgAEwuKehRYzILT8FNoqxrFI96hjX0tzLxLWH pnxQ/VrA==; Received: from [151.115.150.205] (port=45678 helo=gepetto..) by pf-012.whm.fr-par.scw.cloud with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.99.5) (envelope-from ) id 1wxMOd-00000004kiq-1h8z; Fri, 21 Aug 2026 12:22:47 +0200 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Jean?= To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot Cc: Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , K Prateek Nayak , Kees Cook , linux-kernel@vger.kernel.org, linux-mm@kvack.org, =?UTF-8?q?J=C3=A9r=C3=A9my=20Jean?= Subject: [PATCH] fork: initialize function graph state before copy_exec_state() Date: Fri, 21 Aug 2026 10:22:08 +0000 Message-ID: <20260821102207.3626491-2-Jeremy.Jean@oss.cyber.gouv.fr> X-Mailer: git-send-email 2.47.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - pf-012.whm.fr-par.scw.cloud X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - oss.cyber.gouv.fr X-Get-Message-Sender-Via: pf-012.whm.fr-par.scw.cloud: authenticated_id: jeremy.jean@oss.cyber.gouv.fr X-Authenticated-Sender: pf-012.whm.fr-par.scw.cloud: jeremy.jean@oss.cyber.gouv.fr X-Source: X-Source-Args: X-Source-Dir: dup_task_struct() copies the parent's task_struct, including ret_stack. ftrace_graph_init_task() clears the copied function graph state, but it currently runs after copy_exec_state(). For non-CLONE_VM forks, copy_exec_state() allocates a new task_exec_state. If that allocation fails, copy_process() reaches bad_fork_free and free_task() calls ftrace_graph_exit_task(). Since the child still carries the parent's ret_stack pointer, the unwind frees the parent's active function graph return stack. The parent subsequently accesses freed memory from function_graph_enter_regs(). KASAN reports a UAF. Initialize the child function graph state immediately after dup_task_struct(), before the first fallible operation. Fixes: 6b1c66c9cca9 ("exec_state: relocate dumpable information") Assisted-by: Codex:gpt-5 Signed-off-by: J=C3=A9r=C3=A9my Jean Reviewed-by: Bradley Morgan --- kernel/fork.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index 1e68404bd773..cec82a64a07c 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -2139,6 +2139,7 @@ __latent_entropy struct task_struct *copy_process( p =3D dup_task_struct(current, node); if (!p) goto fork_out; + ftrace_graph_init_task(p); retval =3D copy_exec_state(clone_flags, p); if (retval) goto bad_fork_free; @@ -2165,8 +2166,6 @@ __latent_entropy struct task_struct *copy_process( */ p->clear_child_tid =3D (clone_flags & CLONE_CHILD_CLEARTID) ? args->child= _tid : NULL; =20 - ftrace_graph_init_task(p); - rt_mutex_init_task(p); raw_spin_lock_init(&p->blocked_lock); =20 --=20 2.47.3