Skip to content
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

Term with payloads #280

Draft
wants to merge 204 commits into
base: main
Choose a base branch
from
Draft

Term with payloads #280

wants to merge 204 commits into from

Conversation

LCBH
Copy link
Contributor

@LCBH LCBH commented Sep 12, 2023

See [#279 ]
One approach to integrate bit-level mutations (like HAVOC) to tlspuffin and DY fuzzing in general is as follows:

  1. Have a mutation make_bitstring that:
    a. randomly choose a sub-term t in a recipe in the current trace (similar to what is done in this clone,
    b. evaluate it to a bitstring b,
    c. associate a mutable version of b, amenable to bit-level mutations, to t in fields payload and initial_payload of t.
    The idea is that, from now on, future evaluation of t will use payload instead of using the evaluation of t and bit-level mutations can mutate in-place the field payload.
  2. Have bit-level mutations like HAVOC operating on all payloads of all sub-terms of all recipes in the trace.
  3. When evaluating the trace and one of its recipe t:
    a. evaluate it to b_t as currently done.
    b. for each sub-term t' of t having a payload b (hence make_message has been used on t'), do the following:
    • replace t.initial_payload that must be found in b_t by t.payload (even if the two do not have the same size)
    • [Optional] if multiple t.initial_payload can be found at different locations, find the right location corresponding to t'. (One option is to evaluate the first child of t that has t' as descendant, evaluate this child as a bitstring, and find b_t in it. If there is only one matching location, then we win, otherwise, we recursively do the same on this child (instead of t).
  4. Send the modified b_t to the suitable agent.

Pros:

  • compared to [Constant bitstrings in atoms (for bit-level fuzzing) -- Attempt with Codec::read_bytes #278], this approach allows to accept any kind of bit-level mutations. Approaches based on re-interpreting the mutated bit-strings in the Mapper internal structure (here rustls) rejects a lot of mutations that make this re-interpretation/parsing fail. Problem 1: We are not really interested in fuzzing the Mapper: a mutation that may be gracefully rejected by the Mapper might crash the PUT's "Mapper"/parsing routines. Problem 2: even if we used the PUT as Mapper, the context of evaluation in our fuzzer will not be the same as the one of the agent we fuzz, hence some bugs may be missed because of we reject a mutation on the fuzzer side (parsing fails) but this would still crash the PUT.
    --> This approach does not suffer from those problems, any bit-level mutation will go through.
  • we are able to fuzz any sub-terms with this approach. On the contrary, approaches based on fuzzing rustls payloads (like this clone) are only able to fuzz certain parts of messages (such as certificates). Problem 3: structures of messages (header, length, etc.) cannot be fuzzed this way.

Cons:

  • quite cumbersome and hacky
  • tracking down which precise location of the bitstring b to replace is non-trivial (but possible)
  • we need to re-architecture the interface tlspuffin-puffin since no bitstring-access to the PUT agents are exposed (for sending bitstring), only message-level-access to the PUT is exposed
  • maybe too inefficient once we have a lot of sub-terms with payloads (?)

Question: some HAVOC sub-mutations are more expressive if we give them the concatenation of all payloads of all sub-terms (e.g., the ones that swap around some parts of the bitstrings). We may want do to that but reconstructing the new mutated payloads after having applied the mutation is non-trivial.

LCBH and others added 30 commits September 11, 2023 13:48
TODOs:
 - correctly evaluate any sub-term in MakeMessage
 - modify evaluate for terms and replace found payloads_0 by payloads
…e sup-terms of non-symbolic, fix many bugs, test to investigate mutation failures

TODO: clear understanding of which mutations and replacement can fail
LCBH added 10 commits April 11, 2024 13:18
find_relative_node now returns `shift_ancestor_to_search:usize`: this can be non-zero when p is not a sibling but a sibling of an ancestor of to_search.
It then corresponds to the position of `to_search` relatively to the evaluation of this ancestor.
This can happen for example for append(f, fn_support_group_extension(to_search)) when relative node is f and fn_support_group_extension add some headers in front of to_search. shift_ancestor_to_search will be the length of this header.
However, we end up with inconsistent payload replacements. Example: fn_true -> MakeMessage -> BitFlip -> MakeMessage with payload_0 = 0 instead of 1.
…t-in argument like `HELLO_RETRY_REQUEST_RANDOM` which made replace_payload failed!
…n the HandShakeMewssage) + Fix mutation tests
LCBH added 18 commits April 17, 2024 17:11
… encoding, thus failing payloads replacements. Fix most of them. This requires to add several new function symbols.
…or Payload* types (had to use a hacky new trait) add missing types.
….read.encode. Fix try_read_bytes that made this test fail.

Add custom Codec2::read for several types. Remove the identity function fn_opaque_message and use type filtering instead (adapt seeds). Disable some safety checks to explore more messages; can be enabled with `enable-guards`. Fix some offset issue with reading PayloadU8. New Codec::read for HandshakeHash.
…ions, in which case MakeMessage only applies to root messages) + better experiment folder formatting
@maxammann maxammann self-requested a review May 3, 2024 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci:full Run full CI checks on labeled PR enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants