Skip to content

Conversation

@ethangraham2001
Copy link
Owner

@ethangraham2001 ethangraham2001 commented Jul 3, 2025

Description (WIP)

We want to be able to express domain constraint programmatically via macro as we do for exposing kernel fuzz tests with the framework.

This PR, for now, introduces several new macros that define constraint structures with static types. These should be readable in the .kftf.constraints section of the VM Linux binary (see PR ethangraham2001/syzkaller#2 on the syzkaller fork). The idea is to also expose these via the debugfs in one or more entries that can be parsed by fuzzing engines.

This PR also introduces a few macros for defining annotations - annotations allow us to annotate fields with more information in a way that isn't reflected in a type. For example, a const char * field may be an array of bytes, or may be a logical string that is null-terminated. We thus allow the FUZZ_TEST author to annotate fields in the input structures. We currently support

  • Length annotation: one field represents the length of another
  • String annotation: the field is a string

Any validation of such annotations is left up to the fuzzing engine. For example a length field should be a numerical type, and a string should have base type (const) char *.

Ethan Graham added 3 commits July 4, 2025 08:34
@ethangraham2001 ethangraham2001 force-pushed the kftf_domain_constraints branch from f988367 to 581f240 Compare July 6, 2025 18:12
static int write_input_cb_common(struct file *filp, const char __user *buf,
size_t len, loff_t *off, void *arg,
size_t arg_size)
// XXX: why can't we use without the attribute unused anymore??

Choose a reason for hiding this comment

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

Maybe because this function is inlined at every callsite?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ah could be!

*
* Note: if this struct is not a multiple of 64 bytes, everything breaks and
* we get corrupted data and occasional kernel panics. To avoid this happening,
* we enforce 64 Byte alignment and statically assert that this struct has size

Choose a reason for hiding this comment

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

I am afraid we'll have bigger structs in the future (e.g. to list a set of possible values).
Why does everything break?
Maybe we can put the struct length at its beginning?

"struct kftf_constraint should have size 64");

/**
* __KFTF_DEFINE_CONSTRAINT - defines a fuzz test constraint linked to a given

Choose a reason for hiding this comment

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

Nit: you normally don't write doc comments for internal macros/functions.

Ethan Graham added 2 commits July 8, 2025 18:27
strings) and a field being the length of another.
There was not any mechanism in place in the KFuzzTest for distinguishing
between value pointers and array pointers in fuzz test inputs. This
information is difficult to parse without additional semantic
information on the context.

We introduce a new KFTF_ANNOTATE_ARRAY macro that annotates a field in a
KFuzzTest input struct as an array, removing this ambiguity.
@ethangraham2001 ethangraham2001 force-pushed the kftf_domain_constraints branch from 4a7f93e to 8e1f787 Compare July 18, 2025 10:42
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