[PATCH 2/4] counter: stm32-timer-cnt: Adjust final parameter type of stm32_count_direction_read()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: https://github.com/ClangBuiltLinux/linux/issues/1750
Reported-by: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
Signed-off-by: Nathan Chancellor <nathan@xxxxxxxxxx>
---
Cc: Fabrice Gasnier <fabrice.gasnier@xxxxxxxxxxx>
Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
Cc: linux-stm32@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
---
 drivers/counter/stm32-timer-cnt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c
index ece55113ba85..4062296f4bd4 100644
--- a/drivers/counter/stm32-timer-cnt.c
+++ b/drivers/counter/stm32-timer-cnt.c
@@ -137,7 +137,7 @@ static int stm32_count_function_write(struct counter_device *counter,
 
 static int stm32_count_direction_read(struct counter_device *counter,
 				      struct counter_count *count,
-				      enum counter_count_direction *direction)
+				      u32 *direction)
 {
 	struct stm32_timer_cnt *const priv = counter_priv(counter);
 	u32 cr1;
-- 
2.38.1




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux