xpc_object_t content = xpc_dictionary_get_value(req, "source");
size_t count = xpc_array_get_count(content); //XENO: count SACI, based on number of array elements sent
size_t descriptors = malloc(sizeof(size_t) * 4 * count);
size_t *accessBeginPointer = &descriptors[count * 0],
*accessDataLength = &descriptors[count * 1],
*mappedBaseAddress = &descriptors[count * 2],
*mappedLength = &descriptors[count * 3];
for(size_t i = 0; i < count; i++) {
accessBeginPointer[i] = accessDataLength[i] =
mappedBaseAddress[i] = mappedLength[i] = 0;
xpc_object_t chunk = xpc_array_get_value(content, i);
if(xpc_get_type(chunk) == XPC_TYPE_DATA) { /*...*/ }
else if(xpc_get_type(chunk) == XPC_TYPE_SHMEM) {
xpc_object_t map = xpc_array_get_value(chunk, 0);
size_t offset = min(xpc_array_get_uint64(chunk, 1), 0xFFF), //XENO: offset ACID
size = xpc_array_get_uint64(chunk, 2); //XENO: size ACID
size_t mapped_address;
size_t mapped_size = xpc_shmem_map(map, &mapped_address); //XENO: mapped_size ACID
size = min(size, mapped_size - offset);
// ...
}
}
// ...
// cleanup
for(size_t index = 0; index < count; i++) {
if(mappedLength[index]) {
munmap(
mappedBaseAddress[index],
mappedLength[index]
);
}
}
free(descriptors);
There are a few potential vulnerabilities or issues with the code:
Memory allocation issue: the
descriptorsarray is allocated withmallocusing the size of asize_tmultiplied by4times the number ofcountelements, which should be the number of elements in thecontentXPC array. However,sizeof(size_t)is the size of thesize_ttype, not the size of a pointer, so the allocated size may not be correct. It should usesizeof(size_t *)instead.Unchecked array access: the code uses the
countvariable to access thedescriptorsarray and set theaccessBeginPointer,accessDataLength,mappedBaseAddress, andmappedLengthvalues. However, ifcountis greater than the size of thedescriptorsarray, this could result in undefined behavior or memory corruption.Uninitialized memory: the code initializes the
accessBeginPointer,accessDataLength,mappedBaseAddress, andmappedLengthvalues to zero for each array element. However, it is unclear if these values are actually used or set correctly later in the code. If they are not set correctly, this could result in unexpected behavior or vulnerabilities.Missing error checking: the code calls
xpc_shmem_mapto map shared memory, but does not check the return value to ensure that the mapping was successful. If the mapping fails, this could result in undefined behavior or vulnerabilities.Memory leak: the code calls
munmapto unmap shared memory, but does not free thexpc_object_tobjects or thechunkarray, which could result in a memory leak.
No comments:
Post a Comment