Compare commits

...

10 Commits

Author SHA1 Message Date
openeuler-ci-bot
9651647313
!61 [sync] PR-55: fix CVE-2024-29040
From: @openeuler-sync-bot 
Reviewed-by: @zhujianwei001 
Signed-off-by: @zhujianwei001
2024-05-10 06:49:04 +00:00
gengqihu
4c9130d9e3 fix CVE-2024-29040
(cherry picked from commit 0463271db91855b7221905153f8e2d5c3930cf0a)
2024-05-10 10:18:22 +08:00
openeuler-ci-bot
182f07e98f
!42 【轻量级 PR】:在安装阶段创建tss用户
From: @jinlun123123 
Reviewed-by: @huangzq6 
Signed-off-by: @huangzq6
2023-12-14 03:06:43 +00:00
jinlun
a71c9f90bd
在安装阶段创建tss用户
https://gitee.com/src-openEuler/tpm2-tss/issues/I8O8HJ

Signed-off-by: jinlun <jinlun@huawei.com>
2023-12-14 01:46:38 +00:00
openeuler-ci-bot
44e111a82b
!35 [sync] PR-33: 修复CVE-2023-22745
From: @openeuler-sync-bot 
Reviewed-by: @huangzq6 
Signed-off-by: @huangzq6
2023-02-03 06:35:45 +00:00
huangzq6
d99d1ec29c fix CVE-2023-22745
(cherry picked from commit 6dad5928663c22d571ecc4205c7a1a3c28962b09)
2023-02-03 11:21:18 +08:00
openeuler-ci-bot
f5c0582f05
!23 [sync] PR-22: Rebuild for new release number
From: @openeuler-sync-bot 
Reviewed-by: @zhujianwei001 
Signed-off-by: @zhujianwei001
2022-12-14 03:58:49 +00:00
jinlun
de28eaccdc Rebuild for new release number
Signed-off-by: jinlun <jinlun@huawei.com>
(cherry picked from commit 5f0054e6b0d2f0bea74c41610e6099e7bf942af4)
2022-12-12 15:13:36 +08:00
openeuler-ci-bot
51693cdc4f !20 update version to 3.1.0
From: @panxh_purple
Reviewed-by: @zhujianwei001
Signed-off-by: @zhujianwei001
2021-12-06 03:54:53 +00:00
panxiaohe
f7d1bb0996 update version to 3.1.0 2021-12-01 16:57:25 +08:00
5 changed files with 297 additions and 3 deletions

View File

@ -0,0 +1,139 @@
From 306490c8d848c367faa2d9df81f5e69dab46ffb5 Mon Sep 17 00:00:00 2001
From: William Roberts <william.c.roberts@intel.com>
Date: Thu, 19 Jan 2023 11:53:06 -0600
Subject: [PATCH] tss2_rc: ensure layer number is in bounds
The layer handler array was defined as 255, the max number of uint8,
which is the size of the layer field, however valid values are 0-255
allowing for 256 possibilities and thus the array was off by one and
needed to be sized to 256 entries. Update the size and add tests.
Note: previous implementations incorrectly dropped bits on unknown error
output, ie TSS2_RC of 0xFFFFFF should yeild a string of 255:0xFFFFFF,
but earlier implementations returned 255:0xFFFF, dropping the middle
bits, this patch fixes that.
Fixes: CVE-2023-22745
Signed-off-by: William Roberts <william.c.roberts@intel.com>
---
src/tss2-rc/tss2_rc.c | 31 +++++++++++++++++++++----------
test/unit/test_tss2_rc.c | 21 ++++++++++++++++++++-
2 files changed, 41 insertions(+), 11 deletions(-)
diff --git a/src/tss2-rc/tss2_rc.c b/src/tss2-rc/tss2_rc.c
index 15ced56..4e14659 100644
--- a/src/tss2-rc/tss2_rc.c
+++ b/src/tss2-rc/tss2_rc.c
@@ -1,5 +1,8 @@
/* SPDX-License-Identifier: BSD-2-Clause */
-
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include <assert.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
@@ -834,7 +837,7 @@ tss_err_handler (TSS2_RC rc)
static struct {
char name[TSS2_ERR_LAYER_NAME_MAX];
TSS2_RC_HANDLER handler;
-} layer_handler[TPM2_ERROR_TSS2_RC_LAYER_COUNT] = {
+} layer_handler[TPM2_ERROR_TSS2_RC_LAYER_COUNT + 1] = {
ADD_HANDLER("tpm" , tpm2_ehandler),
ADD_NULL_HANDLER, /* layer 1 is unused */
ADD_NULL_HANDLER, /* layer 2 is unused */
@@ -869,7 +872,7 @@ unknown_layer_handler(TSS2_RC rc)
static __thread char buf[32];
clearbuf(buf);
- catbuf(buf, "0x%X", tpm2_error_get(rc));
+ catbuf(buf, "0x%X", rc);
return buf;
}
@@ -966,19 +969,27 @@ Tss2_RC_Decode(TSS2_RC rc)
catbuf(buf, "%u:", layer);
}
- handler = !handler ? unknown_layer_handler : handler;
-
/*
* Handlers only need the error bits. This way they don't
* need to concern themselves with masking off the layer
* bits or anything else.
*/
- UINT16 err_bits = tpm2_error_get(rc);
- const char *e = err_bits ? handler(err_bits) : "success";
- if (e) {
- catbuf(buf, "%s", e);
+ if (handler) {
+ UINT16 err_bits = tpm2_error_get(rc);
+ const char *e = err_bits ? handler(err_bits) : "success";
+ if (e) {
+ catbuf(buf, "%s", e);
+ } else {
+ catbuf(buf, "0x%X", err_bits);
+ }
} else {
- catbuf(buf, "0x%X", err_bits);
+ /*
+ * we don't want to drop any bits if we don't know what to do with it
+ * so drop the layer byte since we we already have that.
+ */
+ const char *e = unknown_layer_handler(rc >> 8);
+ assert(e);
+ catbuf(buf, "%s", e);
}
return buf;
diff --git a/test/unit/test_tss2_rc.c b/test/unit/test_tss2_rc.c
index f4249b7..6d8428b 100644
--- a/test/unit/test_tss2_rc.c
+++ b/test/unit/test_tss2_rc.c
@@ -199,7 +199,7 @@ test_custom_handler(void **state)
* Test an unknown layer
*/
e = Tss2_RC_Decode(rc);
- assert_string_equal(e, "1:0x2A");
+ assert_string_equal(e, "1:0x100");
}
static void
@@ -282,6 +282,23 @@ test_tcti(void **state)
assert_string_equal(e, "tcti:Fails to connect to next lower layer");
}
+static void
+test_all_FFs(void **state)
+{
+ (void) state;
+
+ const char *e = Tss2_RC_Decode(0xFFFFFFFF);
+ assert_string_equal(e, "255:0xFFFFFF");
+}
+
+static void
+test_all_FFs_set_handler(void **state)
+{
+ (void) state;
+ Tss2_RC_SetHandler(0xFF, "garbage", custom_err_handler);
+ Tss2_RC_SetHandler(0xFF, NULL, NULL);
+}
+
/* link required symbol, but tpm2_tool.c declares it AND main, which
* we have a main below for cmocka tests.
*/
@@ -313,6 +330,8 @@ main(int argc, char* argv[])
cmocka_unit_test(test_esys),
cmocka_unit_test(test_mu),
cmocka_unit_test(test_tcti),
+ cmocka_unit_test(test_all_FFs),
+ cmocka_unit_test(test_all_FFs_set_handler)
};
return cmocka_run_group_tests(tests, NULL, NULL);
--
2.27.0

View File

@ -0,0 +1,112 @@
From 710cd0b6adf3a063f34a8e92da46df7a107d9a99 Mon Sep 17 00:00:00 2001
From: Juergen Repp <juergen_repp@web.de>
Date: Tue, 31 Oct 2023 11:08:41 +0100
Subject: [PATCH] FAPI: Fix check of magic number in verify quote.
After deserializing the quote info it was not checked whether
the magic number in the attest is equal TPM2_GENERATED_VALUE.
So an malicious attacker could generate arbitrary quote data
which was not detected by Fapi_VerifyQuote.
Now the number magic number is checket in verify quote and also
in the deserialization of TPM2_GENERATED.
The check is also added to the Unmarshal function for TPMS_ATTEST.
Fixes: CVE-2024-29040
Signed-off-by: Juergen Repp <juergen_repp@web.de>
Signed-off-by: Andreas Fuchs <andreas.fuchs@infineon.com>
---
src/tss2-fapi/api/Fapi_VerifyQuote.c | 5 +++++
src/tss2-fapi/tpm_json_deserialize.c | 11 +++++++++--
src/tss2-mu/tpms-types.c | 23 ++++++++++++++++++++++-
3 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/src/tss2-fapi/api/Fapi_VerifyQuote.c b/src/tss2-fapi/api/Fapi_VerifyQuote.c
index 8a0e119c..50474c6b 100644
--- a/src/tss2-fapi/api/Fapi_VerifyQuote.c
+++ b/src/tss2-fapi/api/Fapi_VerifyQuote.c
@@ -289,6 +289,11 @@ Fapi_VerifyQuote_Finish(
&command->fapi_quote_info);
goto_if_error(r, "Get quote info.", error_cleanup);
+ if (command->fapi_quote_info.attest.magic != TPM2_GENERATED_VALUE) {
+ goto_error(r, TSS2_FAPI_RC_SIGNATURE_VERIFICATION_FAILED,
+ "Attest without TPM2 generated value", error_cleanup);
+ }
+
/* Verify the signature over the attest2b structure. */
r = ifapi_verify_signature_quote(&key_object,
command->signature,
diff --git a/src/tss2-fapi/tpm_json_deserialize.c b/src/tss2-fapi/tpm_json_deserialize.c
index 4c45458a..1b27a83f 100644
--- a/src/tss2-fapi/tpm_json_deserialize.c
+++ b/src/tss2-fapi/tpm_json_deserialize.c
@@ -698,6 +698,7 @@ ifapi_json_TPM2_GENERATED_deserialize(json_object *jso, TPM2_GENERATED *out)
const char *s = json_object_get_string(jso);
const char *str = strip_prefix(s, "TPM_", "TPM2_", "GENERATED_", NULL);
LOG_TRACE("called for %s parsing %s", s, str);
+ TSS2_RC r;
if (str) {
for (size_t i = 0; i < sizeof(tab) / sizeof(tab[0]); i++) {
@@ -707,8 +708,14 @@ ifapi_json_TPM2_GENERATED_deserialize(json_object *jso, TPM2_GENERATED *out)
}
}
}
-
- return ifapi_json_UINT32_deserialize(jso, out);
+ r = ifapi_json_UINT32_deserialize(jso, out);
+ return_if_error(r, "Could not deserialize UINT32");
+ if (*out != TPM2_GENERATED_VALUE) {
+ return_error2(TSS2_FAPI_RC_BAD_VALUE,
+ "Value %x not equal TPM self generated value %x",
+ *out, TPM2_GENERATED_VALUE);
+ }
+ return TSS2_RC_SUCCESS;
}
/** Deserialize a TPM2_ALG_ID json object.
diff --git a/src/tss2-mu/tpms-types.c b/src/tss2-mu/tpms-types.c
index 3ad72520..56aca0c3 100644
--- a/src/tss2-mu/tpms-types.c
+++ b/src/tss2-mu/tpms-types.c
@@ -22,6 +22,27 @@
#define VAL
#define TAB_SIZE(tab) (sizeof(tab) / sizeof(tab[0]))
+static TSS2_RC
+TPM2_GENERATED_Unmarshal(
+ uint8_t const buffer[],
+ size_t buffer_size,
+ size_t *offset,
+ TPM2_GENERATED *magic)
+{
+ TPM2_GENERATED mymagic = 0;
+ TSS2_RC rc = Tss2_MU_UINT32_Unmarshal(buffer, buffer_size, offset, &mymagic);
+ if (rc != TSS2_RC_SUCCESS) {
+ return rc;
+ }
+ if (mymagic != TPM2_GENERATED_VALUE) {
+ LOG_ERROR("Bad magic in tpms_attest");
+ return TSS2_SYS_RC_BAD_VALUE;
+ }
+ if (magic != NULL)
+ *magic = mymagic;
+ return TSS2_RC_SUCCESS;
+}
+
#define TPMS_PCR_MARSHAL(type, firstFieldMarshal) \
TSS2_RC \
Tss2_MU_##type##_Marshal(const type *src, uint8_t buffer[], \
@@ -1219,7 +1240,7 @@ TPMS_MARSHAL_7_U(TPMS_ATTEST,
attested, ADDR, Tss2_MU_TPMU_ATTEST_Marshal)
TPMS_UNMARSHAL_7_U(TPMS_ATTEST,
- magic, Tss2_MU_UINT32_Unmarshal,
+ magic, TPM2_GENERATED_Unmarshal,
type, Tss2_MU_TPM2_ST_Unmarshal,
qualifiedSigner, Tss2_MU_TPM2B_NAME_Unmarshal,
extraData, Tss2_MU_TPM2B_DATA_Unmarshal,
--
2.33.0

Binary file not shown.

BIN
tpm2-tss-3.1.0.tar.gz Normal file

Binary file not shown.

View File

@ -1,12 +1,16 @@
Name: tpm2-tss
Version: 3.0.3
Release: 1
Version: 3.1.0
Release: 5
Summary: TPM2.0 Software Stack
License: BSD and TCGL
License: BSD
URL: https://github.com/tpm2-software/tpm2-tss
Source0: https://github.com/tpm2-software/tpm2-tss/releases/download/%{version}/%{name}-%{version}.tar.gz
Patch1: backport-CVE-2023-22745.patch
Patch2: backport-CVE-2024-29040-FAPI-Fix-check-of-magic-.patch
BuildRequires: gcc-c++ autoconf-archive libtool pkgconfig systemd libgcrypt-devel openssl-devel doxygen json-c-devel libcurl-devel
Requires(pre): shadow
%description
tpm2-tss is a software stack supporting Trusted Platform Module(TPM) 2.0 system
@ -40,6 +44,15 @@ rm -rf %{buildroot}
make check
%pre
getent group tss >/dev/null || groupadd -f -g 59 -r tss
if ! getent passwd tss >/dev/null ; then
if ! getent passwd 59 >/dev/null ; then
useradd -r -u 59 -g tss -d /dev/null -s /sbin/nologin -c "Account used for TPM access" tss
else
useradd -r -g tss -d /dev/null -s /sbin/nologin -c "Account used for TPM access" tss
fi
fi
exit 0
%preun
@ -69,6 +82,36 @@ make check
%{_mandir}/man*/*
%changelog
* Thu May 9 2024 gengqihu <gengqihu2@h-partners.com> - 3.1.0-5
- Type:CVE
- ID:NA
- SUG:NA
- DESC:fix CVE-2024-29040
* Thu Dec 14 2023 jinlun <jinlun@huawei.com> - 3.1.0-4
- Type:bugfix
- CVE:NA
- SUG:NA
- DESC:Specifies the owner group 59 of a user.
* Tue Jan 31 2023 huangzq6 <huangzhenqiang2@huawei.com> - 3.1.0-3
- Type:CVE
- ID:NA
- SUG:NA
- DESC:fix CVE-2023-22745
* Tue Oct 18 2022 jinlun <jinlun@huawei.com> - 3.1.0-2
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:Rebuild for new release number
* Wed Dec 1 2021 panxiaohe <panxiaohe@huawei.com> - 3.1.0-1
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:update version to 3.1.0
* Mon Jan 25 2021 panxiaohe <panxiaohe@huawe.com> - 3.0.3-1
- Type:enhancement
- ID:NA