From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795972001; b=hg52BMyVERQ7aKyvbe5Zv2bkkHnOkCXPc3bGKqxqhVvFFgq6zdTrIgw2EVcq7Vx5yBHp cJjIatdj+62MIXsIw9VeayAh/XWdcUzjbszZ7n55ZbLm03H0td9ApjiRFXXaEQKfInyc3 H6CilbgQJ9+ghEPEDIKPuSsK1/UFTW3qKmujOYkuFA7AyErz7cDN9W/Qm6bHme6slTZff k9jSvQu5vRJrBjB37PKoixlRMD5uuhiR8OY2BYVeo1qxIQWhqYl6vKCp29pwpx7YAq5s5 lZpL7wtVtaxThl6wjQ0LyIqhrv1m3wSG6oBCBAAmLPwKf00R0rsSPYgU5ptewnjRUPw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795972001; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=lk64juXN0HoCLqIHjiFlMfzZjUqdrfZXIED0yZqdsss=; b=S+QyscaRJFfIH143Qt8fcR0piE4nwmmu0LslHY5Vu+S6NJa+sUbuDNvYxc5TD7KsHVlO DWsLPPFRFL7LfV8eBtqlA4Bz5qkEC+A5oKu97R5YRm/3oTiJ/1nhE/TFUn+xPNgvJVWn2 txSc53FYCL0D42LpXABZQif3VAysNbJcLCSWi5le7Q8gqpeRD8qM6+QiCas0T1CtjwLqm FOOsH/b7s1sjbxa41u/ZRxn71zDtsiwaPU1Kg+zUdb+DcjSQ/db1FnnK3bZywwulTqxBI 3ZM2YfVYU4qB2AbVYtHEeDJ2E+M2xqxEY1L7M2nbuHCqwqmA1FvtnTzZ0U8FqqHZtMA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="j/HzTHet"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with UTF8SMTPS id 36AA2606A327; Sun, 29 Nov 2026 17:06:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=j/HzTHet Received: by smtp.kernel.org (Postfix) with UTF8SMTPSA id 3D95A1F00898; Sun, 29 Nov 2026 17:06:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795972001; bh=lk64juXN0HoCLqIHjiFlMfzZjUqdrfZXIED0yZqdsss=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=j/HzTHettqOkH7t/g//hzvNt2YbOEczEB/IS4GbWhXesFTzHr8q48FoGTstM2dy0V h1yO1NDUBgh7P1Brmdu046N8+8uC6HV2vUZSH+QQJ/A1sIAfTItkIkQw27SNeuCmIR ILapaJGBzcSxdO3kNxfcRpMqW40tTXj2gQ89Y4AnEaN1bCIHchbGsn09jN34f8QHaE YwXNC09VfnRyI8cTtb/37e0l8O5Wj+8D/xD6i7NR8HzIHvIxR2I0J3UiY+N/2m5mCb HELuBimczu15pqRZRvDEjFIv7DnoMSOFQKfXqU+gn3Dmd+knR2AGMbxZ85Uc7NvMce 5HouaKxk4Hnbg== From: Jarkko Sakkinen To: keyrings@vger.kernel.org Cc: Jarkko Sakkinen , linux-afs@lists.infradead.org, linux-cifs@vger.kernel.org, linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nfs@vger.kernel.org, linux-s390@vger.kernel.org, linux-security-module@vger.kernel.org, netdev@vger.kernel.org, samba-technical@lists.samba.org, Alexander Gordeev , Anna Schumaker , Bharath SM , Christian Borntraeger , David Howells , "David S. Miller" , Eric Dumazet , Heiko Carstens , Jakub Kicinski , James Bottomley , James Morris , Jonathan Corbet , Marc Dionne , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Mimi Zohar , Namjae Jeon , Paolo Abeni , Paul Moore , Paulo Alcantara , Randy Dunlap , Ronnie Sahlberg , "Serge E. Hallyn" , Shuah Khan , Shyam Prasad N , Simon Horman , Sumit Garg , Sven Schnelle , Tom Talpey , Trond Myklebust , Vasily Gorbik , Willem de Bruijn Subject: [PATCH v7 12/14] KEYS: trusted: Unregister key type on module exit in TEE backend Date: Sun, 29 Nov 2026 19:05:41 +0200 Message-ID: <20261129170543.2915157-13-jarkko@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261129170543.2915157-1-jarkko@kernel.org> References: <20261129170543.2915157-1-jarkko@kernel.org> X-Mailing-List: linux-integrity@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 trusted_key_remove() is a TEE client bus .remove() callback that runs when the underlying TEE device unbinds, whereas key_type_trusted is owned by trusted.ko. Once keys pin trusted.ko and unregister_key_type() no longer reaps extant keys via key_type_dead, unregistering key_type_trusted from trusted_key_remove() can run while trusted keys still exist. Keep key_type_trusted registered until trusted_tee_exit(), matching the other trusted-key backends, while trusted_key_remove() tears down the TEE session so subsequent TEE operations return -ENODEV. Signed-off-by: Jarkko Sakkinen --- security/keys/trusted-keys/trusted_tee.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/security/keys/trusted-keys/trusted_tee.c b/security/keys/trusted-keys/trusted_tee.c index 87ea549f7f0b..4b67f504a54b 100644 --- a/security/keys/trusted-keys/trusted_tee.c +++ b/security/keys/trusted-keys/trusted_tee.c @@ -57,6 +57,7 @@ struct trusted_key_tee_private { }; static struct trusted_key_tee_private pvt_data; +static bool trusted_key_registered; /* Do not hold this mutex across key type registration or unregistration. */ static DEFINE_MUTEX(trusted_key_tee_mutex); @@ -266,10 +267,15 @@ static int trusted_key_probe(struct tee_client_device *rng_device) pvt_data.dev = dev; mutex_unlock(&trusted_key_tee_mutex); - ret = register_key_type(&key_type_trusted); - if (!ret) - return 0; + if (!trusted_key_registered) { + ret = register_key_type(&key_type_trusted); + if (ret) + goto err_close_session; + trusted_key_registered = true; + } + return 0; +err_close_session: mutex_lock(&trusted_key_tee_mutex); tee_client_close_session(ctx, pvt_data.session_id); out_ctx: @@ -284,8 +290,6 @@ static int trusted_key_probe(struct tee_client_device *rng_device) static void trusted_key_remove(struct tee_client_device *dev) { - unregister_key_type(&key_type_trusted); - mutex_lock(&trusted_key_tee_mutex); tee_client_close_session(pvt_data.ctx, pvt_data.session_id); tee_client_close_context(pvt_data.ctx); @@ -320,6 +324,8 @@ static int trusted_tee_init(void) static void trusted_tee_exit(void) { tee_client_driver_unregister(&trusted_key_driver); + if (trusted_key_registered) + unregister_key_type(&key_type_trusted); } struct trusted_key_ops trusted_key_tee_ops = { -- 2.47.3