qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

trace: only permit standard C types and fixed size integer types

Some trace backends will compile code based on the declared trace
events. It should not be assumed that the backends can resolve any QEMU
specific typedefs. So trace events should restrict their argument
types to the standard C types and fixed size integer types. Any complex
pointer types can be declared as "void *" for purposes of trace events,
since nothing will be dereferencing these pointer arguments.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-id: 20180308155524.5082-3-berrange@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>

authored by

Daniel P. Berrangé and committed by
Stefan Hajnoczi
73ff0610 88584448

+46
+46
scripts/tracetool/__init__.py
··· 41 41 lines = [ l % kwargs for l in lines ] 42 42 sys.stdout.writelines("\n".join(lines) + "\n") 43 43 44 + # We only want to allow standard C types or fixed sized 45 + # integer types. We don't want QEMU specific types 46 + # as we can't assume trace backends can resolve all the 47 + # typedefs 48 + ALLOWED_TYPES = [ 49 + "int", 50 + "long", 51 + "short", 52 + "char", 53 + "bool", 54 + "unsigned", 55 + "signed", 56 + "float", 57 + "double", 58 + "int8_t", 59 + "uint8_t", 60 + "int16_t", 61 + "uint16_t", 62 + "int32_t", 63 + "uint32_t", 64 + "int64_t", 65 + "uint64_t", 66 + "void", 67 + "size_t", 68 + "ssize_t", 69 + "uintptr_t", 70 + "ptrdiff_t", 71 + # Magic substitution is done by tracetool 72 + "TCGv", 73 + ] 74 + 75 + def validate_type(name): 76 + bits = name.split(" ") 77 + for bit in bits: 78 + bit = re.sub("\*", "", bit) 79 + if bit == "": 80 + continue 81 + if bit == "const": 82 + continue 83 + if bit not in ALLOWED_TYPES: 84 + raise ValueError("Argument type '%s' is not in whitelist. " 85 + "Only standard C types and fixed size integer " 86 + "types should be used. struct, union, and " 87 + "other complex pointer types should be " 88 + "declared as 'void *'" % name) 44 89 45 90 class Arguments: 46 91 """Event arguments description.""" ··· 87 132 else: 88 133 arg_type, identifier = arg.rsplit(None, 1) 89 134 135 + validate_type(arg_type) 90 136 res.append((arg_type, identifier)) 91 137 return Arguments(res) 92 138