From nobody Wed Oct 1 23:30:09 2025 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 3DA2F1F462C; Mon, 29 Sep 2025 04:00:04 +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=1759118405; cv=none; b=fDu5Y1BErrPUTlneu7V9KhIDu2t8l+XXNkADuclGiIcXnY423kaGjRYAFu6go6yds7G1AZ8JgSRBbvLCqnRYtPdGpKGAycC0DtajQgI2UH4fPQh+ngdw3JsOA0hkniF5lhJJXw+ZXdJPcoSY3qPAEVTZ17ppEK6jLAlIFZzDZAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1759118405; c=relaxed/simple; bh=S7K6IaShWtXQ8ax6mFIu2V9kk51XsYQUCSQjLA/qhsw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MRn6HcRi/i+wxuccnXBqXVpNT2ojO+Ua2jJwJuWSc0OSrm1I6W+qaufJrml2RcFyX0xSP32jjZVbXscYhi4egwaYFdjOdfB5LA5K/R9mtlg9xo9467/NwrWSC86udMS8N7i7Yl3EgvRPOZhbYW7dhM/cDpwfbnQljn/ryc9mqkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SB0+uKmA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SB0+uKmA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41C78C116B1; Mon, 29 Sep 2025 04:00:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1759118404; bh=S7K6IaShWtXQ8ax6mFIu2V9kk51XsYQUCSQjLA/qhsw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SB0+uKmAsbedV/hgzCP6m4lvh/ZwjM67/QGOC3DU/6ar84UUdOUE+SGCNEL2yXgbo vqZpa13Tx6WMGIynf6zK81Zt6Bf5EtQQj01ydqdSK7AxQy77+lv8OVvJANTjim7a98 ZqW2vcYWLkxBVeS16WLufXjuIKFG/ZeW8cENEyGhcJeipYMrE8zmxIC4lshqWu0pnw 2m4DtDnJ9WMX5oYQZyw9Xrn1GTws9Rg5pVycUCeKtPN6aNHpIwfPq/h8wbK5xuakwH Au1524CJ2gM2Jc/Gyakkxrtrc1I20IyP172aZpxYKNbJKIVLyQityF0z756GGvyGEW G+nOS2kZhNFgQ== From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: dpsmith@apertussolutions.com, ross.philipson@oracle.com, Jarkko Sakkinen , David Howells , Jarkko Sakkinen , Paul Moore , James Morris , "Serge E. Hallyn" , James Bottomley , Mimi Zohar , keyrings@vger.kernel.org (open list:KEYS/KEYRINGS), linux-security-module@vger.kernel.org (open list:SECURITY SUBSYSTEM), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 3/9] KEYS: trusted: Use tpm_ret_to_err() in trusted_tpm2 Date: Mon, 29 Sep 2025 06:59:32 +0300 Message-Id: <20250929035938.1773341-4-jarkko@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250929035938.1773341-1-jarkko@kernel.org> References: <20250929035938.1773341-1-jarkko@kernel.org> 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: Jarkko Sakkinen Use tpm_ret_to_err() to transmute TPM return codes in trusted_tpm2. Signed-off-by: Jarkko Sakkinen --- v2: - New patch split out from the fix. --- security/keys/trusted-keys/trusted_tpm2.c | 26 ++++++----------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trus= ted-keys/trusted_tpm2.c index 024be262702f..e165b117bbca 100644 --- a/security/keys/trusted-keys/trusted_tpm2.c +++ b/security/keys/trusted-keys/trusted_tpm2.c @@ -348,25 +348,19 @@ int tpm2_seal_trusted(struct tpm_chip *chip, } =20 blob_len =3D tpm2_key_encode(payload, options, &buf.data[offset], blob_le= n); + if (blob_len < 0) + rc =3D blob_len; =20 out: tpm_buf_destroy(&sized); tpm_buf_destroy(&buf); =20 - if (rc > 0) { - if (tpm2_rc_value(rc) =3D=3D TPM2_RC_HASH) - rc =3D -EINVAL; - else - rc =3D -EPERM; - } - if (blob_len < 0) - rc =3D blob_len; - else + if (!rc) payload->blob_len =3D blob_len; =20 out_put: tpm_put_ops(chip); - return rc; + return tpm_ret_to_err(rc); } =20 /** @@ -468,10 +462,7 @@ static int tpm2_load_cmd(struct tpm_chip *chip, kfree(blob); tpm_buf_destroy(&buf); =20 - if (rc > 0) - rc =3D -EPERM; - - return rc; + return tpm_ret_to_err(rc); } =20 /** @@ -534,8 +525,6 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip, tpm_buf_fill_hmac_session(chip, &buf); rc =3D tpm_transmit_cmd(chip, &buf, 6, "unsealing"); rc =3D tpm_buf_check_hmac_response(chip, &buf, rc); - if (rc > 0) - rc =3D -EPERM; =20 if (!rc) { data_len =3D be16_to_cpup( @@ -568,7 +557,7 @@ static int tpm2_unseal_cmd(struct tpm_chip *chip, =20 out: tpm_buf_destroy(&buf); - return rc; + return tpm_ret_to_err(rc); } =20 /** @@ -600,6 +589,5 @@ int tpm2_unseal_trusted(struct tpm_chip *chip, =20 out: tpm_put_ops(chip); - - return rc; + return tpm_ret_to_err(rc); } --=20 2.39.5