Skip to content
This repository was archived by the owner on Mar 16, 2026. It is now read-only.

move kafl_* script into a single package entrypoint with subcommands#22

Merged
Wenzel merged 30 commits intoIntelLabs:masterfrom
Wenzel:refactor/unique_entrypoint
Nov 29, 2022
Merged

move kafl_* script into a single package entrypoint with subcommands#22
Wenzel merged 30 commits intoIntelLabs:masterfrom
Wenzel:refactor/unique_entrypoint

Conversation

@Wenzel
Copy link
Copy Markdown
Contributor

@Wenzel Wenzel commented Oct 26, 2022

This is the beginning of a PR to fix #13

new

  • __main__.py to make the kafl_fuzzer package executable (python -m kafl_fuzzer)
  • scripts moved into the kafl_fuzzer package, refactoring later on
  • subcommands added in config.py
  • using the set_defaults to automatically associate and call each subcommand's entrypoint.

in cmdline.py:
image
image

  • add a way to associate command line args <-> config file options by replacing confuse with dynaconf
    • the previous solution required to peer into the private attributes of the parser, which is not reliable long term
    • the new solution proposes to delegate the parameters validation from argparse to Dynaconf
    • the validators are placed in settings.py and associated with the dynaconf settings.
      image
    • the configuration file precedence is defined by the app_settings_files() function in settings.py, and already integrates loading the KAFL_CONFIG_FILE environment variable
  • the new unified main look like this:
    image

So the new flow looks like this:

  1. dynaconf is loading the settings files, according to the load order defined in settings.py

  2. parser.parse_args() parses the command line and returns a Namespace object

  3. this object is passed to update_from_namespac() function, defined in settings.py
    image

  4. this function will update the dynaconf settings by extracting a dict from the Namespace object and updating the settings dict.

  5. the validation step comes in, and the validate function is called. Due to bug we had to write our own validation function and manually call the Validator cast functions.
    image

  6. the subcommand entrypoint is finally called in __main__.py

TODO

  • add documentation
  • add --help
  • check subcommands standard args ( kafl {mcat,gui,plot} do not take the standard arguments. mcat takes a file, gui and plot take a workdir (as argument, not -w option) )
  • discuss how the command line should be reworked / improved, given steffen's input on the matter

@Wenzel Wenzel force-pushed the refactor/unique_entrypoint branch from b2ca52e to 574f641 Compare November 3, 2022 10:17
@Wenzel Wenzel force-pushed the refactor/unique_entrypoint branch 3 times, most recently from b193b2b to bb7dc8d Compare November 24, 2022 15:42
@Wenzel Wenzel marked this pull request as ready for review November 24, 2022 15:57
@Wenzel
Copy link
Copy Markdown
Contributor Author

Wenzel commented Nov 24, 2022

Regarding the command line changes, if we take the Fuzzing the linux kernel tutorial:

before

KAFL_CONFIG_FILE=./kafl_config.yaml kafl_fuzz.py --purge -w /dev/shm/kafl \
	--redqueen --grimoire -D --radamsa \
	--kernel linux-guest/arch/x86/boot/bzImage \
	-t 0.1 -ts 0.01 -m 512 --log-crashes -p 2

now

KAFL_CONFIG_FILE=./kafl_config.yaml kafl \
        --purge -w /dev/shm/kafl -p2 \
        fuzz \
        --redqueen --grimoire -D --radamsa --kernel linux-guest/arch/x86/boot/bzImage \
        -t 0.1 -ts 0.01 -m 512 --log-crashes
  • kafl is the program name
  • --purge -w /dev/shm/kafl -p2 are the General options (which must come before the first subcommand)
  • fuzz is the subcommand name

@Wenzel Wenzel force-pushed the refactor/unique_entrypoint branch 2 times, most recently from 3a8979e to a5d2bc6 Compare November 24, 2022 16:39
@Wenzel
Copy link
Copy Markdown
Contributor Author

Wenzel commented Nov 24, 2022

The last update added the General options on every subcommand, so overriding a general option by appending it on the cmdline is easy.

Also, I moved all the configuration default values into default_settings.yaml, so it's much more clear now where to find and update the defaults.

@il-steffen
Copy link
Copy Markdown
Contributor

When called without any arguments, I think we want to print some short usage summary:
image

Here you have some placeholders but then append all possible options at the end?
image

@il-steffen
Copy link
Copy Markdown
Contributor

il-steffen commented Nov 25, 2022

  • I don't see how to get the list of available commands. Short help should probably list them
  • kafl {mcat,gui,plot} do not take the standard arguments. mcat takes a file, gui and plot take a workdir (as argument, not -w option)

@Wenzel Wenzel force-pushed the refactor/unique_entrypoint branch 2 times, most recently from 567693d to 9aca680 Compare November 25, 2022 13:36
@Wenzel Wenzel force-pushed the refactor/unique_entrypoint branch from 9aca680 to 9ef2af6 Compare November 25, 2022 14:03
@Wenzel
Copy link
Copy Markdown
Contributor Author

Wenzel commented Nov 25, 2022

One of your conversation has mysteriously disappeared, although I received the email.

I had to resubmit when the PR changed, then saw it twice and deleted one... :-/

And regarding the fact that you can set test: and Dynaconf doesn't care, i found out that it's a limitation from the YAML parser they are using:

Ok, I suppose we can live with it for now.

[ah fuck...edited instead of quote-reply...]

@Wenzel Wenzel force-pushed the refactor/unique_entrypoint branch from 58b55d3 to 439f6a6 Compare November 25, 2022 15:16
@Wenzel Wenzel force-pushed the refactor/unique_entrypoint branch from 439f6a6 to 4e55e9e Compare November 25, 2022 16:13
Copy link
Copy Markdown
Contributor

@il-steffen il-steffen left a comment

Choose a reason for hiding this comment

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

This seems like a overly complicated fix, maybe we just keep the config.['reload']?
2bdcf01

@Wenzel Wenzel force-pushed the refactor/unique_entrypoint branch 3 times, most recently from e523384 to 5d7679a Compare November 28, 2022 12:39
@Wenzel
Copy link
Copy Markdown
Contributor Author

Wenzel commented Nov 29, 2022

@il-steffen the last update fixed the behavior of kafl plot -w /dev/shm/kafl, which now only produces stdout output.

@Wenzel Wenzel force-pushed the refactor/unique_entrypoint branch from 73bb370 to f743eb5 Compare November 29, 2022 20:14
@il-steffen il-steffen self-requested a review November 29, 2022 21:22
@il-steffen
Copy link
Copy Markdown
Contributor

Lets revert the two hacks for 'snapshot_reload' and 'kafl_work_dir'. The other things are just nitpicks, feel free to merge when ready.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Proposal: Unify kafl entrypoints

2 participants