History

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.

Stephen Boyd committed 6 years ago

Commit aedcade1 parent 805c6d32 files · +31 −31Browse files

Showing the changes to lib/debugobjects.c (1 of 2 files). Show all

Unified · Split

lib/debugobjects.c+15−15
@@ -90,7 +90,7 @@ static int debug_objects_pool_size __read_mostly · 89 unmodified lines
9090 = ODEBUG_POOL_SIZE;
9191 static int debug_objects_pool_min_level __read_mostly
9292 = ODEBUG_POOL_MIN_LEVEL;
93−static struct debug_obj_descr *descr_test __read_mostly;
93+static const struct debug_obj_descr *descr_test __read_mostly;
9494 static struct kmem_cache *obj_cache __read_mostly;
9595
9696 /*
@@ -223,7 +223,7 @@ static struct debug_obj *__alloc_object(struct hlist_head *list) · 126 unmodified lines
223223 * Must be called with interrupts disabled.
224224 */
225225 static struct debug_obj *
226−alloc_object(void *addr, struct debug_bucket *b, struct debug_obj_descr *descr)
226+alloc_object(void *addr, struct debug_bucket *b, const struct debug_obj_descr *descr)
227227 {
228228 struct debug_percpu_free *percpu_pool = this_cpu_ptr(&percpu_obj_pool);
229229 struct debug_obj *obj;
@@ -475,7 +475,7 @@ static struct debug_bucket *get_bucket(unsigned long addr) · 245 unmodified lines
475475
476476 static void debug_print_object(struct debug_obj *obj, char *msg)
477477 {
478− struct debug_obj_descr *descr = obj->descr;
478+ const struct debug_obj_descr *descr = obj->descr;
479479 static int limit;
480480
481481 if (limit < 5 && descr != descr_test) {
@@ -529,7 +529,7 @@ static void debug_object_is_on_stack(void *addr, int onstack) · 47 unmodified lines
529529 }
530530
531531 static void
532−__debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack)
532+__debug_object_init(void *addr, const struct debug_obj_descr *descr, int onstack)
533533 {
534534 enum debug_obj_state state;
535535 bool check_stack = false;
@@ -587,7 +587,7 @@ __debug_object_init(void *addr, struct debug_obj_descr *descr, int onstack) · 51 unmodified lines
587587 * @addr: address of the object
588588 * @descr: pointer to an object specific debug description structure
589589 */
590−void debug_object_init(void *addr, struct debug_obj_descr *descr)
590+void debug_object_init(void *addr, const struct debug_obj_descr *descr)
591591 {
592592 if (!debug_objects_enabled)
593593 return;
@@ -602,7 +602,7 @@ EXPORT_SYMBOL_GPL(debug_object_init); · 8 unmodified lines
602602 * @addr: address of the object
603603 * @descr: pointer to an object specific debug description structure
604604 */
605−void debug_object_init_on_stack(void *addr, struct debug_obj_descr *descr)
605+void debug_object_init_on_stack(void *addr, const struct debug_obj_descr *descr)
606606 {
607607 if (!debug_objects_enabled)
608608 return;
@@ -617,7 +617,7 @@ EXPORT_SYMBOL_GPL(debug_object_init_on_stack); · 8 unmodified lines
617617 * @descr: pointer to an object specific debug description structure
618618 * Returns 0 for success, -EINVAL for check failed.
619619 */
620−int debug_object_activate(void *addr, struct debug_obj_descr *descr)
620+int debug_object_activate(void *addr, const struct debug_obj_descr *descr)
621621 {
622622 enum debug_obj_state state;
623623 struct debug_bucket *db;
@@ -695,7 +695,7 @@ EXPORT_SYMBOL_GPL(debug_object_activate); · 71 unmodified lines
695695 * @addr: address of the object
696696 * @descr: pointer to an object specific debug description structure
697697 */
698−void debug_object_deactivate(void *addr, struct debug_obj_descr *descr)
698+void debug_object_deactivate(void *addr, const struct debug_obj_descr *descr)
699699 {
700700 struct debug_bucket *db;
701701 struct debug_obj *obj;
@@ -747,7 +747,7 @@ EXPORT_SYMBOL_GPL(debug_object_deactivate); · 45 unmodified lines
747747 * @addr: address of the object
748748 * @descr: pointer to an object specific debug description structure
749749 */
750−void debug_object_destroy(void *addr, struct debug_obj_descr *descr)
750+void debug_object_destroy(void *addr, const struct debug_obj_descr *descr)
751751 {
752752 enum debug_obj_state state;
753753 struct debug_bucket *db;
@@ -797,7 +797,7 @@ EXPORT_SYMBOL_GPL(debug_object_destroy); · 43 unmodified lines
797797 * @addr: address of the object
798798 * @descr: pointer to an object specific debug description structure
799799 */
800−void debug_object_free(void *addr, struct debug_obj_descr *descr)
800+void debug_object_free(void *addr, const struct debug_obj_descr *descr)
801801 {
802802 enum debug_obj_state state;
803803 struct debug_bucket *db;
@@ -838,7 +838,7 @@ EXPORT_SYMBOL_GPL(debug_object_free); · 34 unmodified lines
838838 * @addr: address of the object
839839 * @descr: pointer to an object specific debug description structure
840840 */
841−void debug_object_assert_init(void *addr, struct debug_obj_descr *descr)
841+void debug_object_assert_init(void *addr, const struct debug_obj_descr *descr)
842842 {
843843 struct debug_bucket *db;
844844 struct debug_obj *obj;
@@ -886,7 +886,7 @@ EXPORT_SYMBOL_GPL(debug_object_assert_init); · 41 unmodified lines
886886 * @next: state to move to if expected state is found
887887 */
888888 void
889−debug_object_active_state(void *addr, struct debug_obj_descr *descr,
889+debug_object_active_state(void *addr, const struct debug_obj_descr *descr,
890890 unsigned int expect, unsigned int next)
891891 {
892892 struct debug_bucket *db;
@@ -934,7 +934,7 @@ EXPORT_SYMBOL_GPL(debug_object_active_state); · 41 unmodified lines
934934 static void __debug_check_no_obj_freed(const void *address, unsigned long size)
935935 {
936936 unsigned long flags, oaddr, saddr, eaddr, paddr, chunks;
937− struct debug_obj_descr *descr;
937+ const struct debug_obj_descr *descr;
938938 enum debug_obj_state state;
939939 struct debug_bucket *db;
940940 struct hlist_node *tmp;
@@ -1052,7 +1052,7 @@ struct self_test { · 111 unmodified lines
10521052 unsigned long dummy2[3];
10531053 };
10541054
1055−static __initdata struct debug_obj_descr descr_type_test;
1055+static __initconst const struct debug_obj_descr descr_type_test;
10561056
10571057 static bool __init is_static_object(void *addr)
10581058 {
@@ -1177,7 +1177,7 @@ out: · 118 unmodified lines
11771177 return res;
11781178 }
11791179
1180−static __initdata struct debug_obj_descr descr_type_test = {
1180+static __initconst const struct debug_obj_descr descr_type_test = {
11811181 .name = "selftest",
11821182 .is_static_object = is_static_object,
11831183 .fixup_init = fixup_init,