[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221102172217.2860740-2-nathan@kernel.org>
Date: Wed, 2 Nov 2022 10:22:15 -0700
From: Nathan Chancellor <nathan@...nel.org>
To: William Breathitt Gray <william.gray@...aro.org>
Cc: linux-iio@...r.kernel.org,
Nick Desaulniers <ndesaulniers@...gle.com>,
Tom Rix <trix@...hat.com>, Kees Cook <keescook@...omium.org>,
Sami Tolvanen <samitolvanen@...gle.com>, llvm@...ts.linux.dev,
linux-kernel@...r.kernel.org, patches@...ts.linux.dev,
Nathan Chancellor <nathan@...nel.org>,
Fabrice Gasnier <fabrice.gasnier@...s.st.com>,
linux-arm-kernel@...ts.infradead.org,
linux-stm32@...md-mailman.stormreply.com
Subject: [PATCH 2/4] 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: https://github.com/ClangBuiltLinux/linux/issues/1750
Reported-by: Sami Tolvanen <samitolvanen@...gle.com>
Signed-off-by: Nathan Chancellor <nathan@...nel.org>
---
Cc: Fabrice Gasnier <fabrice.gasnier@...s.st.com>
Cc: linux-arm-kernel@...ts.infradead.org
Cc: linux-stm32@...md-mailman.stormreply.com
---
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
Powered by blists - more mailing lists