syz-extract-constants
Defining and extracting kernel constants for syzkaller syzlang descriptions
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 0
- Forks
- 1
01 前言 Front Matter
- name
- syz-extract-constants
- description
- Defining and extracting kernel constants for syzkaller syzlang descriptions
03 SKILL.md 正文
Defining Constants in Syzlang
Overview
Syzkaller needs to know the actual values of kernel constants (ioctl numbers, flags, etc.) to generate valid fuzzing programs. There are two ways to provide these values:
- Manual
.constfile - Define constants directly in a companion file syz-extracttool - Extract values from kernel source headers (requires kernel source)
Method 1: Manual Constants File (Recommended when no kernel source)
Create a .const file alongside your .txt file with the constant values.
File naming
- Syzlang description:
sys/linux/dev_ppdev.txt - Constants file:
sys/linux/dev_ppdev.txt.const
Constants file format
# Constants for your syzlang descriptions
arches = 386, amd64, arm, arm64, mips64le, ppc64le, riscv64, s390x
PPCLAIM = 28811
PPRELEASE = 28812
IEEE1284_MODE_NIBBLE = 0
IEEE1284_MODE_BYTE = 1
The arches line declares which architectures these constants are valid for.
- If a constant is architecture-independent for your purposes, you can list all arches.
- If some constants are arch-dependent (e.g.,
_IOW/_IOR/_IOWRwhere thesizepart depends on the size/layout of the referenced type), you must ensure the values are correct for each arch you claim support for.
Required completeness (do not skip simple ioctls)
Any constant referenced anywhere in the .txt file must exist in the .const file.
This includes:
- ioctl numbers used in
const[...](even for ioctls with no third argument, e.g.,_IO(...)likePPCLAIM/PPRELEASE) - bitflags used in
flags[...] - any numeric
const[...]values you introduce
Practical audit (fast and robust):
- List all constants referenced from the
.txt:
grep -oE 'const\[[A-Z0-9_]+\]' sys/linux/dev_ppdev.txt | sort -u
- Ensure each one has a definition in the
.const:
for c in $(grep -oE 'const\[[A-Z0-9_]+\]' sys/linux/dev_ppdev.txt | sed 's/const\[//;s/\]//' | sort -u); do
grep -qE "^${c}\\s*=" sys/linux/dev_ppdev.txt.const || echo "MISSING: ${c}"
done
If any required constant is missing, you can still sometimes pass make descriptions depending on how the description file is exercised, but downstream validation/tests will fail (e.g., a unit test that checks exact expected values).
Calculating ioctl values
Linux ioctl numbers are encoded as:
_IO(type, nr)=(type << 8) | nr_IOR(type, nr, size)=(2 << 30) | (size << 16) | (type << 8) | nr_IOW(type, nr, size)=(1 << 30) | (size << 16) | (type << 8) | nr_IOWR(type, nr, size)=(3 << 30) | (size << 16) | (type << 8) | nr
For ppdev (type='p'=0x70):
PPCLAIM = _IO('p', 0x8b)=0x708b=28811
When you see failures like “expected PPCLAIM==28811 but got None”, it means the constant wasn’t parsed from the .const file at all (most commonly: the line is missing or malformed).
New-style vs old-style .const files (arch handling)
Syzkaller supports two .const layouts:
- New-style (recommended): one file with a single header:
arches = 386, amd64
NAME = 123
- Old-style: separate per-arch files passed via build machinery (you generally won’t hand-write this unless you know you need it).
For SkillBench-style tasks, use the new-style single-file format with exactly one arches = ... header near the top.
Method 2: Using syz-extract (Requires kernel source)
If kernel source is available:
cd /opt/syzkaller
# Extract constants for a specific file
make extract TARGETOS=linux SOURCEDIR=/path/to/linux FILES=sys/linux/dev_ppdev.txt
Note: This environment does not include kernel source. Use Method 1 (manual constants file) instead.
After Defining Constants
After creating the .const file, build syzkaller:
cd /opt/syzkaller
make descriptions # Compiles descriptions + constants
make all # Full build
Common Errors
"is defined for none of the arches"
This means the constant is used in the .txt file but not defined in the .const file.
- Add the missing constant to the
.constfile - Ensure
archesline lists the target architectures
Example:
PPCLAIM is defined for none of the arches
Missing headers
cannot find include file: uapi/linux/ppdev.h
Solution: Check the kernel source path and ensure headers are properly configured.
"unknown file"
unknown file: sys/linux/dev_ppdev.txt
Solution: Use make extract FILES=... instead of calling bin/syz-extract directly.
Example Workflow
- Write the syzlang description file (
sys/linux/dev_ppdev.txt) - Run
make extract TARGETOS=linux SOURCEDIR=/opt/linux/source FILES=sys/linux/dev_ppdev.txt - Run
make generateto regenerate Go code - Run
maketo build syzkaller - Test with
make descriptionsto verify everything compiles
04 同仓库更多 Skills
video-frame-extraction
Extract frames from video files and save them as images using OpenCV
openai-vision
Analyze images and multi-frame sequences using OpenAI GPT vision models
image-ocr
Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms
video-frame-extraction
Extract frames from video files and save them as images using OpenCV
openai-vision
Analyze images and multi-frame sequences using OpenAI GPT vision models
image-ocr
Extract text content from images using Tesseract OCR via Python, including structured field extraction from receipts and forms