diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2020-05-09 17:36:04 +0200 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2020-05-11 16:54:44 +0200 |
| commit | f4bf31dc3ce9d9bd15aa99276c63b2e21e3d9131 (patch) | |
| tree | cad187daf2ed9fc30c60e7f40ed287d199fa0e08 /sys | |
| parent | b17a8c447430fab3a57c27b0314404b28f241a46 (diff) | |
sys/syz-extract: use -nostdinc on linux
This makes the build completely hermetic.
Diffstat (limited to 'sys')
| -rw-r--r-- | sys/linux/dev_kvm.txt | 1 | ||||
| -rw-r--r-- | sys/linux/dev_kvm_arm.const | 191 | ||||
| -rw-r--r-- | sys/linux/socket_vnet.txt | 1 | ||||
| -rw-r--r-- | sys/syz-extract/linux.go | 35 | ||||
| -rw-r--r-- | sys/syz-sysgen/sysgen.go | 13 |
5 files changed, 34 insertions, 207 deletions
diff --git a/sys/linux/dev_kvm.txt b/sys/linux/dev_kvm.txt index 7b67c9d5d..5fcfd044b 100644 --- a/sys/linux/dev_kvm.txt +++ b/sys/linux/dev_kvm.txt @@ -145,7 +145,6 @@ kvm_vcpu_target = KVM_ARM_TARGET_CORTEX_A53, KVM_ARM_TARGET_AEM_V8, KVM_ARM_TARG kvm_vcpu_features_arm64 = KVM_ARM_VCPU_POWER_OFF, KVM_ARM_VCPU_EL1_32BIT, KVM_ARM_VCPU_PSCI_0_2, KVM_ARM_VCPU_PMU_V3 kvm_mem_slots = 0, 1, 2, 3, 4, 5, 509, 510, 511, 10000, 65536, 65537, 65538, 65539, 65540, 66047, 66048, 66049 -kvm_guest_addrs = 0, 1, 2, 4, 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0xd000, 0xf000, 0x100000, 0x10000 kvm_guest_addr_size = 0x1000, 0x2000, 0x4000, 0x8000, 0x10000, 0x100000 kvm_x86_tss_addr = 0xd000 kvm_x86_cr0 = 1, 2, 4, 8, 16, 32, 65536, 262144, 536870912, 1073741824, 2147483648 diff --git a/sys/linux/dev_kvm_arm.const b/sys/linux/dev_kvm_arm.const index 8e487a863..c9328ca7e 100644 --- a/sys/linux/dev_kvm_arm.const +++ b/sys/linux/dev_kvm_arm.const @@ -1,192 +1 @@ # AUTOGENERATED FILE -AT_FDCWD = 18446744073709551516 -KVM_ARM_SET_DEVICE_ADDR = 1074835115 -# KVM_ARM_TARGET_AEM_V8 is not set -# KVM_ARM_TARGET_CORTEX_A53 is not set -# KVM_ARM_TARGET_CORTEX_A57 is not set -# KVM_ARM_TARGET_FOUNDATION_V8 is not set -# KVM_ARM_TARGET_GENERIC_V8 is not set -# KVM_ARM_TARGET_XGENE_POTENZA is not set -# KVM_ARM_VCPU_EL1_32BIT is not set -KVM_ARM_VCPU_INIT = 1075883694 -# KVM_ARM_VCPU_PMU_V3 is not set -KVM_ARM_VCPU_POWER_OFF = 0 -KVM_ARM_VCPU_PSCI_0_2 = 1 -KVM_ASSIGN_DEV_IRQ = 1077980784 -KVM_ASSIGN_PCI_DEVICE = 2151722601 -KVM_ASSIGN_SET_INTX_MASK = 1077980836 -KVM_ASSIGN_SET_MSIX_ENTRY = 1074835060 -KVM_ASSIGN_SET_MSIX_NR = 1074310771 -KVM_CAP_DISABLE_QUIRKS = 116 -KVM_CAP_HYPERV_SYNIC = 123 -KVM_CAP_SPLIT_IRQCHIP = 121 -KVM_CAP_X2APIC_API = 129 -KVM_CHECK_EXTENSION = 44547 -# KVM_CPUID_FEATURES is not set -# KVM_CPUID_FLAG_SIGNIFCANT_INDEX is not set -# KVM_CPUID_FLAG_STATEFUL_FUNC is not set -# KVM_CPUID_FLAG_STATE_READ_NEXT is not set -# KVM_CPUID_SIGNATURE is not set -KVM_CREATE_DEVICE = 3222056672 -KVM_CREATE_DEVICE_TEST = 1 -KVM_CREATE_IRQCHIP = 44640 -KVM_CREATE_PIT2 = 1077980791 -KVM_CREATE_VCPU = 44609 -KVM_CREATE_VM = 44545 -KVM_DEASSIGN_DEV_IRQ = 1077980789 -KVM_DEASSIGN_PCI_DEVICE = 1077980786 -KVM_DEV_ASSIGN_ENABLE_IOMMU = 1 -KVM_DEV_ASSIGN_MASK_INTX = 4 -KVM_DEV_ASSIGN_PCI_2_3 = 2 -KVM_DEV_IRQ_GUEST_INTX = 256 -KVM_DEV_IRQ_GUEST_MSI = 512 -KVM_DEV_IRQ_GUEST_MSIX = 1024 -KVM_DEV_IRQ_HOST_INTX = 1 -KVM_DEV_IRQ_HOST_MSI = 2 -KVM_DEV_IRQ_HOST_MSIX = 4 -KVM_DEV_TYPE_FLIC = 6 -KVM_DEV_TYPE_FSL_MPIC_20 = 1 -KVM_DEV_TYPE_FSL_MPIC_42 = 2 -KVM_DEV_TYPE_VFIO = 4 -KVM_DEV_TYPE_XICS = 3 -KVM_DIRTY_TLB = 1074835114 -KVM_ENABLE_CAP = 1080602275 -KVM_GET_API_VERSION = 44544 -KVM_GET_CLOCK = 2150674044 -# KVM_GET_CPUID2 is not set -# KVM_GET_DEBUGREGS is not set -KVM_GET_DEVICE_ATTR = 1075359458 -KVM_GET_DIRTY_LOG = 1074835010 -# KVM_GET_EMULATED_CPUID is not set -KVM_GET_FPU = 2147528332 -KVM_GET_IRQCHIP = 3255348834 -# KVM_GET_LAPIC is not set -KVM_GET_MP_STATE = 2147790488 -# KVM_GET_MSRS is not set -# KVM_GET_MSR_INDEX_LIST is not set -# KVM_GET_NESTED_STATE is not set -KVM_GET_NR_MMU_PAGES = 44613 -KVM_GET_ONE_REG = 1074835115 -# KVM_GET_PIT is not set -# KVM_GET_PIT2 is not set -KVM_GET_REGS = 2157489793 -KVM_GET_REG_LIST = 3221794480 -KVM_GET_SREGS = 2147528323 -# KVM_GET_SUPPORTED_CPUID is not set -KVM_GET_TSC_KHZ = 44707 -KVM_GET_VCPU_EVENTS = 2151722655 -KVM_GET_VCPU_MMAP_SIZE = 44548 -# KVM_GET_XCRS is not set -# KVM_GET_XSAVE is not set -KVM_GUESTDBG_ENABLE = 1 -# KVM_GUESTDBG_INJECT_BP is not set -# KVM_GUESTDBG_INJECT_DB is not set -KVM_GUESTDBG_SINGLESTEP = 2 -# KVM_GUESTDBG_USE_HW_BP is not set -# KVM_GUESTDBG_USE_SW_BP is not set -KVM_HAS_DEVICE_ATTR = 1075359459 -KVM_HYPERV_EVENTFD = 1075359421 -KVM_INTERRUPT = 1074048646 -KVM_IOEVENTFD = 1077980793 -KVM_IOEVENTFD_FLAG_DATAMATCH = 1 -KVM_IOEVENTFD_FLAG_DEASSIGN = 4 -KVM_IOEVENTFD_FLAG_PIO = 2 -KVM_IOEVENTFD_FLAG_VIRTIO_CCW_NOTIFY = 8 -# KVM_IRQCHIP_IOAPIC is not set -# KVM_IRQCHIP_PIC_MASTER is not set -# KVM_IRQCHIP_PIC_SLAVE is not set -KVM_IRQFD = 1075883638 -KVM_IRQ_LINE = 1074310753 -KVM_IRQ_LINE_STATUS = 3221794407 -KVM_IRQ_ROUTING_HV_SINT = 4 -KVM_IRQ_ROUTING_IRQCHIP = 1 -KVM_IRQ_ROUTING_MSI = 2 -KVM_IRQ_ROUTING_S390_ADAPTER = 3 -KVM_KVMCLOCK_CTRL = 44717 -KVM_MEM_LOG_DIRTY_PAGES = 1 -KVM_MEM_READONLY = 2 -KVM_MP_STATE_CHECK_STOP = 6 -KVM_MP_STATE_HALTED = 3 -KVM_MP_STATE_INIT_RECEIVED = 2 -KVM_MP_STATE_LOAD = 8 -KVM_MP_STATE_OPERATING = 7 -KVM_MP_STATE_RUNNABLE = 0 -KVM_MP_STATE_SIPI_RECEIVED = 4 -KVM_MP_STATE_STOPPED = 5 -KVM_MP_STATE_UNINITIALIZED = 1 -KVM_NMI = 44698 -KVM_PPC_ALLOCATE_HTAB = 3221532327 -KVM_PPC_GET_PVINFO = 1082175137 -KVM_PPC_GET_SMMU_INFO = 2186325670 -KVM_REGISTER_COALESCED_MMIO = 1074835047 -KVM_REINJECT_CONTROL = 44657 -KVM_RUN = 44672 -KVM_S390_INTERRUPT = 1074835092 -KVM_S390_UCAS_MAP = 1075359312 -KVM_S390_UCAS_UNMAP = 1075359313 -KVM_S390_VCPU_FAULT = 1074048594 -KVM_SETUP_CPL3 = 8 -KVM_SETUP_PAE = 2 -KVM_SETUP_PAGING = 1 -KVM_SETUP_PROTECTED = 4 -KVM_SETUP_SMM = 32 -KVM_SETUP_VIRT86 = 16 -KVM_SETUP_VM = 64 -KVM_SET_BOOT_CPU_ID = 44664 -KVM_SET_CLOCK = 1076932219 -# KVM_SET_CPUID is not set -# KVM_SET_CPUID2 is not set -# KVM_SET_DEBUGREGS is not set -KVM_SET_DEVICE_ATTR = 1075359457 -KVM_SET_FPU = 1073786509 -KVM_SET_GSI_ROUTING = 1074310762 -KVM_SET_GUEST_DEBUG = 1074310811 -KVM_SET_IDENTITY_MAP_ADDR = 1074310728 -KVM_SET_IRQCHIP = 2181607011 -# KVM_SET_LAPIC is not set -KVM_SET_MP_STATE = 1074048665 -# KVM_SET_MSRS is not set -# KVM_SET_NESTED_STATE is not set -KVM_SET_NR_MMU_PAGES = 44612 -KVM_SET_ONE_REG = 1074835116 -# KVM_SET_PIT is not set -# KVM_SET_PIT2 is not set -KVM_SET_REGS = 1083747970 -KVM_SET_SIGNAL_MASK = 1074048651 -KVM_SET_SREGS = 1073786500 -KVM_SET_TSC_KHZ = 44706 -KVM_SET_TSS_ADDR = 44615 -KVM_SET_USER_MEMORY_REGION = 1075883590 -KVM_SET_VAPIC_ADDR = 1074310803 -KVM_SET_VCPU_EVENTS = 1077980832 -# KVM_SET_XCRS is not set -# KVM_SET_XSAVE is not set -KVM_SIGNAL_MSI = 1075883685 -KVM_SMI = 44727 -# KVM_STATE_NESTED_GUEST_MODE is not set -# KVM_STATE_NESTED_RUN_PENDING is not set -# KVM_STATE_NESTED_SMM_GUEST_MODE is not set -# KVM_STATE_NESTED_SMM_VMXON is not set -KVM_TPR_ACCESS_REPORTING = 3223891602 -KVM_TRANSLATE = 3222843013 -KVM_UNREGISTER_COALESCED_MMIO = 1074835048 -KVM_X86_GET_MCE_CAP_SUPPORTED = 2148052637 -KVM_X86_SETUP_MCE = 1074310812 -# KVM_X86_SET_MCE is not set -# KVM_XEN_HVM_CONFIG is not set -# MCG_STATUS_EIPV is not set -# MCG_STATUS_LMCES is not set -# MCG_STATUS_MCIP is not set -# MCG_STATUS_RIPV is not set -# MCI_STATUS_ADDRV is not set -# MCI_STATUS_AR is not set -# MCI_STATUS_EN is not set -# MCI_STATUS_MISCV is not set -# MCI_STATUS_OVER is not set -# MCI_STATUS_PCC is not set -# MCI_STATUS_S is not set -# MCI_STATUS_UC is not set -# MCI_STATUS_VAL is not set -VMCS12_SIZE = 4096 -__NR_ioctl = 54 -__NR_openat = 322 diff --git a/sys/linux/socket_vnet.txt b/sys/linux/socket_vnet.txt index 65396887b..32db44cb1 100644 --- a/sys/linux/socket_vnet.txt +++ b/sys/linux/socket_vnet.txt @@ -144,6 +144,7 @@ vhost_features = VHOST_LOG_ALL, VIRTIO_NOTIFY_ON_EMPTY, VIRTIO_RING_F_INDIRECT_D vhost_vring_index = VSOCK_VQ_RX, VSOCK_VQ_TX, VSOCK_VQ_EVENT, VSOCK_VQ_MAX vhost_iotlb_type = VHOST_IOTLB_MISS, VHOST_IOTLB_UPDATE, VHOST_IOTLB_INVALIDATE, VHOST_IOTLB_ACCESS_FAIL vhost_iotlb_perm = VHOST_ACCESS_RO, VHOST_ACCESS_WO, VHOST_ACCESS_RW +kvm_guest_addrs = 0, 1, 2, 4, 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0xd000, 0xf000, 0x100000, 0x10000 define VHOST_LOG_ALL 1 << VHOST_F_LOG_ALL define VIRTIO_NOTIFY_ON_EMPTY 1 << VIRTIO_F_NOTIFY_ON_EMPTY diff --git a/sys/syz-extract/linux.go b/sys/syz-extract/linux.go index f40b634ea..ceafafc5d 100644 --- a/sys/syz-extract/linux.go +++ b/sys/syz-extract/linux.go @@ -52,17 +52,20 @@ func (*linux) prepareArch(arch *Arch) error { // So we create empty stubs in buildDir/syzkaller and add -IbuildDir/syzkaller // as the last flag so it won't override real kernel headers. for hdr, data := range map[string]string{ + // This is the only compiler header kernel uses, + // need to provide it since we use -nostdinc below. + "stdarg.h": ` +#pragma once +#define va_list __builtin_va_list +#define va_start __builtin_va_start +#define va_end __builtin_va_end +#define va_arg __builtin_va_arg +#define va_copy __builtin_va_copy +#define __va_copy __builtin_va_copy +`, "asm/a.out.h": "", "asm/prctl.h": "", "asm/mce.h": "", - "asm/kvm_host.h": ` -#define KVM_USER_MEM_SLOTS 1 -#define KVM_MAX_VCPUS 1 -struct kvm_vm_stat {}; -struct kvm_vcpu_stat {}; -struct kvm_arch {}; -struct kvm_vcpu_arch {}; -`, } { fullPath := filepath.Join(arch.buildDir, "syzkaller", hdr) if err := osutil.MkdirAll(filepath.Dir(fullPath)); err != nil { @@ -123,13 +126,18 @@ struct kvm_vcpu_arch {}; } func (*linux) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint64, map[string]bool, error) { + if info.File == "dev_kvm.txt" && arch.target.Arch == "arm" { + // Hack: KVM is not supported on ARM anymore. We may want some more official support + // for marking descriptions arch-specific, but so far this combination is the only one. + // Note: syz-sysgen also ignores this file for arm. + return nil, nil, nil + } headerArch := arch.target.KernelHeaderArch sourceDir := arch.sourceDir buildDir := arch.buildDir args := []string{ - // This would be useful to ensure that we don't include any host headers, - // but kernel includes at least <stdarg.h> - // "-nostdinc", + // This makes the build completely hermetic, only kernel headers are used. + "-nostdinc", "-w", "-fmessage-length=0", "-O3", // required to get expected values for some __builtin_constant_p "-I.", @@ -138,6 +146,8 @@ func (*linux) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint "-I" + sourceDir + "/arch/" + headerArch + "/include", "-I" + buildDir + "/arch/" + headerArch + "/include/generated/uapi", "-I" + buildDir + "/arch/" + headerArch + "/include/generated", + "-I" + sourceDir + "/arch/" + headerArch + "/include/asm/mach-malta", + "-I" + sourceDir + "/arch/" + headerArch + "/include/asm/mach-generic", "-I" + buildDir + "/include", "-I" + sourceDir + "/include", "-I" + sourceDir + "/arch/" + headerArch + "/include/uapi", @@ -145,9 +155,8 @@ func (*linux) processFile(arch *Arch, info *compiler.ConstInfo) (map[string]uint "-I" + sourceDir + "/include/uapi", "-I" + buildDir + "/include/generated/uapi", "-I" + sourceDir, + "-I" + sourceDir + "/include/linux", "-I" + buildDir + "/syzkaller", - "-I" + sourceDir + "/arch/" + headerArch + "/include/asm/mach-malta", - "-I" + sourceDir + "/arch/" + headerArch + "/include/asm/mach-generic", "-include", sourceDir + "/include/linux/kconfig.h", } args = append(args, arch.target.CrossCFlags...) diff --git a/sys/syz-sysgen/sysgen.go b/sys/syz-sysgen/sysgen.go index 654664af6..9e4f894cd 100644 --- a/sys/syz-sysgen/sysgen.go +++ b/sys/syz-sysgen/sysgen.go @@ -69,8 +69,8 @@ func main() { data := &ExecutorData{} for _, OS := range OSList { - top := ast.ParseGlob(filepath.Join("sys", OS, "*.txt"), nil) - if top == nil { + descriptions := ast.ParseGlob(filepath.Join("sys", OS, "*.txt"), nil) + if descriptions == nil { os.Exit(1) } osutil.MkdirAll(filepath.Join("sys", OS, "gen")) @@ -111,6 +111,15 @@ func main() { if consts == nil { return } + top := descriptions + if OS == "linux" && job.Target.Arch == "arm" { + // Hack: KVM is not supported on ARM anymore. + // Note: syz-extract also ignores this file for arm. + top = descriptions.Filter(func(n ast.Node) bool { + pos, _, _ := n.Info() + return pos.File != "dev_kvm.txt" + }) + } if OS == "test" { constInfo := compiler.ExtractConsts(top, job.Target, eh) compiler.FabricateSyscallConsts(job.Target, constInfo, consts) |
