syzkaller--->syscalldescription语法
syzkaller
Syzkaller具有豐富的官方文檔,其中包括以下幾個方面:
使用Syzkaller的介紹:這部分介紹了如何安裝和配置Syzkaller,并提供了詳細的操作手冊。該文檔還介紹了如何運行Syzkaller的示例和常用的測試命令。
Syzkaller測試策略:該文檔介紹了Syzkaller使用的測試策略,包括隨機測試策略、覆蓋率優化策略、死鎖檢測策略等。該文檔詳細介紹了不同策略的原理和使用方法,并提供了配置樣例。
Syzkaller規則系統:Syzkaller的規則系統是生成系統調用序列的重要部分。該文檔介紹了規則系統的結構和機制,演示了如何編寫自定義規則,以及如何將規則集成到測試過程中。
錯誤報告和調試:Syzkaller在測試過程中會抓取內核崩潰信息,并生成詳細的錯誤報告。該文檔介紹了如何解析錯誤報告和定位問題。此外,該文檔還介紹了Syzkaller內置的調試和分析工具的使用方法。
Syzkaller開發:該文檔介紹了Syzkaller源代碼結構、API接口、擴展點和開發工具鏈。該文檔還提供了一些常見擴展和案例,如如何增加系統調用支持、如何自定義fuzzer策略等。
所有官方文檔均可在Syzkaller GitHub倉庫的doc目錄下找到,并提供了詳細的使用說明。此外,Syzkaller的官方網站還提供了社區支持論壇、Bug報告頁面、GitHub Issue等多種支持方式。
本身是個較強大的fuzz工具,使用方法較簡單, syz-manager -config my.cfg
但難點是編輯特異性的語法魔板,用于特定模塊和系統調用的fuzz。
公開git上已經包含了說明,但感覺比較晦澀,先按字面意思理一下
syscall_descriptions_syntax.md
- 文本1
syscall_descriptions_syntax.md
上來先定義了一套怪異的語法規則,和一般的程序不太一樣,光看文字有點不明吧,對照binfmt.txt文本來大致猜測了下。
- 文本2
/sys/linux/binfmt.txt
文本2用來描述fuzz系統調用的原則,file ptr[in, filename] 描述了參數名字文件,屬于指針,輸入類型,文件名類型
argv ptr[in, array[ptr[in, string]] 描述了指針類型的參數, 指針指向數組指針, 數組指針包含一些字符串。
len bytesize[data]描述 了data的長度。
其他參數類似。
總之參數定義完成后就是變異參數fuzz內核的過程,參數定義還可包含復雜的結構體,可以自行查看sys/linux目錄下的各種文檔。
syscallname 包含兩種形式,一種直接調用,類似execve這種,另一種 write$binfmt_script 對特定數據的系統調用,估計給每個調用起了新的名字。
總之,核心就是給系統調用設置各種參數, argv ptr[in, array[ptr[in, string]]] ,這種。約束了參數后,對系統調用的fuzz就是有針對性的。
常見數據類型
對類型作一些解釋,intN標識多少位的整型,還有一些根據名字可以猜到大概。說一些不太明白的。
- “flags”: a set of values, type-options:
reference to flags description (see below), underlying int type (e.g. “int32”)
定義的一系列選項,估計是宏定義啥的
-
“glob”: glob pattern to match on the target files, type-options:
a pattern string in quotes (syntax: https://golang.org/pkg/path/filepath/#Match)
(e.g. “/sys/” or “/sys/**/*”),
類似正則匹配的東西應該 -
“proc”: per process int (see description below), type-options:
value range start, how many values per process, underlying type
這個其實有點疑問,但是例子中大部分用法都是這樣:
類似調用號,不過我感覺應該這兩個proc好像代表的意思不太一樣,
type signalno int32[0:65]
type net_port proc[20000, 4, int16be]
這里應該是正解,代表了一系列的以4為步長的整形變量。
foo(a const[10], b const[-10]) foo(a const[0xabcd]) foo(a int8['a':'z']) foo(a const[PATH_MAX]) foo(a ptr[in, array[int8, MY_PATH_MAX]]) define MY_PATH_MAX PATH_MAX + 2還有這個,應該都是參數變異的依據。
- “text”: machine code of the specified type, type-options:
text type (x86_real, x86_16, x86_32, x86_64, arm64)
使用
編寫完文本后就是生成對應的fuzz工具,
$ bin/syz-extract -os linux -arch amd64 -sourcedir /home/fanrong/Computer/kernel/linux-5.1 proc_operation.txt $ bin/syz-sysgen $ make clean $ make all最后啟動fuzz
備注(一些例子收集)
cgroup_freezer_states = "THAWED", "FREEZING", "FROZEN" openat$cgroup_freezer_state(fd fd_cgroup, file ptr[in, string["freezer.state"]], flags const[O_RDWR], mode const[0]) fd_cgroup_freezer_state write$cgroup_freezer_state(fd fd_cgroup_freezer_state, buf ptr[in, string[cgroup_freezer_states]], len bytesize[buf]) # devices (.allow, .deny) cgroup_devices_files = "devices.allow", "devices.deny"# device types: (a)ll, (c)har, (b)lock cgroup_devices_type = "a", "c", "b"# access: (r)ead, (w)rite, (m)knod, or a combination of them cgroup_devices_access = "r", "w", "m", "rw", "rm", "wm", "rwm"# TODO: device_major_minor is in form MAJOR:MINOR, where '*' is used for all. # It is non-trivial to describe valid MAJOR:MINOR as MAJOR takes values from # a wide range while not all such devices might exist in the system. cgroup_devices_towrite {dev stringnoz[cgroup_devices_type]device_major_minor stringnoz[" *:* "]access string[cgroup_devices_access] } [packed]openat$cgroup_devices(fd fd_cgroup, file ptr[in, string[cgroup_devices_files]], flags const[O_RDWR], mode const[0]) fd_cgroup_devices write$cgroup_devices(fd fd_cgroup_devices, buf ptr[in, cgroup_devices_towrite], len bytesize[buf])總結
以上是生活随笔為你收集整理的syzkaller--->syscalldescription语法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: TortoiseSVN 如何去掉文件夹
- 下一篇: Hie with the Pie(Flo