#include "log_encode_types.h"
#include <sys/param.h>
-#if KERNEL
+#if __has_feature(ptrauth_calls)
+#include <mach/vm_param.h>
+#include <ptrauth.h>
+#endif /* __has_feature(ptrauth_calls) */
+
+#ifdef KERNEL
#define isdigit(ch) (((ch) >= '0') && ((ch) <= '9'))
+extern boolean_t doprnt_hide_pointers;
#endif
static bool
OS_ALWAYS_INLINE
static inline bool
-_os_log_encode_arg(const void *arg, uint16_t arg_len, os_log_value_type_t ctype, bool is_private, os_log_buffer_context_t context)
+_os_log_encode_arg(void *arg, uint16_t arg_len, os_log_value_type_t ctype, bool is_private, os_log_buffer_context_t context)
{
os_log_buffer_value_t content = (os_log_buffer_value_t) &context->buffer->content[context->content_off];
size_t content_sz = sizeof(*content) + arg_len;
#ifndef KERNEL
bool obj_private = true;
#endif
-
+
+#ifdef KERNEL
+ /* scrub kernel pointers */
+ if (doprnt_hide_pointers &&
+ ctype == OS_LOG_BUFFER_VALUE_TYPE_SCALAR &&
+ arg_len >= sizeof(void *)) {
+ unsigned long long value = 0;
+ memcpy(&value, arg, arg_len);
+
+#if __has_feature(ptrauth_calls)
+ /**
+ * Strip out the pointer authentication code before
+ * checking whether the pointer is a kernel address.
+ */
+ value = (unsigned long long)VM_KERNEL_STRIP_PTR(value);
+#endif /* __has_feature(ptrauth_calls) */
+
+ if (value >= VM_MIN_KERNEL_AND_KEXT_ADDRESS && value <= VM_MAX_KERNEL_ADDRESS) {
+ is_private = true;
+ bzero(arg, arg_len);
+ }
+ }
+#endif
+
content->type = ctype;
content->flags = (is_private ? OS_LOG_CONTENT_FLAG_PRIVATE : 0);