-
Notifications
You must be signed in to change notification settings - Fork 803
Handle reader limits for SC Card unwrap operations - Fixes #2514 #2682
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
Conversation
frankmorgner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please check the compiler warnings from CI
card-sc-hsm.c:852:9: error: variable 'sent' set but not used [-Werror,-Wunused-but-set-variable]
|
I see. Will fix the build issues. |
|
@frankmorgner note that the build fails using gcc 12. So I needed to configure using Hold on, I may need a few hours to have the build fixed. |
|
@frankmorgner the following change did the trick for me However, this change has nothing to do with the PR at hand. You should perhaps deal with it elsewhere or correct the type punning in |
|
Strictly speaking, this warning relates to some undefined behavior. Please use this patch: diff --git a/src/sm/sm-eac.c b/src/sm/sm-eac.c
index 56acdf21..2058e8b6 100644
--- a/src/sm/sm-eac.c
+++ b/src/sm/sm-eac.c
@@ -2223,9 +2223,11 @@ eac_sm_pre_transmit(sc_card_t *card, const struct iso_sm_ctx *ctx,
r = SC_ERROR_OUT_OF_MEMORY;
goto err;
}
+ unsigned char *p = (unsigned char *) eacsmctx->auxiliary_data->data;
eacsmctx->auxiliary_data->length = i2d_ASN1_AUXILIARY_DATA(
msesetat->auxiliary_data,
- (unsigned char **) &eacsmctx->auxiliary_data->data);
+ &p);
+ eacsmctx->auxiliary_data->data = (char *) p;
if ((int) eacsmctx->auxiliary_data->length < 0) {
sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Error encoding auxiliary data.");
ssl_error(card->ctx);Note that there should be some more cases of this in |
|
There is also a memory leak here OpenSC/src/libopensc/card-sc-hsm.c Line 1728 in d21b6ab
|
Interesting that it occurs here, because the code in question ( |
Sure that you pointed to the correct line in the code? |
|
Indeed... this may fix the problem: diff --git a/src/tests/fuzzing/fuzz_pkcs15_decode.c b/src/tests/fuzzing/fuzz_pkcs15_decode.c
index a83c719cb..e5758ba4d 100644
--- a/src/tests/fuzzing/fuzz_pkcs15_decode.c
+++ b/src/tests/fuzzing/fuzz_pkcs15_decode.c
@@ -108,9 +108,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
sc_pkcs15_parse_unusedspace(buf, buf_len, p15card);
- sc_pkcs15_card_free(p15card);
-
err:
+ sc_pkcs15_card_free(p15card);
sc_disconnect_card(card);
sc_release_context(ctx);
return 0;
diff --git a/src/tests/fuzzing/fuzz_pkcs15_encode.c b/src/tests/fuzzing/fuzz_pkcs15_encode.c
index eb3436dae..a10ecf564 100644
--- a/src/tests/fuzzing/fuzz_pkcs15_encode.c
+++ b/src/tests/fuzzing/fuzz_pkcs15_encode.c
@@ -80,8 +80,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
sc_pkcs15_encode_unusedspace(ctx, p15card, &unused_space, &unused_space_len);
free(unused_space);
- sc_pkcs15_card_free(p15card);
err:
+ sc_pkcs15_card_free(p15card);
sc_disconnect_card(card);
sc_release_context(ctx); |
bdb0068 to
8b91975
Compare
|
@frankmorgner rebased, squashed. Hopefully it is now ready for review. Let's see what the CI checks tell us. |
|
appveyor job needs a restart |
|
@frankmorgner Hm... Probably this one hits: Lines 325 to 335 in f2497d9
It seems that the initialization fails straight away while fuzzing: Line 358 in f2497d9
The driver allocates some private data OpenSC/src/libopensc/card-sc-hsm.c Line 1773 in f2497d9
which is never Lines 398 to 402 in f2497d9
because the internal data is only OpenSC/src/libopensc/card-sc-hsm.c Lines 1880 to 1896 in f2497d9
That is to say, probably Line 402 in f2497d9
But I cannot tell if this change would have significant negative impact on the other driver implementations. |
|
I simply gave it a try with d868efb |
In principle, this change is a good idea. However, sc_disconnect_card then requires some more caution. For example, |
Indeed. Alas, this would also mean refactoring some of the other drivers' OpenSC/src/libopensc/card-iasecc.c Lines 1520 to 1521 in f2497d9
(see last fuzzer error) To lock and limit the scope of this PR I will try to find a solution within |
agreed, thank you |
|
@CardContact Please review this PR. |
Jakuje
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly nits. Please, squash the fixup and revert commits to have clean commit series before merging.
Ok. Probably we should add a pre-commit linter that enforces the expected code format. Usually, I go for https://pre-commit.com/. Maybe this in combination with https://github.com/pocc/pre-commit-hooks is an option here. |
f834236 to
a5eb1bc
Compare
|
@Jakuje squashed / force pushed again. |
It is a problem that we are not on the same page what would be the "correct" format and configuration to achieve it, see #2017. I would be all for something like this as soon as we will have the final .clang-format to use. |
aca5f0a to
be2baf0
Compare
|
Rebased to 20899a1, force-pushed. |
|
Thanks! |
Fixes #2514
Using reader with a card: REINER SCT cyberJack RFID komfort (4639352370) 00 00
SmartCard-HSM version 3.4
Checklist