Changeset 40601 in vbox for trunk/src/VBox/HostDrivers/Support
- Timestamp:
- Mar 24, 2012 9:31:11 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPDrv-dtrace.cpp
r40600 r40601 122 122 123 123 124 static int supdrvVtgValidateString(const char *psz) 125 { 126 size_t off = 0; 127 while (off < _4K) 128 { 129 char const ch = psz[off++]; 130 if (!ch) 131 return VINF_SUCCESS; 132 if ( !RTLocCIsAlNum(ch) 133 && ch != ' ' 134 && ch != '(' 135 && ch != ')' 136 && ch != ',' 137 && ch != '*' 138 && ch != '&' 139 ) 140 return VERR_SUPDRV_VTG_BAD_STRING; 141 } 142 return VERR_SUPDRV_VTG_STRING_TOO_LONG; 143 } 144 124 145 /** 125 146 * Validates the VTG data. … … 134 155 static int supdrvVtgValidate(PVTGOBJHDR pVtgHdr, size_t cbVtgObj, uint8_t *pbImage, size_t cbImage) 135 156 { 136 /*137 * The header.138 */139 if (!memcmp(pVtgHdr->szMagic, VTGOBJHDR_MAGIC, sizeof(pVtgHdr->szMagic))) 140 return VERR_SUPDRV_VTG_MAGIC;141 if (pVtgHdr->cBits != ARCH_BITS)142 return VERR_SUPDRV_VTG_BITS;143 if (pVtgHdr->u32Reserved0)144 return VERR_SUPDRV_VTG_RESERVED;157 uintptr_t cbTmp; 158 uintptr_t i; 159 int rc; 160 161 if (!pbImage || !cbImage) 162 { 163 pbImage = NULL; 164 cbImage = 0; 165 } 145 166 146 167 #define MY_VALIDATE_PTR(p, cb, cMin, cMax, cbUnit) \ … … 156 177 return VERR_SUPDRV_VTG_NOT_MULTIPLE; \ 157 178 } while (0) 158 159 MY_VALIDATE_PTR(pVtgHdr->paProviders, pVtgHdr->cbProviders, 1, 16, sizeof(VTGDESCPROVIDER)); 160 MY_VALIDATE_PTR(pVtgHdr->paProbes, pVtgHdr->cbProbes, 1, _32K, sizeof(VTGDESCPROBE)); 161 MY_VALIDATE_PTR(pVtgHdr->pafProbeEnabled, pVtgHdr->cbProbeEnabled, 1, _32K, sizeof(bool)); 162 MY_VALIDATE_PTR(pVtgHdr->pachStrTab, pVtgHdr->cbStrTab, 4, _1M, sizeof(char)); 163 MY_VALIDATE_PTR(pVtgHdr->paArgLists, pVtgHdr->cbArgLists, 0, _32K, sizeof(uint32_t)); 179 #define MY_WITHIN_IMAGE(p) \ 180 do { \ 181 if (pbImage) \ 182 { \ 183 if ((uintptr_t)(p) - (uintptr_t)pbImage > cbImage) \ 184 return VERR_SUPDRV_VTG_BAD_PTR; \ 185 } \ 186 else if (!RT_VALID_PTR(p)) \ 187 return VERR_SUPDRV_VTG_BAD_PTR; \ 188 } while (0) 189 #define MY_WITHIN_IMAGE_RANGE(p, cb) 190 do { \ 191 if (pbImage) \ 192 { \ 193 if ( (cb) > cbImage \ 194 || (uintptr_t)(p) - (uintptr_t)pbImage > cbImage - (cb)) \ 195 return VERR_SUPDRV_VTG_BAD_PTR; \ 196 } \ 197 else if (!RT_VALID_PTR(p) || RT_VALID_PTR((uint8_t *)(p) + cb)) \ 198 return VERR_SUPDRV_VTG_BAD_PTR; \ 199 } while (0) 200 #define MY_VALIDATE_STR(offStrTab) \ 201 do { \ 202 if ((offStrTab) >= pVtgHdr->cbStrTab) \ 203 return VERR_SUPDRV_VTG_STRTAB_OFF; \ 204 rc = supdrvVtgValidateString(pVtgHdr->pachStrTab + (offStrTab)); \ 205 if (rc != VINF_SUCCESS) \ 206 return rc; \ 207 } while (0) 208 #define MY_VALIDATE_ATTR(Attr) 209 do { \ 210 if ((Attr).u8Code <= (uint8_t)kVTGStability_Invalid || (Attr).u8Code >= (uint8_t)kVTGStability_End) \ 211 return VERR_SUPDRV_VTG_BAD_ATTR; \ 212 if ((Attr).u8Data <= (uint8_t)kVTGStability_Invalid || (Attr).u8Data >= (uint8_t)kVTGStability_End) \ 213 return VERR_SUPDRV_VTG_BAD_ATTR; \ 214 if ((Attr).u8DataDep <= (uint8_t)kVTGClass_Invalid || (Attr).u8DataDep >= (uint8_t)kVTGClass_End) \ 215 return VERR_SUPDRV_VTG_BAD_ATTR; \ 216 } while (0) 217 218 /* 219 * The header. 220 */ 221 if (!memcmp(pVtgHdr->szMagic, VTGOBJHDR_MAGIC, sizeof(pVtgHdr->szMagic))) 222 return VERR_SUPDRV_VTG_MAGIC; 223 if (pVtgHdr->cBits != ARCH_BITS) 224 return VERR_SUPDRV_VTG_BITS; 225 if (pVtgHdr->u32Reserved0) 226 return VERR_SUPDRV_VTG_RESERVED; 227 228 MY_VALIDATE_PTR(pVtgHdr->paProviders, pVtgHdr->cbProviders, 1, 16, sizeof(VTGDESCPROVIDER)); 229 MY_VALIDATE_PTR(pVtgHdr->paProbes, pVtgHdr->cbProbes, 1, _32K, sizeof(VTGDESCPROBE)); 230 MY_VALIDATE_PTR(pVtgHdr->pafProbeEnabled, pVtgHdr->cbProbeEnabled, 1, _32K, sizeof(bool)); 231 MY_VALIDATE_PTR(pVtgHdr->pachStrTab, pVtgHdr->cbStrTab, 4, _1M, sizeof(char)); 232 MY_VALIDATE_PTR(pVtgHdr->paArgLists, pVtgHdr->cbArgLists, 0, _32K, sizeof(uint32_t)); 233 MY_WITHIN_IMAGE(pVtgHdr->paProbLocs); 234 MY_WITHIN_IMAGE(pVtgHdr->paProbLocsEnd); 235 if ((uintptr_t)pVtgHdr->paProbLocs > (uintptr_t)pVtgHdr->paProbLocsEnd) 236 return VERR_SUPDRV_VTG_BAD_PTR; 237 cbTmp = (uintptr_t)pVtgHdr->paProbLocsEnd - (uintptr_t)pVtgHdr->paProbLocs; 238 MY_VALIDATE_PTR(pVtgHdr->paProbLocs, cbTmp, 1, _128K, sizeof(VTGPROBELOC)) 239 if (cbTmp < sizeof(VTGPROBELOC)) 240 return VERR_SUPDRV_VTG_TOO_FEW; 241 242 if (pVtgHdr->cbProbes / sizeof(VTGDESCPROBE) != pVtgHdr->cbProbeEnabled) 243 return VERR_SUPDRV_VTG_BAD_HDR; 244 245 /* 246 * Validate the providers. 247 */ 248 i = pVtgHdr->cbProviders / sizeof(VTGDESCPROVIDER); 249 while (i-- > 0) 250 { 251 MY_VALIDATE_STR(pVtgHdr->paProviders[i].offName); 252 if (pVtgHdr->paProviders[i].iFirstProbe >= pVtgHdr->cbProbeEnabled) 253 return VERR_SUPDRV_VTG_BAD_PROVIDER; 254 if (pVtgHdr->paProviders[i].iFirstProbe + pVtgHdr->paProviders[i].cProbes > pVtgHdr->cbProbeEnabled) 255 return VERR_SUPDRV_VTG_BAD_PROVIDER; 256 MY_VALIDATE_ATTR(pVtgHdr->paProviders[i].AttrSelf); 257 MY_VALIDATE_ATTR(pVtgHdr->paProviders[i].AttrModules); 258 MY_VALIDATE_ATTR(pVtgHdr->paProviders[i].AttrFunctions); 259 MY_VALIDATE_ATTR(pVtgHdr->paProviders[i].AttrName); 260 MY_VALIDATE_ATTR(pVtgHdr->paProviders[i].AttrArguments); 261 if (pVtgHdr->paProviders[i].bReserved) 262 return VERR_SUPDRV_VTG_RESERVED; 263 } 264 265 /* 266 * Validate probes. 267 */ 268 i = pVtgHdr->cbProbes / sizeof(VTGDESCPROBE); 269 while (i-- > 0) 270 { 271 MY_VALIDATE_STR(pVtgHdr->paProbes[i].offName); 272 } 273 274 return VINF_SUCCESS; 275 #undef MY_VALIDATE_STR 164 276 #undef MY_VALIDATE_PTR 165 166 if (!RT_VALID_PTR(pVtgHdr->paProbLocs)) 167 return VERR_SUPDRV_VTG_BAD_PTR; 168 if (!RT_VALID_PTR(pVtgHdr->paProbLocsEnd)) 169 return VERR_SUPDRV_VTG_BAD_PTR; 170 if ((uintptr_t)pVtgHdr->paProbLocsEnd - (uintptr_t)pVtgHdr->paProbLocs < sizeof(VTGPROBELOC)) 171 return VERR_SUPDRV_VTG_TOO_FEW; 172 if ((uintptr_t)pVtgHdr->paProbLocsEnd - (uintptr_t)pVtgHdr->paProbLocs > sizeof(VTGPROBELOC) * _128K) 173 return VERR_SUPDRV_VTG_TOO_MUCH; 174 if ( ((uintptr_t)pVtgHdr->paProbLocsEnd - (uintptr_t)pVtgHdr->paProbLocs) 175 / sizeof(VTGPROBELOC) * sizeof(VTGPROBELOC) 176 != (uintptr_t)pVtgHdr->paProbLocsEnd - (uintptr_t)pVtgHdr->paProbLocs) 177 return VERR_SUPDRV_VTG_NOT_MULTIPLE; 178 if (pbImage && cbImage) 179 { 180 if ((uintptr_t)pVtgHdr->paProbLocs - (uintptr_t)pbImage >= cbImage) 181 return VERR_SUPDRV_VTG_BAD_PTR; 182 if ((uintptr_t)pVtgHdr->paProbLocsEnd - (uintptr_t)pbImage > cbImage) 183 return VERR_SUPDRV_VTG_BAD_PTR; 184 } 185 186 /* 187 * Validate the providers. 188 */ 189 190 191 return VINF_SUCCESS; 277 #undef MY_WITHIN_IMAGE 278 #undef MY_WITHIN_IMAGE_RANGE 192 279 } 193 280
Note:
See TracChangeset
for help on using the changeset viewer.