Skip to content

Conversation

@xhanulik
Copy link
Member

@xhanulik xhanulik commented Mar 9, 2022

This PR adds fuzzers for encoding functions for PKCS#15 objects and generic sc_*() functions.

  • fuzz_pkcs15_encode iterates over objects on p15card and calls corresponding sc_pkcs15_encode_*_entry().
  • fuzz_card calls some functions from libopensc/sec.c and libopensc/card.c that are not covered according to OSS-Fuzz coverage reports.

Also, there are some changes in the fuzz_pkcs15_decode. The setting of algorithms for the sc_pkcs15_decode_pubkey() in a cycle extends testing to other algorithms besides RSA. Some of the sc_pkcs15_decode_*_entry() internally use p15card->app - these paths were not covered, since p15card was not initialized via sc_pkcs15_bind(). That is fixed with the usage of the reader from fuzz_pkcs15_reader.

After local run, fuzz_card encounter asserts in muscle.c - these are exchanged for explicit checking the arguments.

Checklist
  • New files have a LGPL 2.1 license statement

@xhanulik xhanulik force-pushed the fuzzer branch 4 times, most recently from 76464ed to ad9cec5 Compare March 11, 2022 20:42
@Jakuje
Copy link
Member

Jakuje commented Mar 21, 2022

@frankmorgner can you check this PR if there is something you would like to do differently before I will merge it (after resolving the conflict indeed)?

`sc_pkcs15_decode_pubkey()` uses `key->algorithm` to decide next steps.
Binding with p15card can lead to new paths
in code during fuzzing (decode functions use p15card->app).
Each decoding function gets its own data buffer - data generation
 adapts to each function.
Copy link
Member

@frankmorgner frankmorgner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the ideas for integrating the encoding/decoding functions with the fuzzing input, good job!

Some minor things could be improved, though - please see the inline comments.

Fuzz target uses the first two bytes of fuzzing input as the length
for a buffer that is supplied to the tested function.
The rest is set as data for the reader.
@xhanulik
Copy link
Member Author

With the change mentioned in #2520 (comment), the structure of fuzzing input has changed. I will create and add some suitable corpus for fuzz_pkcs15_decode (at least some that can cover connecting of the card) as soon as possible.

@Jakuje Jakuje requested a review from frankmorgner March 29, 2022 11:50
@Jakuje
Copy link
Member

Jakuje commented Apr 5, 2022

I like the ideas for integrating the encoding/decoding functions with the fuzzing input, good job!

Some minor things could be improved, though - please see the inline comments.

@frankmorgner can you check this PR if there is something to fix from your point of view or are we ready to merge this?

@Jakuje Jakuje merged commit b35993d into OpenSC:master Apr 12, 2022
@xhanulik xhanulik deleted the fuzzer branch August 10, 2022 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants