All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: William Breathitt Gray <william.gray@linaro.org>
Cc: linux-iio@vger.kernel.org,
	Nick Desaulniers <ndesaulniers@google.com>,
	Tom Rix <trix@redhat.com>, Kees Cook <keescook@chromium.org>,
	Sami Tolvanen <samitolvanen@google.com>,
	llvm@lists.linux.dev, linux-kernel@vger.kernel.org,
	patches@lists.linux.dev, Nathan Chancellor <nathan@kernel.org>,
	Vignesh Raghavendra <vigneshr@ti.com>,
	Julien Panis <jpanis@baylibre.com>,
	linux-omap@vger.kernel.org
Subject: [PATCH 3/4] counter: ti-ecap-capture: Adjust final parameter type of ecap_cnt_pol_{read,write}()
Date: Wed,  2 Nov 2022 10:22:16 -0700	[thread overview]
Message-ID: <20221102172217.2860740-3-nathan@kernel.org> (raw)
In-Reply-To: <20221102172217.2860740-1-nathan@kernel.org>

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/ti-ecap-capture.c:384:2: error: incompatible function pointer types initializing 'int (*)(struct counter_device *, struct counter_signal *, size_t, u32 *)' (aka 'int (*)(struct counter_device *, struct counter_signal *, unsigned long, unsigned int *)') with an expression of type 'int (struct counter_device *, struct counter_signal *, size_t, enum counter_signal_polarity *)' (aka 'int (struct counter_device *, struct counter_signal *, unsigned long, enum counter_signal_polarity *)') [-Werror,-Wincompatible-function-pointer-types-strict]
          COUNTER_COMP_ARRAY_POLARITY(ecap_cnt_pol_read, ecap_cnt_pol_write, ecap_cnt_pol_array),
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ./include/linux/counter.h:627:27: note: expanded from macro 'COUNTER_COMP_ARRAY_POLARITY'
          .signal_array_u32_read = (_read), \
                                  ^~~~~~~
  drivers/counter/ti-ecap-capture.c:384:2: error: incompatible function pointer types initializing 'int (*)(struct counter_device *, struct counter_signal *, size_t, u32)' (aka 'int (*)(struct counter_device *, struct counter_signal *, unsigned long, unsigned int)') with an expression of type 'int (struct counter_device *, struct counter_signal *, size_t, enum counter_signal_polarity)' (aka 'int (struct counter_device *, struct counter_signal *, unsigned long, enum counter_signal_polarity)') [-Werror,-Wincompatible-function-pointer-types-strict]
          COUNTER_COMP_ARRAY_POLARITY(ecap_cnt_pol_read, ecap_cnt_pol_write, ecap_cnt_pol_array),
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ./include/linux/counter.h:628:28: note: expanded from macro 'COUNTER_COMP_ARRAY_POLARITY'
          .signal_array_u32_write = (_write), \
                                    ^~~~~~~~
  2 errors generated.

->signal_array_u32_read() and ->signal_array_u32_write() in 'struct
counter_comp' expect a final parameter type of 'u32 *' and 'u32'
respectively, not 'enum counter_signal_polarity *' and 'enum
counter_signal_polarity'. Adjust the final parameter type of
ecap_cnt_pol_{read,write}() 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@google.com>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
Cc: Vignesh Raghavendra <vigneshr@ti.com>
Cc: Julien Panis <jpanis@baylibre.com>
Cc: linux-omap@vger.kernel.org
---
 drivers/counter/ti-ecap-capture.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/counter/ti-ecap-capture.c b/drivers/counter/ti-ecap-capture.c
index 96e5d1f271b8..49e349680884 100644
--- a/drivers/counter/ti-ecap-capture.c
+++ b/drivers/counter/ti-ecap-capture.c
@@ -234,7 +234,7 @@ static int ecap_cnt_clk_get_freq(struct counter_device *counter,
 
 static int ecap_cnt_pol_read(struct counter_device *counter,
 			     struct counter_signal *signal,
-			     size_t idx, enum counter_signal_polarity *pol)
+			     size_t idx, u32 *pol)
 {
 	struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
 	int bitval;
@@ -250,7 +250,7 @@ static int ecap_cnt_pol_read(struct counter_device *counter,
 
 static int ecap_cnt_pol_write(struct counter_device *counter,
 			      struct counter_signal *signal,
-			      size_t idx, enum counter_signal_polarity pol)
+			      size_t idx, u32 pol)
 {
 	struct ecap_cnt_dev *ecap_dev = counter_priv(counter);
 
-- 
2.38.1


  parent reply	other threads:[~2022-11-02 17:22 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02 17:22 [PATCH 1/4] counter: Adjust final parameter type in function and signal callbacks Nathan Chancellor
2022-11-02 17:22 ` Nathan Chancellor
2022-11-02 17:22 ` [PATCH 2/4] counter: stm32-timer-cnt: Adjust final parameter type of stm32_count_direction_read() Nathan Chancellor
2022-11-02 17:22   ` Nathan Chancellor
2022-11-02 17:22 ` Nathan Chancellor [this message]
2022-11-02 17:22 ` [PATCH 4/4] counter: 104-quad-8: Adjust final parameter type of certain callback functions Nathan Chancellor
2022-11-02 19:21 ` [PATCH 1/4] counter: Adjust final parameter type in function and signal callbacks Kees Cook
2022-11-02 19:21   ` Kees Cook
2022-11-02 20:23   ` Nathan Chancellor
2022-11-02 20:23     ` Nathan Chancellor
2022-11-02 21:30     ` William Breathitt Gray
2022-11-02 21:30       ` William Breathitt Gray
2022-11-02 22:02     ` Kees Cook
2022-11-02 22:02       ` Kees Cook
2022-11-02 23:22     ` Kees Cook
2022-11-02 23:22       ` Kees Cook
2022-11-03  3:38       ` William Breathitt Gray
2022-11-03  3:38         ` William Breathitt Gray

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221102172217.2860740-3-nathan@kernel.org \
    --to=nathan@kernel.org \
    --cc=jpanis@baylibre.com \
    --cc=keescook@chromium.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=ndesaulniers@google.com \
    --cc=patches@lists.linux.dev \
    --cc=samitolvanen@google.com \
    --cc=trix@redhat.com \
    --cc=vigneshr@ti.com \
    --cc=william.gray@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.