mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-16 09:13:55 +08:00
debugobjects: Allow debug_obj_descr to be const
The debugobject core could be slightly harder to corrupt if the debug_obj_descr would be a pointer to const memory. Depending on the architecture, const data structures are placed into read-only memory and thus are harder to corrupt or hijack. This descriptor is used to fix up stuff like timers and workqueues when core kernel data structures are busted, so moving the descriptors to read-only memory will make debugobjects more resilient to something going wrong and then corrupting the function pointers inside struct debug_obj_descr. Signed-off-by: Stephen Boyd <swboyd@chromium.org> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20200815004027.2046113-2-swboyd@chromium.org
This commit is contained in:
parent
805c6d3c19
commit
aedcade6f4
@ -30,7 +30,7 @@ struct debug_obj {
|
||||
enum debug_obj_state state;
|
||||
unsigned int astate;
|
||||
void *object;
|
||||
struct debug_obj_descr *descr;
|
||||
const struct debug_obj_descr *descr;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -64,14 +64,14 @@ struct debug_obj_descr {
|
||||
};
|
||||
|
||||
#ifdef CONFIG_DEBUG_OBJECTS
|
||||
extern void debug_object_init (void *addr, struct debug_obj_descr *descr);
|
||||
extern void debug_object_init (void *addr, const struct debug_obj_descr *descr);
|
||||
extern void
|
||||
debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr);
|
||||
extern int debug_object_activate (void *addr, struct debug_obj_descr *descr);
|
||||
extern void debug_object_deactivate(void *addr, struct debug_obj_descr *descr);
|
||||
extern void debug_object_destroy (void *addr, struct debug_obj_descr *descr);
|
||||
extern void debug_object_free (void *addr, struct debug_obj_descr *descr);
|
||||
extern void debug_object_assert_init(void *addr, struct debug_obj_descr *descr);
|
||||
debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr);
|
||||
extern int debug_object_activate (void *addr, const struct debug_obj_descr *descr);
|
||||
extern void debug_object_deactivate(void *addr, const struct debug_obj_descr *descr);
|
||||
extern void debug_object_destroy (void *addr, const struct debug_obj_descr *descr);
|
||||
extern void debug_object_free (void *addr, const struct debug_obj_descr *descr);
|
||||
extern void debug_object_assert_init(void *addr, const struct debug_obj_descr *descr);
|
||||
|
||||
/*
|
||||
* Active state:
|
||||
@ -79,26 +79,26 @@ extern void debug_object_assert_init(void *addr, struct debug_obj_descr *descr);
|
||||
* - Must return to 0 before deactivation.
|
||||
*/
|
||||
extern void
|
||||
debug_object_active_state(void *addr, struct debug_obj_descr *descr,
|
||||
debug_object_active_state(void *addr, const struct debug_obj_descr *descr,
|
||||
unsigned int expect, unsigned int next);
|
||||
|
||||
extern void debug_objects_early_init(void);
|
||||
extern void debug_objects_mem_init(void);
|
||||
#else
|
||||
static inline void
|
||||
debug_object_init (void *addr, struct debug_obj_descr *descr) { }
|
||||
debug_object_init (void *addr, const struct debug_obj_descr *descr) { }
|
||||
static inline void
|
||||
debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr) { }
|
||||
debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr) { }
|
||||
static inline int
|
||||
debug_object_activate (void *addr, struct debug_obj_descr *descr) { return 0; }
|
||||
debug_object_activate (void *addr, const struct debug_obj_descr *descr) { return 0; }
|
||||
static inline void
|
||||
debug_object_deactivate(void *addr, struct debug_obj_descr *descr) { }
|
||||
debug_object_deactivate(void *addr, const struct debug_obj_descr *descr) { }
|
||||
static inline void
|
||||
debug_object_destroy (void *addr, struct debug_obj_descr *descr) { }
|
||||
debug_object_destroy (void *addr, const struct debug_obj_descr *descr) { }
|
||||
static inline void
|
||||
debug_object_free (void *addr, struct debug_obj_descr *descr) { }
|
||||
debug_object_free (void *addr, const struct debug_obj_descr *descr) { }
|
||||
static inline void
|
||||
debug_object_assert_init(void *addr, struct debug_obj_descr *descr) { }
|
||||
debug_object_assert_init(void *addr, const struct debug_obj_descr *descr) { }
|
||||
|
||||
static inline void debug_objects_early_init(void) { }
|
||||
static inline void debug_objects_mem_init(void) { }
|
||||
|
@ -90,7 +90,7 @@ static int debug_objects_pool_size __read_mostly
|
||||
= ODEBUG_POOL_SIZE;
|
||||
static int debug_objects_pool_min_level __read_mostly
|
||||
= ODEBUG_POOL_MIN_LEVEL;
|
||||
static struct debug_obj_descr *descr_test __read_mostly;
|
||||
static const struct debug_obj_descr *descr_test __read_mostly;
|
||||
static struct kmem_cache *obj_cache __read_mostly;
|
||||
|
||||
/*
|
||||
@ -223,7 +223,7 @@ static struct debug_obj *__alloc_object(struct hlist_head *list)
|
||||
* Must be called with interrupts disabled.
|
||||
*/
|
||||
static struct debug_obj *
|
||||
alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr)
|
||||
alloc_object(void *addr, struct debug_bucket *b, const struct debug_obj_descr *descr)
|
||||
{
|
||||
struct debug_percpu_free *percpu_pool = this_cpu_ptr(&percpu_obj_pool);
|
||||
struct debug_obj *obj;
|
||||
@ -475,7 +475,7 @@ static struct debug_bucket *get_bucket(unsigned long addr)
|
||||
|
||||
static void debug_print_object(struct debug_obj *obj, char *msg)
|
||||
{
|
||||
struct debug_obj_descr *descr = obj->descr;
|
||||
const struct debug_obj_descr *descr = obj->descr;
|
||||
static int limit;
|
||||
|
||||
if (limit < 5 && descr != descr_test) {
|
||||
@ -529,7 +529,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
|
||||
}
|
||||
|
||||
static void
|
||||
__debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)
|
||||
__debug_object_init(void *addr, const struct debug_obj_descr *descr, int onstack)
|
||||
{
|
||||
enum debug_obj_state state;
|
||||
bool check_stack = false;
|
||||
@ -587,7 +587,7 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)
|
||||
* @addr: address of the object
|
||||
* @descr: pointer to an object specific debug description structure
|
||||
*/
|
||||
void debug_object_init(void *addr, struct debug_obj_descr *descr)
|
||||
void debug_object_init(void *addr, const struct debug_obj_descr *descr)
|
||||
{
|
||||
if (!debug_objects_enabled)
|
||||
return;
|
||||
@ -602,7 +602,7 @@ EXPORT_SYMBOL_GPL(debug_object_init);
|
||||
* @addr: address of the object
|
||||
* @descr: pointer to an object specific debug description structure
|
||||
*/
|
||||
void debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr)
|
||||
void debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr)
|
||||
{
|
||||
if (!debug_objects_enabled)
|
||||
return;
|
||||
@ -617,7 +617,7 @@ EXPORT_SYMBOL_GPL(debug_object_init_on_stack);
|
||||
* @descr: pointer to an object specific debug description structure
|
||||
* Returns 0 for success, -EINVAL for check failed.
|
||||
*/
|
||||
int debug_object_activate(void *addr, struct debug_obj_descr *descr)
|
||||
int debug_object_activate(void *addr, const struct debug_obj_descr *descr)
|
||||
{
|
||||
enum debug_obj_state state;
|
||||
struct debug_bucket *db;
|
||||
@ -695,7 +695,7 @@ EXPORT_SYMBOL_GPL(debug_object_activate);
|
||||
* @addr: address of the object
|
||||
* @descr: pointer to an object specific debug description structure
|
||||
*/
|
||||
void debug_object_deactivate(void *addr, struct debug_obj_descr *descr)
|
||||
void debug_object_deactivate(void *addr, const struct debug_obj_descr *descr)
|
||||
{
|
||||
struct debug_bucket *db;
|
||||
struct debug_obj *obj;
|
||||
@ -747,7 +747,7 @@ EXPORT_SYMBOL_GPL(debug_object_deactivate);
|
||||
* @addr: address of the object
|
||||
* @descr: pointer to an object specific debug description structure
|
||||
*/
|
||||
void debug_object_destroy(void *addr, struct debug_obj_descr *descr)
|
||||
void debug_object_destroy(void *addr, const struct debug_obj_descr *descr)
|
||||
{
|
||||
enum debug_obj_state state;
|
||||
struct debug_bucket *db;
|
||||
@ -797,7 +797,7 @@ EXPORT_SYMBOL_GPL(debug_object_destroy);
|
||||
* @addr: address of the object
|
||||
* @descr: pointer to an object specific debug description structure
|
||||
*/
|
||||
void debug_object_free(void *addr, struct debug_obj_descr *descr)
|
||||
void debug_object_free(void *addr, const struct debug_obj_descr *descr)
|
||||
{
|
||||
enum debug_obj_state state;
|
||||
struct debug_bucket *db;
|
||||
@ -838,7 +838,7 @@ EXPORT_SYMBOL_GPL(debug_object_free);
|
||||
* @addr: address of the object
|
||||
* @descr: pointer to an object specific debug description structure
|
||||
*/
|
||||
void debug_object_assert_init(void *addr, struct debug_obj_descr *descr)
|
||||
void debug_object_assert_init(void *addr, const struct debug_obj_descr *descr)
|
||||
{
|
||||
struct debug_bucket *db;
|
||||
struct debug_obj *obj;
|
||||
@ -886,7 +886,7 @@ EXPORT_SYMBOL_GPL(debug_object_assert_init);
|
||||
* @next: state to move to if expected state is found
|
||||
*/
|
||||
void
|
||||
debug_object_active_state(void *addr, struct debug_obj_descr *descr,
|
||||
debug_object_active_state(void *addr, const struct debug_obj_descr *descr,
|
||||
unsigned int expect, unsigned int next)
|
||||
{
|
||||
struct debug_bucket *db;
|
||||
@ -934,7 +934,7 @@ EXPORT_SYMBOL_GPL(debug_object_active_state);
|
||||
static void __debug_check_no_obj_freed(const void *address, unsigned long size)
|
||||
{
|
||||
unsigned long flags, oaddr, saddr, eaddr, paddr, chunks;
|
||||
struct debug_obj_descr *descr;
|
||||
const struct debug_obj_descr *descr;
|
||||
enum debug_obj_state state;
|
||||
struct debug_bucket *db;
|
||||
struct hlist_node *tmp;
|
||||
@ -1052,7 +1052,7 @@ struct self_test {
|
||||
unsigned long dummy2[3];
|
||||
};
|
||||
|
||||
static __initdata struct debug_obj_descr descr_type_test;
|
||||
static __initconst const struct debug_obj_descr descr_type_test;
|
||||
|
||||
static bool __init is_static_object(void *addr)
|
||||
{
|
||||
@ -1177,7 +1177,7 @@ out:
|
||||
return res;
|
||||
}
|
||||
|
||||
static __initdata struct debug_obj_descr descr_type_test = {
|
||||
static __initconst const struct debug_obj_descr descr_type_test = {
|
||||
.name = "selftest",
|
||||
.is_static_object = is_static_object,
|
||||
.fixup_init = fixup_init,
|
||||
|
Loading…
Reference in New Issue
Block a user