/* Returns true if any portion of [ptr,ptr+n) over laps with [low,high). */ staticbool overlaps(constunsignedlong ptr, unsignedlong n, unsignedlong low, unsignedlong high)
{ constunsignedlong check_low = ptr; unsignedlong check_high = check_low + n;
/* Does not overlap if entirely above or entirely below. */ if (check_low >= high || check_high <= low) returnfalse;
returntrue;
}
/* Is this address range in the kernel text area? */ staticinlinevoid check_kernel_text_object(constunsignedlong ptr, unsignedlong n, bool to_user)
{ unsignedlong textlow = (unsignedlong)_stext; unsignedlong texthigh = (unsignedlong)_etext; unsignedlong textlow_linear, texthigh_linear;
if (overlaps(ptr, n, textlow, texthigh))
usercopy_abort("kernel text", NULL, to_user, ptr - textlow, n);
/* *Somearchitectureshavevirtualmemorymappingswithasecondary *mappingofthekerneltext,i.e.thereismorethanonevirtual *kerneladdressthatpointstothekernelimage.Itisusually *whenthereisaseparatelinearphysicalmemorymapping,inthat *__pa()isnotjustthereverseof__va().Thiscanbedetected *andchecked:
*/
textlow_linear = (unsignedlong)lm_alias(textlow); /* No different mapping: we're done. */ if (textlow_linear == textlow) return;
/* Check the secondary mapping... */
texthigh_linear = (unsignedlong)lm_alias(texthigh); if (overlaps(ptr, n, textlow_linear, texthigh_linear))
usercopy_abort("linear kernel text", NULL, to_user,
ptr - textlow_linear, n);
}
staticinlinevoid check_bogus_address(constunsignedlong ptr, unsignedlong n, bool to_user)
{ /* Reject if object wraps past end of memory. */ if (ptr + (n - 1) < ptr)
usercopy_abort("wrapped address", NULL, to_user, 0, ptr + n);
/* Reject if NULL or ZERO-allocation. */ if (ZERO_OR_NULL_PTR(ptr))
usercopy_abort("null address", NULL, to_user, ptr, n);
}
/* *Validatesthatthegivenobjectis: *-notbogusaddress *-fullycontainedbystack(orstackframe,whenavailable) *-fullywithinSLABobject(orobjectwhitelistarea,whenavailable) *-notinkerneltext
*/ void __check_object_size(constvoid *ptr, unsignedlong n, bool to_user)
{ /* Skip all tests if size is zero. */ if (!n) return;
/* Check for invalid addresses. */
check_bogus_address((constunsignedlong)ptr, n, to_user);
/* Check for bad stack object. */ switch (check_stack_object(ptr, n)) { case NOT_STACK: /* Object is not touching the current process stack. */ break; case GOOD_FRAME: case GOOD_STACK: /* *Objectiseitherinthecorrectframe(whenit *ispossibletocheck)orjustgenerallyonthe *processstack(whenframecheckingnotavailable).
*/ return; default:
usercopy_abort("process stack", NULL, to_user, #ifdef CONFIG_ARCH_HAS_CURRENT_STACK_POINTER
IS_ENABLED(CONFIG_STACK_GROWSUP) ?
ptr - (void *)current_stack_pointer :
(void *)current_stack_pointer - ptr, #else 0, #endif
n);
}
/* Check for bad heap object. */
check_heap_object(ptr, n, to_user);
/* Check for object in kernel to avoid text exposure. */
check_kernel_text_object((constunsignedlong)ptr, n, to_user);
}
EXPORT_SYMBOL(__check_object_size);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.