-
-
Notifications
You must be signed in to change notification settings - Fork 18.2k
tpm2-tss: fix CVE-2023-22745 #240750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
RaitoBezarius
merged 1 commit into
NixOS:staging-23.05
from
baloo:baloo/release-23.05/tpm2-tss/CVE-2023-22745
Jul 1, 2023
Merged
tpm2-tss: fix CVE-2023-22745 #240750
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
pkgs/development/libraries/tpm2-tss/CVE-2023-22745.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| diff --git a/src/tss2-rc/tss2_rc.c b/src/tss2-rc/tss2_rc.c | ||
| index 15ced567..4e146593 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 f4249b7b..c297298d 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.