Skip to content

Commit b16c42c

Browse files
melverkees
authored andcommitted
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>
1 parent 7a0fd5e commit b16c42c

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

arch/arm64/kvm/hyp/nvhe/list_debug.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ static inline __must_check bool nvhe_check_data_corruption(bool v)
2626

2727
/* The predicates checked here are taken from lib/list_debug.c. */
2828

29-
bool __list_add_valid(struct list_head *new, struct list_head *prev,
30-
struct list_head *next)
29+
bool __list_add_valid_or_report(struct list_head *new, struct list_head *prev,
30+
struct list_head *next)
3131
{
3232
if (NVHE_CHECK_DATA_CORRUPTION(next->prev != prev) ||
3333
NVHE_CHECK_DATA_CORRUPTION(prev->next != next) ||
@@ -37,7 +37,7 @@ bool __list_add_valid(struct list_head *new, struct list_head *prev,
3737
return true;
3838
}
3939

40-
bool __list_del_entry_valid(struct list_head *entry)
40+
bool __list_del_entry_valid_or_report(struct list_head *entry)
4141
{
4242
struct list_head *prev, *next;
4343

include/linux/list.h

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,39 @@ static inline void INIT_LIST_HEAD(struct list_head *list)
3939
}
4040

4141
#ifdef CONFIG_DEBUG_LIST
42-
extern bool __list_add_valid(struct list_head *new,
43-
struct list_head *prev,
44-
struct list_head *next);
45-
extern bool __list_del_entry_valid(struct list_head *entry);
42+
/*
43+
* Performs the full set of list corruption checks before __list_add().
44+
* On list corruption reports a warning, and returns false.
45+
*/
46+
extern bool __list_add_valid_or_report(struct list_head *new,
47+
struct list_head *prev,
48+
struct list_head *next);
49+
50+
/*
51+
* Performs list corruption checks before __list_add(). Returns false if a
52+
* corruption is detected, true otherwise.
53+
*/
54+
static __always_inline bool __list_add_valid(struct list_head *new,
55+
struct list_head *prev,
56+
struct list_head *next)
57+
{
58+
return __list_add_valid_or_report(new, prev, next);
59+
}
60+
61+
/*
62+
* Performs the full set of list corruption checks before __list_del_entry().
63+
* On list corruption reports a warning, and returns false.
64+
*/
65+
extern bool __list_del_entry_valid_or_report(struct list_head *entry);
66+
67+
/*
68+
* Performs list corruption checks before __list_del_entry(). Returns false if a
69+
* corruption is detected, true otherwise.
70+
*/
71+
static __always_inline bool __list_del_entry_valid(struct list_head *entry)
72+
{
73+
return __list_del_entry_valid_or_report(entry);
74+
}
4675
#else
4776
static inline bool __list_add_valid(struct list_head *new,
4877
struct list_head *prev,

lib/list_debug.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
* attempt).
1818
*/
1919

20-
bool __list_add_valid(struct list_head *new, struct list_head *prev,
21-
struct list_head *next)
20+
bool __list_add_valid_or_report(struct list_head *new, struct list_head *prev,
21+
struct list_head *next)
2222
{
2323
if (CHECK_DATA_CORRUPTION(prev == NULL,
2424
"list_add corruption. prev is NULL.\n") ||
@@ -37,9 +37,9 @@ bool __list_add_valid(struct list_head *new, struct list_head *prev,
3737

3838
return true;
3939
}
40-
EXPORT_SYMBOL(__list_add_valid);
40+
EXPORT_SYMBOL(__list_add_valid_or_report);
4141

42-
bool __list_del_entry_valid(struct list_head *entry)
42+
bool __list_del_entry_valid_or_report(struct list_head *entry)
4343
{
4444
struct list_head *prev, *next;
4545

@@ -65,6 +65,5 @@ bool __list_del_entry_valid(struct list_head *entry)
6565
return false;
6666

6767
return true;
68-
6968
}
70-
EXPORT_SYMBOL(__list_del_entry_valid);
69+
EXPORT_SYMBOL(__list_del_entry_valid_or_report);

0 commit comments

Comments
 (0)