From 05da0b583098b2f3f1cb437cfc6f59fa8f2acc1d Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Tue, 15 Sep 2020 11:38:17 -0600 Subject: [PATCH] Fix two source over-reads detected by gcc-11 --- tpm2-pkcs11-gcc11.patch | 30 ++++++++++++++++++++++++++++++ tpm2-pkcs11.spec | 6 +++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 tpm2-pkcs11-gcc11.patch diff --git a/tpm2-pkcs11-gcc11.patch b/tpm2-pkcs11-gcc11.patch new file mode 100644 index 0000000..92fb2f7 --- /dev/null +++ b/tpm2-pkcs11-gcc11.patch @@ -0,0 +1,30 @@ +diff --git a/src/lib/slot.c b/src/lib/slot.c +index b3c7c82..f0a4f2e 100644 +--- a/src/lib/slot.c ++++ b/src/lib/slot.c +@@ -120,7 +120,9 @@ CK_RV slot_get_info (CK_SLOT_ID slot_id, CK_SLOT_INFO *info) { + } + + str_padded_copy(info->manufacturerID, token_info.manufacturerID, sizeof(info->manufacturerID)); +- str_padded_copy(info->slotDescription, token_info.label, sizeof(info->slotDescription)); ++ size_t to_copy = sizeof (token_info.label); ++ to_copy = (to_copy > sizeof (info->slotDescription)) ? sizeof (info->slotDescription) : to_copy; ++ str_padded_copy(info->slotDescription, token_info.label, to_copy); + + info->hardwareVersion = token_info.hardwareVersion; + info->firmwareVersion = token_info.firmwareVersion; +diff --git a/src/lib/tpm.c b/src/lib/tpm.c +index 90fb3c3..1bce3ac 100644 +--- a/src/lib/tpm.c ++++ b/src/lib/tpm.c +@@ -732,7 +732,9 @@ CK_RV tpm_get_token_info (tpm_ctx *ctx, CK_TOKEN_INFO *info) { + unsigned char manufacturerID[sizeof(UINT32)+1] = {0}; // 4 bytes + '\0' as temp storage + UINT32 manufacturer = ntohl(tpmProperties[TPM2_PT_MANUFACTURER - TPM2_PT_FIXED].value); + memcpy(manufacturerID, (unsigned char*) &manufacturer, sizeof(uint32_t)); +- str_padded_copy(info->manufacturerID, manufacturerID, sizeof(info->manufacturerID)); ++ size_t to_copy = sizeof (manufacturerID); ++ to_copy = (to_copy > sizeof (info->manufacturerID)) ? sizeof (info->manufacturerID) : to_copy; ++ str_padded_copy(info->manufacturerID, manufacturerID, to_copy); + + // Map human readable Manufacturer String, if available, + // otherwise 4 byte ID was already padded and will be used. diff --git a/tpm2-pkcs11.spec b/tpm2-pkcs11.spec index 8e0c347..b3c0ba6 100644 --- a/tpm2-pkcs11.spec +++ b/tpm2-pkcs11.spec @@ -7,7 +7,7 @@ Name: tpm2-pkcs11 Version: 1.4.0 -Release: 1%{?candidate:.%{candidate}}%{?dist} +Release: 2%{?candidate:.%{candidate}}%{?dist} Summary: PKCS#11 interface for TPM 2.0 hardware License: BSD @@ -16,6 +16,7 @@ Source0: https://github.com/tpm2-software/%{name}/releases/download/%{version}%{ Source1: https://github.com/tpm2-software/%{name}/releases/download/%{version}%{?candidate:-%{candidate}}/%{name}-%{version}%{?candidate:-%{candidate}}.tar.gz.asc # William Roberts (Bill Roberts) key from pgp.mit.edu Source2: gpgkey-8E1F50C1.gpg +Patch0: tpm2-pkcs11-gcc11.patch BuildRequires: gcc BuildRequires: make @@ -99,6 +100,9 @@ cd tools %changelog +* Tue Sep 15 2020 Jeff Law - 1.4.0-2 +- Fix two source over-reads detected by gcc-11 + * Mon Aug 24 2020 Peter Robinson - 1.4.0-1 - Update to 1.4.0