etc~ scripts and random things |
| git clone https://github.com/djnnvx/etc.git |
| log | files | refs | archive |
usbip_fuzz.h (3551B)
1 #pragma once 2 /* 3 * usbip_fuzz.h — fuzz control header, included before any usbip source. 4 * 5 * Provides: 6 * - global fuzz buffer (populated by harness main, consumed by __wrap_recv) 7 * - logging macro stubs so usbip source compiles without a real logging lib 8 * - usbip_header wire-format structs for fuzz_urb (not in userspace headers) 9 * 10 * Protocol constants (USBIP_VERSION, OP_*, SYSFS_BUS_ID_SIZE, etc.) are NOT 11 * defined here — they come from usbip_common.h / usbip_network.h / config.h. 12 */ 13 14 #include <stddef.h> 15 #include <stdint.h> 16 #include <string.h> 17 #include <stdio.h> 18 19 /* ── fuzz buffer (defined in mock_syscalls.c, declared here) ──────── */ 20 #define FUZZ_BUF_MAX (1 << 16) /* 64 KB */ 21 22 extern uint8_t g_fuzz_buf[FUZZ_BUF_MAX]; 23 extern size_t g_fuzz_len; 24 extern size_t g_fuzz_offset; 25 26 static inline void fuzz_reset(const uint8_t *data, size_t size) { 27 size_t n = size < FUZZ_BUF_MAX ? size : FUZZ_BUF_MAX; 28 memcpy(g_fuzz_buf, data, n); 29 g_fuzz_len = n; 30 g_fuzz_offset = 0; 31 } 32 33 /* ── silence usbip logging ────────────────────────────────────────── */ 34 #ifndef pr_err 35 # define pr_err(fmt, ...) do { } while (0) 36 #endif 37 #ifndef pr_warn 38 # define pr_warn(fmt, ...) do { } while (0) 39 #endif 40 #ifndef pr_info 41 # define pr_info(fmt, ...) do { } while (0) 42 #endif 43 #ifndef pr_debug 44 # define pr_debug(fmt, ...) do { } while (0) 45 #endif 46 47 /* usbip uses these debug wrappers over pr_debug */ 48 #ifndef dbg 49 # define dbg(fmt, ...) do { } while (0) 50 #endif 51 #ifndef usbip_dbg_xmit 52 # define usbip_dbg_xmit(fmt, ...) do { } while (0) 53 #endif 54 #ifndef usbip_dbg_sysfs 55 # define usbip_dbg_sysfs(fmt, ...) do { } while (0) 56 #endif 57 #ifndef usbip_dbg_urb 58 # define usbip_dbg_urb(fmt, ...) do { } while (0) 59 #endif 60 61 /* 62 * usbip_debug_flag — extern referenced by logging macros in usbip_common.h. 63 */ 64 extern unsigned long usbip_debug_flag; 65 66 /* 67 * ── USB/IP URB PDU wire-format constants and structs ────────────────── 68 * struct usbip_header lives only in the kernel's internal headers, not in 69 * any userspace UAPI. Define the wire layout here for fuzz_urb.c so it 70 * can call usbip_net_recv() and inspect the PDU fields. 71 * 72 * Matches drivers/usb/usbip/usbip_common.h — do not change field order. 73 */ 74 #define USBIP_CMD_SUBMIT 0x00000001 75 #define USBIP_CMD_UNLINK 0x00000002 76 #define USBIP_RET_SUBMIT 0x00000003 77 #define USBIP_RET_UNLINK 0x00000004 78 79 /* PDU header is 48 bytes on the wire (20-byte basic + 28-byte union) */ 80 #define USBIP_PDU_HDR_SIZE 48 81 82 struct usbip_header_basic { 83 uint32_t command; 84 uint32_t seqnum; 85 uint32_t devid; 86 uint32_t direction; 87 uint32_t ep; 88 }; 89 90 struct usbip_header_cmd_submit { 91 uint32_t transfer_flags; 92 int32_t transfer_buffer_length; 93 int32_t start_frame; 94 int32_t number_of_packets; 95 int32_t interval; 96 uint8_t setup[8]; 97 }; 98 99 struct usbip_header_ret_submit { 100 int32_t status; 101 int32_t actual_length; 102 int32_t start_frame; 103 int32_t number_of_packets; 104 int32_t error_count; 105 }; 106 107 struct usbip_header_cmd_unlink { uint32_t seqnum; }; 108 struct usbip_header_ret_unlink { int32_t status; }; 109 110 struct usbip_header { 111 struct usbip_header_basic base; 112 union { 113 struct usbip_header_cmd_submit cmd_submit; 114 struct usbip_header_ret_submit ret_submit; 115 struct usbip_header_cmd_unlink cmd_unlink; 116 struct usbip_header_ret_unlink ret_unlink; 117 } u; 118 };