From mboxrd@z Thu Jan 1 00:00:00 1970 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 EA244285419; Fri, 28 Nov 2025 02:54:47 +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=1764298488; cv=none; b=EMURF0qlnHr5Q1knU0u0aO1XICFVLsIdgi+pS8fzeg4QMBk49pusMwJpFAkPi6CiLX8+gabZZM3wHEhMmGsTKtJF8x4cBVvHwykX+na6iZDd7sl9ptw2H4Ed0SypVv1E4IIU+DWvR/KXPzRBMjahNbKPEX9Pmwdh0h+lccJIaw0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764298488; c=relaxed/simple; bh=P+oNiCo+pZx7vZVITxThbDwgnEp/P+7W5CTQpa8RIVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BzEcXOzKNbdb9wvzxLJ7O0iY9Mm5Vz1KEFIu3YRKJrZgTVJIoXS9o+xI7xtSriSLo4qRAc5rtg5KlstVu36V5sXTvhWysW+UUxKFav6JU/lkS1Jom0Lf37Tn+YIqEHb3wNMbnqCSStn/bN+S2egIFJvG/JIRo3SJQLXSIF/+yfI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mvl2yxEu; 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="mvl2yxEu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC6CFC4CEF8; Fri, 28 Nov 2025 02:54:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764298487; bh=P+oNiCo+pZx7vZVITxThbDwgnEp/P+7W5CTQpa8RIVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mvl2yxEuZMyiwBdvEXs0c5eSye3J8TJFalKuTQtyq6bBXFi4pn60wf8dI4ayAaBdN 5tpbvRrqtU9k9Fbfa2pVKYdM0QSOvp9RGK/vpRLXaEQSfE+DYTjwPKsoDJqjn5k4nk 4fQtkiuFlmFUOmHse/CWn2DYeK5lHonGabYfapfuvyIwCWefOXPLPR+u0UPUPy2hcb npHHx1CS6VSxzsZYVN0yIpxJp8lRJZfyZE+B/WqhD1B36YQyJVVu1b53Gwd/ARtbNd aFsHTY7lAk8vDjLHotPBGkEL/zyrrgMOhPZDIoc0pQwmavRYjnDYEsbi3qBvEPrWBx CaO3xy7aNGY9w== From: Jarkko Sakkinen To: linux-integrity@vger.kernel.org Cc: ross.philipson@oracle.com, Jonathan McDowell , Stefano Garzarella , Jarkko Sakkinen , Jonathan McDowell , Peter Huewe , Jarkko Sakkinen , Jason Gunthorpe , James Bottomley , Mimi Zohar , David Howells , Paul Moore , James Morris , "Serge E. Hallyn" , linux-kernel@vger.kernel.org, keyrings@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v9 6/8] tpm-buf: Merge TPM_BUF_BOUNDARY_ERROR and TPM_BUF_OVERFLOW Date: Fri, 28 Nov 2025 04:53:58 +0200 Message-ID: <20251128025402.4147024-7-jarkko@kernel.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20251128025402.4147024-1-jarkko@kernel.org> References: <20251128025402.4147024-1-jarkko@kernel.org> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jarkko Sakkinen Merge TPM_BUF_BOUNDARY_ERROR and TPM_BUF_OVERFLOW into TPM_BUF_INVALID, given that they are identical. The only difference are the log messages. In addition, add a missing TPM_BUF_INVALID check to tpm_buf_append_handle() following the pattern from other functions in tpm-buf.c. Signed-off-by: Jarkko Sakkinen Reviewed-by: Jonathan McDowell --- v9: - Improvde the commit message. v8: - No changes. v7: - No changes. v6: - Change short summary to something more descriptive. v5: - No changes. v4: - No changes. v3: - No changes. v2: - A new patch. --- drivers/char/tpm/tpm-buf.c | 14 ++++++++------ include/linux/tpm.h | 8 +++----- security/keys/trusted-keys/trusted_tpm2.c | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/char/tpm/tpm-buf.c b/drivers/char/tpm/tpm-buf.c index dc882fc9fa9e..69ee77400539 100644 --- a/drivers/char/tpm/tpm-buf.c +++ b/drivers/char/tpm/tpm-buf.c @@ -104,13 +104,12 @@ EXPORT_SYMBOL_GPL(tpm_buf_length); */ void tpm_buf_append(struct tpm_buf *buf, const u8 *new_data, u16 new_length) { - /* Return silently if overflow has already happened. */ - if (buf->flags & TPM_BUF_OVERFLOW) + if (buf->flags & TPM_BUF_INVALID) return; if ((buf->length + new_length) > PAGE_SIZE) { WARN(1, "tpm_buf: write overflow\n"); - buf->flags |= TPM_BUF_OVERFLOW; + buf->flags |= TPM_BUF_INVALID; return; } @@ -157,8 +156,12 @@ EXPORT_SYMBOL_GPL(tpm_buf_append_u32); */ void tpm_buf_append_handle(struct tpm_chip *chip, struct tpm_buf *buf, u32 handle) { + if (buf->flags & TPM_BUF_INVALID) + return; + if (buf->flags & TPM_BUF_TPM2B) { dev_err(&chip->dev, "Invalid buffer type (TPM2B)\n"); + buf->flags |= TPM_BUF_INVALID; return; } @@ -177,14 +180,13 @@ static void tpm_buf_read(struct tpm_buf *buf, off_t *offset, size_t count, void { off_t next_offset; - /* Return silently if overflow has already happened. */ - if (buf->flags & TPM_BUF_BOUNDARY_ERROR) + if (buf->flags & TPM_BUF_INVALID) return; next_offset = *offset + count; if (next_offset > buf->length) { WARN(1, "tpm_buf: read out of boundary\n"); - buf->flags |= TPM_BUF_BOUNDARY_ERROR; + buf->flags |= TPM_BUF_INVALID; return; } diff --git a/include/linux/tpm.h b/include/linux/tpm.h index cbd3a70c0378..2796bac2a114 100644 --- a/include/linux/tpm.h +++ b/include/linux/tpm.h @@ -369,12 +369,10 @@ struct tpm_header { } __packed; enum tpm_buf_flags { - /* the capacity exceeded: */ - TPM_BUF_OVERFLOW = BIT(0), /* TPM2B format: */ - TPM_BUF_TPM2B = BIT(1), - /* read out of boundary: */ - TPM_BUF_BOUNDARY_ERROR = BIT(2), + TPM_BUF_TPM2B = BIT(0), + /* The buffer is in invalid and unusable state: */ + TPM_BUF_INVALID = BIT(1), }; /* diff --git a/security/keys/trusted-keys/trusted_tpm2.c b/security/keys/trusted-keys/trusted_tpm2.c index 8e2d1a013c7e..8f3fc64c2399 100644 --- a/security/keys/trusted-keys/trusted_tpm2.c +++ b/security/keys/trusted-keys/trusted_tpm2.c @@ -280,7 +280,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip, /* creation PCR */ tpm_buf_append_u32(&buf, 0); - if (buf.flags & TPM_BUF_OVERFLOW) { + if (buf.flags & TPM_BUF_INVALID) { rc = -E2BIG; tpm2_end_auth_session(chip); goto out; @@ -293,7 +293,7 @@ int tpm2_seal_trusted(struct tpm_chip *chip, goto out; blob_len = tpm_buf_read_u32(&buf, &offset); - if (blob_len > MAX_BLOB_SIZE || buf.flags & TPM_BUF_BOUNDARY_ERROR) { + if (blob_len > MAX_BLOB_SIZE || buf.flags & TPM_BUF_INVALID) { rc = -E2BIG; goto out; } @@ -403,7 +403,7 @@ static int tpm2_load_cmd(struct tpm_chip *chip, tpm_buf_append(&buf, blob, blob_len); - if (buf.flags & TPM_BUF_OVERFLOW) { + if (buf.flags & TPM_BUF_INVALID) { rc = -E2BIG; tpm2_end_auth_session(chip); goto out; -- 2.52.0