Skip to content

Commit c176716

Browse files
nathanchanceintel-lab-lkp
authored andcommitted
counter: stm32-timer-cnt: Adjust final parameter type of stm32_count_direction_read()
With clang's kernel control flow integrity (kCFI, CONFIG_CFI_CLANG), indirect call targets are validated against the expected function pointer prototype to make sure the call target is valid to help mitigate ROP attacks. If they are not identical, there is a failure at run time, which manifests as either a kernel panic or thread getting killed. A proposed warning in clang aims to catch these at compile time, which reveals: drivers/counter/stm32-timer-cnt.c:220:2: error: incompatible function pointer types initializing 'int (*)(struct counter_device *, struct counter_count *, u32 *)' (aka 'int (*)(struct counter_device *, struct counter_count *, unsigned int *)') with an expression of type 'int (struct counter_device *, struct counter_count *, enum counter_count_direction *)' [-Werror,-Wincompatible-function-pointer-types-strict] COUNTER_COMP_DIRECTION(stm32_count_direction_read), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./include/linux/counter.h:596:20: note: expanded from macro 'COUNTER_COMP_DIRECTION' .count_u32_read = (_read), \ ^~~~~~~ 1 error generated ->count_u32_read() in 'struct counter_comp' expects a return type of 'u32 *', not 'enum counter_count_direction *'. Adjust the final parameter type of stm32_count_direction_read() to match the prototype's to resolve the warning and CFI failure. Link: ClangBuiltLinux#1750 Reported-by: Sami Tolvanen <[email protected]> Signed-off-by: Nathan Chancellor <[email protected]>
1 parent cf88a10 commit c176716

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/counter/stm32-timer-cnt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static int stm32_count_function_write(struct counter_device *counter,
137137

138138
static int stm32_count_direction_read(struct counter_device *counter,
139139
struct counter_count *count,
140-
enum counter_count_direction *direction)
140+
u32 *direction)
141141
{
142142
struct stm32_timer_cnt *const priv = counter_priv(counter);
143143
u32 cr1;

0 commit comments

Comments
 (0)