Skip to content

test: fuzz the shim's annotation injection - #1195

Merged
cmainas merged 3 commits into
urunc-dev:main-pr1195from
pocopepe:feat/fuzz-shim
Nov 20, 2026
Merged

cmainas merged 3 commits into
urunc-dev:main-pr1195from
pocopepe:feat/fuzz-shim

Conversation

@pocopepe

@pocopepe pocopepe commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Description

This adds fuzzers for fetchUruncAnnotations and patchConfigJSON in the containerd shim. It also adds grepping the Fuzz targets rather than manual additions inside build.sh. Adds a new way of building the seeds from a centrailized toml file that can be updated for all the targets.

Related issues

How was this tested?

It was tested by running the fuzzer on my branch. Plus a quick make fuzz was ran, nothing broke.

LLM usage

Opus 5.5

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

@netlify

netlify Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

👷 Deploy request for urunc pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit ab23821

@cmainas cmainas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hello @pocopepe ,

thank you for the PR. There is a problem with the current design. The seeds of the two new targets get garbled on their way to ClusterFuzzLite. libFuzzer stores every input as one byte string, so addStdLibCorpusToFuzzer joins a seed's arguments together without recording where each one ends, and the fuzzer later cuts that string back into equal-sized pieces. For example, the seed {} of FuzzPatchConfigJSON ends up with config {}com.uru. Only single-[]byte targets survive the conversion.

I think it would be simpler to have each target take a single []byte and fuzz just the data: the manifest in FuzzFetchUruncAnnotations, with the media type and label fixed (OCI and Docker manifests go through the same code anyway), and the config in FuzzPatchConfigJSON. The other cases, like read failures, broken streams and non-manifest media types, would fit better in a regular table test. The seeds can then be a couple of inline JSON literals, so seeds.toml and the loader wouldn't be needed.

Please, let me know your opinion.

I have also added some inline comments.

Comment thread .clusterfuzzlite/build.sh Outdated
fuzzer=FuzzGetUnikernelConfig
compile_native_go_fuzzer_v2 github.com/urunc-dev/urunc/pkg/unikontainers "$fuzzer" "$fuzzer"
# Every Fuzz function of a test file, as <package dir>:<name>.
targets=$(grep -rHoE --include='*_test.go' '^func Fuzz[A-Za-z0-9_]+' pkg internal | sed 's|/[^/]*:func |:|' | sort -u)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It would be better to use go test list here instead of grep The current filter will match with any function that starts with Fuzz, evne helper ones which are not actual fuzzing functions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed, it now uses go test -list '^Fuzz'. I also added set -o pipefail, so a package that fails to compile can't silently drop its targets just in case.

if !maps.Equal(out.Annotations, want) {
t.Fatalf("annotations %v, want %v", out.Annotations, want)
}
// Nothing else changes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: The comment is not very accurate. Some more things change. Fields that are not recognized by the runtime-spec version that the shim uses will get dropped.

}
}
annotations := map[string]string{key1: value1, key2: value2}
if err := os.WriteFile(path, config, 0o640); err != nil { //nolint:gosec // a non-default mode, to check it is kept

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should be careful here with umask. Even if we set 0o640, umask might still change it. To enforce permissions, it is better to use chmod.

@pocopepe

Copy link
Copy Markdown
Contributor Author

Hi @cmainas, thanks for the review. I've pushed the changes along the lines you suggested. I had hit the same equal split problem before and was considering a NUL separator to split the seeds, but a single []byte with inline seeds is simpler. I kept a small fuzzseed.Add helper, libFuzzer ignores f.Add, so it writes the inline seeds to files that build.sh packs into the seed corpus, which gives each new target a starting point in ClusterFuzzLite.

@pocopepe pocopepe mentioned this pull request Nov 16, 2026
3 of 4 tasks

@cmainas cmainas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @pocopepe for the update.

I would strongly recommend to have a follow up or a PR that explains the limitations and what future fuzzing targets should keep in mind. A few examples:

  • The seeds should be added with fuzzseed.Add and not f.Add
  • Any new fuzz target should be added in the Makefile list
  • Be careful with go cache and errors from seed conversion.

Other than that, the Pr looks ok as a first step I have added a few comments, but feel free to ignore the future notes.

Comment thread .clusterfuzzlite/build.sh
# compile_native_go_fuzzer_v2 exits 0 when it cannot find the function.
test -x "$OUT/$fuzzer"

# libFuzzer ignores f.Add, so the seeds are dumped to files first.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just as a note for the future as a TODO/follow-up. Go's cache can prevent the corpus form growing. THis is not a bug now because we use mktemp for a directory, but future additions should be mindful of that. Furthermore, every seed that can not be read / parsed wlll get passed over unnoticed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Noted, I'd add it in the fuzzing doc


// Add is f.Add for a single-[]byte target, the only shape libFuzzer keeps intact. When
// URUNC_SEED_DIR is set it also writes the seed there in the "go test fuzz v1" format.
func Add(f *testing.F, seed []byte) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: We should mark this as a helper function so any errors (e.g. when we write the file), point to the actual function.

Comment thread internal/fuzzseed/fuzzseed.go Outdated
}
file := fmt.Sprintf("go test fuzz v1\n[]byte(%q)\n", seed)
name := fmt.Sprintf("%x", sha256.Sum256([]byte(file)))
if err := os.WriteFile(filepath.Join(dir, name), []byte(file), 0o600); err != nil { //nolint:gosec // name is a hash

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Another linter issue here is that the name comes from an environment variable.

Comment on lines +44 to +45
wantErr := json.Unmarshal(manifest, &parsed) != nil
if (err != nil) != wantErr || (err != nil && got != nil) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's simplify these lines.

t.Fatal(err)
}
if entries, _ := os.ReadDir(bundle); len(entries) != 1 {
t.Fatalf("%d files left in the bundle", len(entries))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can also show the error from above here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We need to add this file in the unit tests target in Makefile. See https://github.com/urunc-dev/urunc/blob/main/Makefile#L242

const (
testNamespace = "k8s.io"
testDigest = "sha256:x"
ociManifest = "application/vnd.oci.image.manifest.v1+json"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use imagespec.MediaTypeImageManifest instead.

store: fakeStore{chunks: [][]byte{[]byte(manifest[:7]), []byte(manifest[7:])}},
want: map[string]string{labelKey: "manifest", uruncPrefix + "b": "2"},
wantReads: 1},
{name: "docker manifest", mediaType: "application/vnd.docker.distribution.manifest.v2+json",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use images.MediaTypeDockerSchema2Manifest instead.

store: fakeStore{chunks: [][]byte{[]byte(manifest)}},
want: map[string]string{labelKey: "manifest", uruncPrefix + "b": "2"},
wantReads: 1},
{name: "index is not read", mediaType: "application/vnd.oci.image.index.v1+json",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use imagespec.MediaTypeImageIndex instead.

ref urunc-dev#852

Signed-off-by: viju <avijusanjai@gmail.com>
ref urunc-dev#852

Signed-off-by: viju <avijusanjai@gmail.com>
ref urunc-dev#852

Signed-off-by: viju <avijusanjai@gmail.com>
@pocopepe

Copy link
Copy Markdown
Contributor Author

Hi @cmainas, thanks again for the review. I've pushed the fixes for the inline comments and rebased on main. I'll follow up with a separate PR that adds a short fuzzing doc to the developer guide covering it.

@cmainas cmainas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @pocopepe for the updates.

@cmainas
cmainas self-requested a review November 20, 2026 12:53
@urunc-bot
urunc-bot Bot changed the base branch from main to main-pr1195 November 20, 2026 13:13
@cmainas
cmainas merged commit 48d18ea into urunc-dev:main-pr1195 Nov 20, 2026
42 of 44 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 20, 2026
ref #852

PR: #1195
Signed-off-by: viju <avijusanjai@gmail.com>
Reviewed-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Approved-by: Charalampos Mainas <cmainas@nubificus.co.uk>
github-actions Bot pushed a commit that referenced this pull request Nov 20, 2026
ref #852

PR: #1195
Signed-off-by: viju <avijusanjai@gmail.com>
Reviewed-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Approved-by: Charalampos Mainas <cmainas@nubificus.co.uk>
github-actions Bot pushed a commit that referenced this pull request Nov 20, 2026
ref #852

PR: #1195
Signed-off-by: viju <avijusanjai@gmail.com>
Reviewed-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Approved-by: Charalampos Mainas <cmainas@nubificus.co.uk>
urunc-bot Bot pushed a commit that referenced this pull request Nov 20, 2026
ref #852

PR: #1195
Signed-off-by: viju <avijusanjai@gmail.com>
Reviewed-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Approved-by: Charalampos Mainas <cmainas@nubificus.co.uk>
urunc-bot Bot pushed a commit that referenced this pull request Nov 20, 2026
ref #852

PR: #1195
Signed-off-by: viju <avijusanjai@gmail.com>
Reviewed-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Approved-by: Charalampos Mainas <cmainas@nubificus.co.uk>
urunc-bot Bot pushed a commit that referenced this pull request Nov 20, 2026
ref #852

PR: #1195
Signed-off-by: viju <avijusanjai@gmail.com>
Reviewed-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Approved-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants