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
descriptors
array is allocated withmalloc
using the size of asize_t
multiplied by4
times the number ofcount
elements, which should be the number of elements in thecontent
XPC array. However,sizeof(size_t)
is the size of thesize_t
type, 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
count
variable to access thedescriptors
array and set theaccessBeginPointer
,accessDataLength
,mappedBaseAddress
, andmappedLength
values. However, ifcount
is greater than the size of thedescriptors
array, this could result in undefined behavior or memory corruption.Uninitialized memory: the code initializes the
accessBeginPointer
,accessDataLength
,mappedBaseAddress
, andmappedLength
values 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_map
to 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
munmap
to unmap shared memory, but does not free thexpc_object_t
objects or thechunk
array, which could result in a memory leak.
No comments:
Post a Comment