list_debug: Introduce inline wrappers for debug checks

Turn the list debug checking functions __list_*_valid() into inline
functions that wrap the out-of-line functions. Care is taken to ensure
the inline wrappers are always inlined, so that additional compiler
instrumentation (such as sanitizers) does not result in redundant
outlining.

This change is preparation for performing checks in the inline wrappers.

No functional change intended.

Signed-off-by: Marco Elver <elver@google.com>
Link: https://lore.kernel.org/r/20230811151847.1594958-2-elver@google.com
Signed-off-by: Kees Cook <keescook@chromium.org>
This commit is contained in:
Marco Elver 2023-08-11 17:18:39 +02:00 committed by Kees Cook
parent 7a0fd5e167
commit b16c42c8fd
3 changed files with 41 additions and 13 deletions

View File

@ -26,7 +26,7 @@ static inline __must_check bool nvhe_check_data_corruption(bool v)
/* The predicates checked here are taken from lib/list_debug.c. */
bool __list_add_valid(struct list_head *new, struct list_head *prev,
bool __list_add_valid_or_report(struct list_head *new, struct list_head *prev,
struct list_head *next)
{
if (NVHE_CHECK_DATA_CORRUPTION(next->prev != prev) ||
@ -37,7 +37,7 @@ bool __list_add_valid(struct list_head *new, struct list_head *prev,
return true;
}
bool __list_del_entry_valid(struct list_head *entry)
bool __list_del_entry_valid_or_report(struct list_head *entry)
{
struct list_head *prev, *next;

View File

@ -39,10 +39,39 @@ static inline void INIT_LIST_HEAD(struct list_head *list)
}
#ifdef CONFIG_DEBUG_LIST
extern bool __list_add_valid(struct list_head *new,
/*
* Performs the full set of list corruption checks before __list_add().
* On list corruption reports a warning, and returns false.
*/
extern bool __list_add_valid_or_report(struct list_head *new,
struct list_head *prev,
struct list_head *next);
extern bool __list_del_entry_valid(struct list_head *entry);
/*
* Performs list corruption checks before __list_add(). Returns false if a
* corruption is detected, true otherwise.
*/
static __always_inline bool __list_add_valid(struct list_head *new,
struct list_head *prev,
struct list_head *next)
{
return __list_add_valid_or_report(new, prev, next);
}
/*
* Performs the full set of list corruption checks before __list_del_entry().
* On list corruption reports a warning, and returns false.
*/
extern bool __list_del_entry_valid_or_report(struct list_head *entry);
/*
* Performs list corruption checks before __list_del_entry(). Returns false if a
* corruption is detected, true otherwise.
*/
static __always_inline bool __list_del_entry_valid(struct list_head *entry)
{
return __list_del_entry_valid_or_report(entry);
}
#else
static inline bool __list_add_valid(struct list_head *new,
struct list_head *prev,

View File

@ -17,7 +17,7 @@
* attempt).
*/
bool __list_add_valid(struct list_head *new, struct list_head *prev,
bool __list_add_valid_or_report(struct list_head *new, struct list_head *prev,
struct list_head *next)
{
if (CHECK_DATA_CORRUPTION(prev == NULL,
@ -37,9 +37,9 @@ bool __list_add_valid(struct list_head *new, struct list_head *prev,
return true;
}
EXPORT_SYMBOL(__list_add_valid);
EXPORT_SYMBOL(__list_add_valid_or_report);
bool __list_del_entry_valid(struct list_head *entry)
bool __list_del_entry_valid_or_report(struct list_head *entry)
{
struct list_head *prev, *next;
@ -65,6 +65,5 @@ bool __list_del_entry_valid(struct list_head *entry)
return false;
return true;
}
EXPORT_SYMBOL(__list_del_entry_valid);
EXPORT_SYMBOL(__list_del_entry_valid_or_report);