From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5425BCA5FAB for ; Wed, 30 Sep 2026 06:42:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=/f72Z+MEWNGWysprS0ii85w3IitLDtyI12UnQpvPMAI=; b=iwVn5gJ/SgiJ5TkBTPJhrSIzeo FeUIXbiigm1Gvk4atNJ2Y324HJMgFjAlVv4hE0e+jRTwFcnJW2HeDY7cNVwcNb4fVomFJidcUadYV PvPzdFld4Qw9XeyTbKr2CmL2+rp7CYoMhgqw3ZuHmffMz9OM27jgnTMrzHh5smxAV/iCLwX2FIw6B LzYI9Or9xdS60xcUKoucPYrZB7417yOJTfsXgkHDV0xoDL2BBUwTN6Mw2aao7JHTNyzqzIe8DESbY GnSY+eJN3nAGlBTlcPnUenWMAMTJmFtaAz4NG+2Ks5Pfx8LWjDoE1sYgg5I+jLbU0QdQOMfqlRCVr AVMq1+MA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1xBo1C-00000005Av9-35oY; Wed, 30 Sep 2026 06:42:18 +0000 Received: from smtp1.osuosl.org ([140.211.166.138]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1xBo1A-00000005AsO-01Sj for linux-arm-kernel@lists.infradead.org; Wed, 30 Sep 2026 06:42:17 +0000 Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 8D9E481022; Wed, 30 Sep 2026 06:36:48 +0000 (UTC) X-Virus-Scanned: amavis at osuosl.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavis, port 10024) with ESMTP id tm6BMWKRjpYP; Wed, 30 Sep 2026 06:36:48 +0000 (UTC) ARC-Filter: OpenARC Filter v1.3.0 smtp1.osuosl.org EEC7780AFE Authentication-Results: smtp1.osuosl.org; arc=none smtp.remote-ip=140.211.9.71 ARC-Seal: i=1; d=osuosl.org; s=arc; a=rsa-sha256; cv=none; t=1790750208; b=HMetY7rxg6E0y5e43V4/0+556gxqbr8q2z4A4mo5Zho2UbCFJApPIoq3RCn9k18/NNfl 5GcKFnc8yahBQbLk+W/6/IgynHM6sJN1XWvIqzyrGQ7QEeZHYi0/4ffY90vJ2kBBuIANu mIgg4IvPNcN7XFF+zZf8DAyYddJSH/gU6cN8lXxEcOz3TercKE7Kutj440V1wwxTDxTEe E0zxsTArANGheBwRpQzj+4IJQiXxhqgASIKBhANElWG/bfz3/MyWKArobd8PiIhadIGXd vmVEdWxHh0cbHr4FO39bOnLK1myP47kS1K99zc2evTEa9znb2TBtOPSNYG1d980ChGw== ARC-Message-Signature: i=1; d=osuosl.org; s=arc; a=rsa-sha256; c=relaxed/relaxed; t=1790750208; h=X-Comment:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=/f72Z+MEWNGWysprS0ii85w3IitLDtyI12UnQpvPMAI=; b=qzpVxkOdZW7x+zOiAt8kqKUhHV4Jn86ppzwPm4J0LLbNCfcBUP5ddpveFMIKyx8B6f5I 41Q2lQW6JpgiZ+e4bC4IUiyUA8u+2XnaKtjC2dQcqJMKllAXeTvMNcCCjdIg+uqOdapiO AMUwPF7coBAINFkwrHvjDnD/KTK1BS2LRKohn/7Q77uwSCQ2zeoyykkGkfCNBjdsaDM3N KAK6xm77UKvwqUeq2EjqCvAjUiH5ERQOOF6K1y0bbgwRJ6bJ/neMR2dZKO2c/4bDUwXZh 1SxZyq2IMa2pZfiJsvvEe4JgkJcFL/6yVUMe+FCmU2i/+hOQnhcoPowHVY62anKEmTw== ARC-Authentication-Results: i=1; smtp1.osuosl.org; arc=none smtp.remote-ip=140.211.9.71 X-Comment: SPF check N/A for local connections - client-ip=140.211.9.71; helo=p10-linux-brads.localdomain; envelope-from=root@p10-linux-brads.localdomain; receiver= Received: from p10-linux-brads.localdomain (p10-linux-brads.osuosl.org [140.211.9.71]) by smtp1.osuosl.org (Postfix) with ESMTPS id EEC7780AFE; Wed, 30 Sep 2026 06:36:47 +0000 (UTC) Received: by p10-linux-brads.localdomain (Postfix, from userid 0) id D59A04407F3; Wed, 30 Sep 2026 06:36:47 +0000 (UTC) From: Bradley Morgan To: Catalin Marinas , Will Deacon Cc: Mark Rutland , Mark Brown , Vladimir Murzin , Ard Biesheuvel , Kees Cook , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Bradley Morgan Subject: [PATCH] arm64: scrub vector and pointer auth state on task death Date: Wed, 30 Sep 2026 06:36:47 +0000 Message-ID: <20260930063647.1356613-1-brads@mainlining.org> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260929_234216_073923_97ECEF5B X-CRM114-Status: GOOD ( 16.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When a task dies its SVE, SME and FPSIMD register state, and its pointer auth keys, stay in freed slab pages until the allocator hands them out again. init_on_free=1 users get this wiped for the whole heap but the option is expensive, so it is off in most builds. The vector registers are not idle memory: userspace crypto runs AES-GCM and Argon2 through SVE, so key material ends up in sve_state, sme_state and thread_struct. On task exit and on the exec and vector length reallocation paths those buffers are dropped with a plain kfree(), and on task death the register file copy embedded in thread_struct is not wiped at all. Anything that reads the freed slab back (slab bugs, cold boot, a leaked page) gets the dead task's keys. Scrub it. kfree_sensitive() already exists for this exact job, so the freeing sites just switch to it. The register file copy and the pointer auth keys embedded in thread_struct cannot go through kfree_sensitive(), so arch_release_task_struct() zeroes them directly with memzero_explicit(). Scrubbed state: - sve_state, sme_state allocations, freed on task death, exec flush and vector length change - the uw.fpsimd_state register file copy embedded in thread_struct - pointer auth user and kernel keys embedded in thread_struct This is a cold path. The cost is one memset of at most a few KB plus the register file per dying task. Signed-off-by: Bradley Morgan --- arch/arm64/kernel/fpsimd.c | 12 ++++++------ arch/arm64/kernel/process.c | 16 +++++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c index e7f1682a3059..c149c12ba9f9 100644 --- a/arch/arm64/kernel/fpsimd.c +++ b/arch/arm64/kernel/fpsimd.c @@ -737,7 +737,7 @@ void cpu_enable_fpmr(const struct arm64_cpu_capabilities *__always_unused p) #ifdef CONFIG_ARM64_SVE static void sve_free(struct task_struct *task) { - kfree(task->thread.sve_state); + kfree_sensitive(task->thread.sve_state); task->thread.sve_state = NULL; } @@ -846,13 +846,13 @@ static int change_live_vector_length(struct task_struct *task, */ fpsimd_sync_from_effective_state(task); task_set_vl(task, type, vl); - kfree(task->thread.sve_state); + kfree_sensitive(task->thread.sve_state); task->thread.sve_state = sve_state; fpsimd_sync_to_effective_state_zeropad(task); if (type == ARM64_VEC_SME) { task->thread.svcr &= ~SVCR_ZA_MASK; - kfree(task->thread.sme_state); + kfree_sensitive(task->thread.sme_state); task->thread.sme_state = sme_state; } @@ -1195,7 +1195,7 @@ void sme_alloc(struct task_struct *task, bool flush) static void sme_free(struct task_struct *task) { - kfree(task->thread.sme_state); + kfree_sensitive(task->thread.sme_state); task->thread.sme_state = NULL; } @@ -1687,8 +1687,8 @@ void fpsimd_flush_thread(void) current->thread.fp_type = FP_STATE_FPSIMD; put_cpu_fpsimd_context(); - kfree(sve_state); - kfree(sme_state); + kfree_sensitive(sve_state); + kfree_sensitive(sme_state); } /* diff --git a/arch/arm64/kernel/process.c b/arch/arm64/kernel/process.c index 581f80e9b9b7..c1d5d7c0fd3f 100644 --- a/arch/arm64/kernel/process.c +++ b/arch/arm64/kernel/process.c @@ -344,6 +344,20 @@ void flush_thread(void) void arch_release_task_struct(struct task_struct *tsk) { fpsimd_release_task(tsk); + + /* + * Wipe the register file copy and the pointer auth keys, they + * can hold key material the dead task used. + */ + memzero_explicit(&tsk->thread.uw.fpsimd_state, + sizeof(tsk->thread.uw.fpsimd_state)); +#ifdef CONFIG_ARM64_PTR_AUTH + memzero_explicit(&tsk->thread.keys_user, sizeof(tsk->thread.keys_user)); +#ifdef CONFIG_ARM64_PTR_AUTH_KERNEL + memzero_explicit(&tsk->thread.keys_kernel, + sizeof(tsk->thread.keys_kernel)); +#endif +#endif } int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src) @@ -397,7 +411,7 @@ static int copy_thread_za(struct task_struct *dst, struct task_struct *src) sme_state_size(src), GFP_KERNEL); if (!dst->thread.sme_state) { - kfree(dst->thread.sve_state); + kfree_sensitive(dst->thread.sve_state); dst->thread.sve_state = NULL; return -ENOMEM; } -- 2.53.0