/*
- * Copyright (c) 2009-2016 Apple Inc. All rights reserved.
+ * Copyright (c) 2009-2020 Apple Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
#include <sys/kdebug.h>
#include <kern/copyout_shim.h>
+#include <kern/zalloc_internal.h>
#undef copyin
#undef copyout
extern int _copyout_atomic32(const uint32_t *u32, char *src);
extern int _copyout_atomic64(const uint64_t *u64, char *src);
-/* On by default, optionally disabled by boot-arg */
-extern boolean_t copyio_zalloc_check;
-
/*
* Types of copies:
*/
if (__improbable((vm_offset_t)kernel_addr < VM_MIN_KERNEL_AND_KEXT_ADDRESS)) {
panic("Invalid copy parameter, copy type: %d, kernel address: %p", copy_type, kernel_addr);
}
- if (__probable(copyio_zalloc_check)) {
- kernel_buf_size = zone_element_size(kernel_addr, NULL);
- if (__improbable(kernel_buf_size && kernel_buf_size < nbytes)) {
+ if (__probable(!zalloc_disable_copyio_check)) {
+ zone_t src_zone = NULL;
+ kernel_buf_size = zone_element_size(kernel_addr, &src_zone);
+ /*
+ * Size of elements in the permanent zone is not saved as a part of the
+ * zone's info
+ */
+ if (__improbable(src_zone && !src_zone->z_permanent &&
+ kernel_buf_size < nbytes)) {
panic("copyio: kernel buffer %p has size %lu < nbytes %lu", kernel_addr, kernel_buf_size, nbytes);
}
}