From b454813322532bba9ce53eedd64991375fe5c044 Mon Sep 17 00:00:00 2001 From: Mikhail Malyshev Date: Tue, 14 Nov 2023 19:33:41 +0000 Subject: [PATCH 1/2] Make it compatible with kernel >= 6.4 - get_user_pages was changed in 6.5 - class_create was changed in 6.4 Signed-off-by: Mikhail Malyshev --- linux/pcie/src/pcie.c | 4 ++++ linux/utils/compact.h | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/linux/pcie/src/pcie.c b/linux/pcie/src/pcie.c index c14e0b1..2f93b3f 100644 --- a/linux/pcie/src/pcie.c +++ b/linux/pcie/src/pcie.c @@ -963,7 +963,11 @@ int hailo_pcie_register_chrdev(unsigned int major, const char *name) char_major = register_chrdev(major, name, &hailo_pcie_fops); +#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 4, 0) chardev_class = class_create(THIS_MODULE, "hailo_chardev"); +#else + chardev_class = class_create("hailo_chardev"); +#endif return char_major; } diff --git a/linux/utils/compact.h b/linux/utils/compact.h index 8439710..52c06f1 100644 --- a/linux/utils/compact.h +++ b/linux/utils/compact.h @@ -24,7 +24,10 @@ #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 5, 0) +#define get_user_pages_compact(start, nr_pages, gup_flags, pages, vmas) \ + get_user_pages(start, nr_pages, gup_flags, pages) +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 9, 0) #define get_user_pages_compact get_user_pages #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 168)) && (LINUX_VERSION_CODE < KERNEL_VERSION(4, 5, 0)) #define get_user_pages_compact(start, nr_pages, gup_flags, pages, vmas) \ @@ -143,4 +146,4 @@ static inline bool is_dma_capable(struct device *dev, dma_addr_t dma_addr, size_ } #endif // LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) -#endif /* _HAILO_PCI_COMPACT_H_ */ \ No newline at end of file +#endif /* _HAILO_PCI_COMPACT_H_ */ From a01be998e08713e7a51488e23198f3e09296a3bb Mon Sep 17 00:00:00 2001 From: Mikhail Malyshev Date: Tue, 14 Nov 2023 19:39:56 +0000 Subject: [PATCH 2/2] Mitigate [UBSAN: array-index-out-of-bounds in linux/pcie/../../common/pcie_common.c:343:53] Declare array as variable length rather than [0] Signed-off-by: Mikhail Malyshev --- common/fw_validation.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/fw_validation.h b/common/fw_validation.h index ba62479..99ef4e6 100644 --- a/common/fw_validation.h +++ b/common/fw_validation.h @@ -44,7 +44,7 @@ typedef struct { typedef struct { uint32_t key_size; uint32_t content_size; - uint8_t certificates_data[0]; + uint8_t certificates_data[]; } secure_boot_certificate_t; #ifdef _MSC_VER @@ -62,4 +62,4 @@ int FW_VALIDATION__validate_fw_header(uintptr_t firmware_base_address, int FW_VALIDATION__validate_cert_header(uintptr_t firmware_base_address, size_t firmware_size, uint32_t *outer_consumed_firmware_offset, secure_boot_certificate_t **out_firmware_cert); -#endif \ No newline at end of file +#endif