From c756ba4e975097bf74b952367e2cd1a8db466c69 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Mon, 2 Dec 2024 10:57:36 +0100 Subject: tools/syz-declextract: extract file_operations descriptions Extend the clang tool to locate file_operations variables and arrays and dump open/read/write/mmap/ioctl callbacks for each. It also tries to extract set of ioctl commands and argument types for them in a simple best-effort way (for now). It just locates switch in the ioctl callback and extracts each case as a command. --- .../testdata/file_operations.c.json | 118 +++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100644 tools/syz-declextract/testdata/file_operations.c.json (limited to 'tools/syz-declextract/testdata/file_operations.c.json') diff --git a/tools/syz-declextract/testdata/file_operations.c.json b/tools/syz-declextract/testdata/file_operations.c.json new file mode 100644 index 000000000..e5ddad2b2 --- /dev/null +++ b/tools/syz-declextract/testdata/file_operations.c.json @@ -0,0 +1,118 @@ +{ + "includes": [ + "include/uapi/file_operations.h" + ], + "structs": [ + { + "name": "foo_ioctl_arg", + "byte_size": 8, + "fields": [ + { + "name": "a", + "counted_by": -1, + "type": { + "int": { + "byte_size": 4, + "name": "int", + "base": "int" + } + } + }, + { + "name": "b", + "counted_by": -1, + "type": { + "int": { + "byte_size": 4, + "name": "int", + "base": "int" + } + } + } + ] + } + ], + "file_ops": [ + { + "name": "foo_file_operations", + "open": "foo_open", + "read": "foo_read", + "write": "foo_write", + "mmap": "foo_mmap", + "ioctl": "foo_ioctl", + "ioctl_cmds": [ + { + "name": "FOO_IOCTL5", + "type": { + "ptr": { + "elem": { + "struct": "foo_ioctl_arg" + } + } + } + }, + { + "name": "FOO_IOCTL4", + "type": { + "ptr": { + "elem": { + "struct": "foo_ioctl_arg" + } + } + } + }, + { + "name": "FOO_IOCTL3", + "type": { + "ptr": { + "elem": { + "struct": "foo_ioctl_arg" + }, + "is_const": true + } + } + }, + { + "name": "FOO_IOCTL2", + "type": { + "ptr": { + "elem": { + "int": { + "byte_size": 4, + "name": "int", + "base": "int" + } + }, + "is_const": true + } + } + }, + { + "name": "FOO_IOCTL1", + "type": { + "int": { + "byte_size": 1, + "is_const": true + } + } + } + ], + "source_file": "file_operations.c" + }, + { + "name": "proc_ops_file_operations", + "open": "proc_open", + "read": "proc_read", + "write": "proc_write", + "mmap": "proc_open", + "source_file": "file_operations.c" + }, + { + "name": "proc_ops_file_operations1", + "open": "proc_open", + "mmap": "proc_open", + "ioctl": "proc_ioctl", + "source_file": "file_operations.c" + } + ] +} \ No newline at end of file -- cgit mrf-deployment