aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/list_sort.h
diff options
context:
space:
mode:
authorSami Tolvanen <samitolvanen@google.com>2021-04-08 11:28:34 -0700
committerKees Cook <keescook@chromium.org>2021-04-08 16:04:22 -0700
commit4f0f586bf0c898233d8f316f471a21db2abd522d (patch)
tree3b3ec78051f5a5d2b96f834347355b1b306026ea /include/linux/list_sort.h
parentbpf: disable CFI in dispatcher functions (diff)
downloadlinux-dev-4f0f586bf0c898233d8f316f471a21db2abd522d.tar.xz
linux-dev-4f0f586bf0c898233d8f316f471a21db2abd522d.zip
treewide: Change list_sort to use const pointers
list_sort() internally casts the comparison function passed to it to a different type with constant struct list_head pointers, and uses this pointer to call the functions, which trips indirect call Control-Flow Integrity (CFI) checking. Instead of removing the consts, this change defines the list_cmp_func_t type and changes the comparison function types of all list_sort() callers to use const pointers, thus avoiding type mismatches. Suggested-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Kees Cook <keescook@chromium.org> Tested-by: Nick Desaulniers <ndesaulniers@google.com> Tested-by: Nathan Chancellor <nathan@kernel.org> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/20210408182843.1754385-10-samitolvanen@google.com
Diffstat (limited to 'include/linux/list_sort.h')
-rw-r--r--include/linux/list_sort.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/include/linux/list_sort.h b/include/linux/list_sort.h
index 20f178c24e9d..453105f74e05 100644
--- a/include/linux/list_sort.h
+++ b/include/linux/list_sort.h
@@ -6,8 +6,9 @@
struct list_head;
+typedef int __attribute__((nonnull(2,3))) (*list_cmp_func_t)(void *,
+ const struct list_head *, const struct list_head *);
+
__attribute__((nonnull(2,3)))
-void list_sort(void *priv, struct list_head *head,
- int (*cmp)(void *priv, struct list_head *a,
- struct list_head *b));
+void list_sort(void *priv, struct list_head *head, list_cmp_func_t cmp);
#endif