From nobody Tue Dec 16 14:35:46 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 CCF242D321D; Sun, 14 Dec 2025 15:38:42 +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=1765726722; cv=none; b=Sliwheyx4Tvp/2ohzuf+/RkTcO9yAp2l0I4I4v7ZX2RpfXL3pSdWZpeyCfAROMA/6W/DW3gTVhknc9BWggpYibRDO7deM5RpH8/Q27aci9g99HOTIroRGTSJaFE3CJ7o6hFjY538kNpJwRVQnoi5gH8rDM2+SEiuGedf+GJjsAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765726722; c=relaxed/simple; bh=syj0MAULIysE2DgFxh7p8MUgTG4fCnV6ZnXbKSMGMYU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JFYic9rDsHREeuy6XFv8A5OTlLnI+u7peCJ3kcr/doa+StUYT9s074YSTn7vUQ257sgchpDb4UumZNKsGbk+uSXwH6a0N7Qa0uLA5E5Y2sOl+VJHyL829vevXNjAPDl8AgygO3aPx1PiWEdospBPrFeCX6FyrV4MQHgdIK984E4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=axXrk9X+; 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="axXrk9X+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F169BC4CEFB; Sun, 14 Dec 2025 15:38:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1765726722; bh=syj0MAULIysE2DgFxh7p8MUgTG4fCnV6ZnXbKSMGMYU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=axXrk9X+pulwyvdjgGp52Xl321IHUl6RZ2NALz4zHzfENM56VjC8HNWnWm9KswaDE FirwZtaUFR2OXrbO0V0toqTa5caWeGjz7ehRZwj06WGgNou1CgMw4t4dI7tsuKllaK tay7e9+4i1r53XkbPWh+zdA4JJPK2zRDrqIvl4VtqbGLfqm15eTUFlvzxAfUFWiea2 9Ji322X9te+R+q1L6+egMtFJu6Z+TsMHrY0iSbmTQgHDClgq4SOAo3ub6d30wFBFLH 4Hp0eB03kqvD9tEMIkLzpm4t3dUZFWDmqPIGMQOuoL+oFc99LbER1aT4+zx152hPGO nZKJf36koT90Q== From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: Ross Philipson , Jarkko Sakkinen , Peter Huewe , Jason Gunthorpe , David Howells , Paul Moore , James Morris , "Serge E. Hallyn" , linux-kernel@vger.kernel.org (open list), keyrings@vger.kernel.org (open list:KEYS/KEYRINGS), linux-security-module@vger.kernel.org (open list:SECURITY SUBSYSTEM) Subject: [PATCH v6 05/11] tpm2-sessions: Remove AUTH_MAX_NAMES Date: Sun, 14 Dec 2025 17:38:02 +0200 Message-Id: <20251214153808.73831-6-jarkko@kernel.org> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20251214153808.73831-1-jarkko@kernel.org> References: <20251214153808.73831-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" In all of the call sites only one session is ever append. Thus, reduce AUTH_MAX_NAMES, which leads into removing constant completely. Signed-off-by: Jarkko Sakkinen --- drivers/char/tpm/tpm2-sessions.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/drivers/char/tpm/tpm2-sessions.c b/drivers/char/tpm/tpm2-sessi= ons.c index 3bc3c31cf512..37570dc088cf 100644 --- a/drivers/char/tpm/tpm2-sessions.c +++ b/drivers/char/tpm/tpm2-sessions.c @@ -72,9 +72,6 @@ #include #include =20 -/* maximum number of names the TPM must remember for authorization */ -#define AUTH_MAX_NAMES 3 - #define AES_KEY_BYTES AES_KEYSIZE_128 #define AES_KEY_BITS (AES_KEY_BYTES*8) =20 @@ -136,8 +133,8 @@ struct tpm2_auth { * handle, but they are part of the session by name, which * we must compute and remember */ - u8 name[AUTH_MAX_NAMES][TPM2_MAX_NAME_SIZE]; - u16 name_size_tbl[AUTH_MAX_NAMES]; + u8 name[TPM2_MAX_NAME_SIZE]; + u16 name_size; }; =20 #ifdef CONFIG_TCG_TPM2_HMAC @@ -261,11 +258,14 @@ EXPORT_SYMBOL_GPL(tpm2_read_public); int tpm_buf_append_name(struct tpm_chip *chip, struct tpm_buf *buf, u32 handle, u8 *name, u16 name_size) { -#ifdef CONFIG_TCG_TPM2_HMAC struct tpm2_auth *auth; - int slot; int ret; -#endif + + if (tpm_buf_length(buf) !=3D TPM_HEADER_SIZE) { + dev_err(&chip->dev, "too many handles\n"); + ret =3D -EIO; + goto err; + } =20 if (!tpm2_chip_auth(chip)) { tpm_buf_append_handle(chip, buf, handle); @@ -273,12 +273,6 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct = tpm_buf *buf, } =20 #ifdef CONFIG_TCG_TPM2_HMAC - slot =3D (tpm_buf_length(buf) - TPM_HEADER_SIZE) / 4; - if (slot >=3D AUTH_MAX_NAMES) { - dev_err(&chip->dev, "too many handles\n"); - ret =3D -EIO; - goto err; - } auth =3D chip->auth; if (auth->session !=3D tpm_buf_length(buf)) { dev_err(&chip->dev, "session state malformed"); @@ -287,16 +281,14 @@ int tpm_buf_append_name(struct tpm_chip *chip, struct= tpm_buf *buf, } tpm_buf_append_u32(buf, handle); auth->session +=3D 4; - memcpy(auth->name[slot], name, name_size); - auth->name_size_tbl[slot] =3D name_size; + memcpy(auth->name, name, name_size); + auth->name_size =3D name_size; #endif return 0; =20 -#ifdef CONFIG_TCG_TPM2_HMAC err: tpm2_end_auth_session(chip); return ret; -#endif } EXPORT_SYMBOL_GPL(tpm_buf_append_name); =20 @@ -665,8 +657,7 @@ int tpm_buf_fill_hmac_session(struct tpm_chip *chip, st= ruct tpm_buf *buf) /* ordinal is already BE */ sha256_update(&sctx, (u8 *)&head->ordinal, sizeof(head->ordinal)); /* add the handle names */ - for (i =3D 0; i < handles; i++) - sha256_update(&sctx, auth->name[i], auth->name_size_tbl[i]); + sha256_update(&sctx, auth->name, auth->name_size); if (offset_s !=3D tpm_buf_length(buf)) sha256_update(&sctx, &buf->data[offset_s], tpm_buf_length(buf) - offset_s); --=20 2.39.5