From patchwork Wed Nov 2 17:22:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 14406 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp37439wru; Wed, 2 Nov 2022 10:24:00 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7s85OkaxCYgKO6glgG91c6LSFiEZlfZnmFTjq+3vdmhxF0eQ7zEkOQ8g/uid8neINR4Rh4 X-Received: by 2002:a05:6402:428d:b0:460:b26c:82a5 with SMTP id g13-20020a056402428d00b00460b26c82a5mr26566078edc.66.1667409840269; Wed, 02 Nov 2022 10:24:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667409840; cv=none; d=google.com; s=arc-20160816; b=WLMhNhv+rScILtqJN6kaSU2hjATa8dFDl7c+k1OlFTEJB7BYnAWBaHfzG4RvjuvK4Q 0VecQHIsUyzGMV/8Pl0pxl5OxEHBNmjcYJLUY6Re0BHkN4Mt/zc9bF61RErHlFeR1Xxa nNmGrE/oxSbzvW6N17grqW2nDtXKOsv49p/+VJDflIqp3FeHHQsFp0hcELmbsMXsBzAU 8mDY2Pq2MMXOj2FtgzSmFpd0N/X5Sbgk8Gw9MhTj9Hel/doVfDWSXC9cYbT28axBdw3t qRq0WmO4YdGM3kwIX8ht/JL4VwwV2fxA2aHyycnZj2sKJbj/F06xEsMBdfSbfUedI58Y DDkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=K08Fol9w96Gv9+DiMU5MgDQvF5Zcxv71n+OqvgvBg6w=; b=Xcr5C6x2nQ/ixCKk0Eclp6GmbQF15TBIcIBMa7C+qIDy7sVsUzNOOvS4UrnPgALhjE qui6guRPoiejg8pVD/8mWsoHGhXyl6SfQdzKBPxqIopTN2hpuZnNf8bQnM3aqW0XWvTN HUBVmnoV+x+d2Xl8S4r/uovg+rZde2oJrYOQltuyKViujlyJwhtwZkwYZfETu9bhiwO+ BCCOuMN1/M0tGYQgEGCwyQjJ+tN5qXMrzGSaQ1eHXBN5xc9r7YPA7PXQH/+8v18wdH8w DhOtDTrVds2PAsb+Bz+CDTMpZgwtuYAHZcd2RFpzINnfxrT2BIBTgXw+LyinIOdvGvMt 464g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fwYlxiZd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w1-20020a056402268100b0045d292ef641si17954812edd.493.2022.11.02.10.23.35; Wed, 02 Nov 2022 10:24:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fwYlxiZd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231366AbiKBRWq (ORCPT + 99 others); Wed, 2 Nov 2022 13:22:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230165AbiKBRWj (ORCPT ); Wed, 2 Nov 2022 13:22:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CD7E248D2; Wed, 2 Nov 2022 10:22:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C61CDB8240C; Wed, 2 Nov 2022 17:22:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54B70C433C1; Wed, 2 Nov 2022 17:22:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667409755; bh=JlfqGwLsDwKmCS1oBu/kDA5a6tTjFIObU3wa7YVmC/s=; h=From:To:Cc:Subject:Date:From; b=fwYlxiZd1S6Xehhl+9gWwUABNVhSHD8WbO/1WqVXCxG5SFaBD9iKXCgIip2P+Fec2 WPqIW2QHMTt/2LRGqnD46V2AzVqK0dEhtDe/8CxcKsM7EvEKl+yM3AsRo8QnOHf8W/ N79bzAfXx0BQ1FiHuKoC8dNJrF9C4ziBLvvZa5bt9LJuslxaV81eM8XdepDvjH185m eiljRfsxrYmoj+Gb3lXzWHS8Mwc+qnB+TxLE5Z5RKXafG1/wmxp5hX48kb9R8fss3x h6OB+IObWN3X2Fwk7AcVLFlDcPlgoiKmb1A/cGIyfSj3t0jEYwRP71aTZYEof6xUpK zZZmgk372RtIQ== From: Nathan Chancellor To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, Nick Desaulniers , Tom Rix , Kees Cook , Sami Tolvanen , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Nathan Chancellor , Patrick Havelange , Jarkko Nikula , Oleksij Rempel , Pengutronix Kernel Team , Fabrice Gasnier , Vignesh Raghavendra , Julien Panis , David Lechner , linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-omap@vger.kernel.org Subject: [PATCH 1/4] counter: Adjust final parameter type in function and signal callbacks Date: Wed, 2 Nov 2022 10:22:14 -0700 Message-Id: <20221102172217.2860740-1-nathan@kernel.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748405940793583583?= X-GMAIL-MSGID: =?utf-8?q?1748405940793583583?= 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/counter-chrdev.c:323:34: error: incompatible function pointer types assigning to 'int (*)(struct counter_device *, struct counter_signal *, u32 *)' (aka 'int (*)(struct counter_device *, struct counter_signal *, unsigned int *)') from 'int (*const)(struct counter_device *, struct counter_signal *, enum counter_signal_level *)' [-Werror,-Wincompatible-function-pointer-types-strict] comp_node.comp.signal_u32_read = counter->ops->signal_read; ^ ~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/counter/counter-chrdev.c:337:33: error: incompatible function pointer types assigning to 'int (*)(struct counter_device *, struct counter_count *, u32 *)' (aka 'int (*)(struct counter_device *, struct counter_count *, unsigned int *)') from 'int (*const)(struct counter_device *, struct counter_count *, enum counter_function *)' [-Werror,-Wincompatible-function-pointer-types-strict] comp_node.comp.count_u32_read = counter->ops->function_read; ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ 2 errors generated. drivers/counter/counter-sysfs.c:845:23: error: incompatible function pointer types assigning to 'int (*)(struct counter_device *, struct counter_signal *, u32 *)' (aka 'int (*)(struct counter_device *, struct counter_signal *, unsigned int *)') from 'int (*const)(struct counter_device *, struct counter_signal *, enum counter_signal_level *)' [-Werror,-Wincompatible-function-pointer-types-strict] comp.signal_u32_read = counter->ops->signal_read; ^ ~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/counter/counter-sysfs.c:958:22: error: incompatible function pointer types assigning to 'int (*)(struct counter_device *, struct counter_count *, u32 *)' (aka 'int (*)(struct counter_device *, struct counter_count *, unsigned int *)') from 'int (*const)(struct counter_device *, struct counter_count *, enum counter_function *)' [-Werror,-Wincompatible-function-pointer-types-strict] comp.count_u32_read = counter->ops->function_read; ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/counter/counter-sysfs.c:959:23: error: incompatible function pointer types assigning to 'int (*)(struct counter_device *, struct counter_count *, u32)' (aka 'int (*)(struct counter_device *, struct counter_count *, unsigned int)') from 'int (*const)(struct counter_device *, struct counter_count *, enum counter_function)' [-Werror,-Wincompatible-function-pointer-types-strict] comp.count_u32_write = counter->ops->function_write; ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 3 errors generated. The ->signal_u32_read(), ->count_u32_read(), and ->count_u32_write() callbacks in 'struct counter_comp' expect the final parameter to have a type of 'u32' or 'u32 *' but the ops functions that are being assigned to those callbacks have an enumerated type as the final parameter. While these are compatible from an ABI perspective, they will fail the aforementioned CFI checks. Adjust the type of the final parameter in the ->signal_read(), ->function_read(), and ->function_write() callbacks in 'struct counter_ops' and their implementations to match the prototypes in 'struct counter_comp' to clear up these warnings and CFI failures. Link: https://github.com/ClangBuiltLinux/linux/issues/1750 Reported-by: Sami Tolvanen Signed-off-by: Nathan Chancellor --- Cc: Patrick Havelange Cc: Jarkko Nikula Cc: Oleksij Rempel Cc: Pengutronix Kernel Team Cc: Fabrice Gasnier Cc: Vignesh Raghavendra Cc: Julien Panis Cc: David Lechner Cc: linux-arm-kernel@lists.infradead.org Cc: linux-stm32@st-md-mailman.stormreply.com Cc: linux-omap@vger.kernel.org --- drivers/counter/104-quad-8.c | 6 +++--- drivers/counter/ftm-quaddec.c | 2 +- drivers/counter/intel-qep.c | 2 +- drivers/counter/interrupt-cnt.c | 4 ++-- drivers/counter/microchip-tcb-capture.c | 6 +++--- drivers/counter/stm32-lptimer-cnt.c | 4 ++-- drivers/counter/stm32-timer-cnt.c | 4 ++-- drivers/counter/ti-ecap-capture.c | 2 +- drivers/counter/ti-eqep.c | 4 ++-- include/linux/counter.h | 6 +++--- 10 files changed, 20 insertions(+), 20 deletions(-) base-commit: d501d37841d3b7f18402d71a9ef057eb9dde127e diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index deed4afadb29..30b40f805f88 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -135,7 +135,7 @@ struct quad8 { static int quad8_signal_read(struct counter_device *counter, struct counter_signal *signal, - enum counter_signal_level *level) + u32 *level) { const struct quad8 *const priv = counter_priv(counter); unsigned int state; @@ -258,7 +258,7 @@ static int quad8_function_get(const struct quad8 *const priv, const size_t id, static int quad8_function_read(struct counter_device *counter, struct counter_count *count, - enum counter_function *function) + u32 *function) { struct quad8 *const priv = counter_priv(counter); unsigned long irqflags; @@ -275,7 +275,7 @@ static int quad8_function_read(struct counter_device *counter, static int quad8_function_write(struct counter_device *counter, struct counter_count *count, - enum counter_function function) + u32 function) { struct quad8 *const priv = counter_priv(counter); const int id = count->id; diff --git a/drivers/counter/ftm-quaddec.c b/drivers/counter/ftm-quaddec.c index aea6622a9b13..03f03614fc22 100644 --- a/drivers/counter/ftm-quaddec.c +++ b/drivers/counter/ftm-quaddec.c @@ -189,7 +189,7 @@ static int ftm_quaddec_count_write(struct counter_device *counter, static int ftm_quaddec_count_function_read(struct counter_device *counter, struct counter_count *count, - enum counter_function *function) + u32 *function) { *function = COUNTER_FUNCTION_QUADRATURE_X4; diff --git a/drivers/counter/intel-qep.c b/drivers/counter/intel-qep.c index af5942e66f7d..0eedd9e1a94e 100644 --- a/drivers/counter/intel-qep.c +++ b/drivers/counter/intel-qep.c @@ -123,7 +123,7 @@ static const enum counter_function intel_qep_count_functions[] = { static int intel_qep_function_read(struct counter_device *counter, struct counter_count *count, - enum counter_function *function) + u32 *function) { *function = COUNTER_FUNCTION_QUADRATURE_X4; diff --git a/drivers/counter/interrupt-cnt.c b/drivers/counter/interrupt-cnt.c index 229473855c5b..f068248967d6 100644 --- a/drivers/counter/interrupt-cnt.c +++ b/drivers/counter/interrupt-cnt.c @@ -113,7 +113,7 @@ static const enum counter_function interrupt_cnt_functions[] = { static int interrupt_cnt_function_read(struct counter_device *counter, struct counter_count *count, - enum counter_function *function) + u32 *function) { *function = COUNTER_FUNCTION_INCREASE; @@ -122,7 +122,7 @@ static int interrupt_cnt_function_read(struct counter_device *counter, static int interrupt_cnt_signal_read(struct counter_device *counter, struct counter_signal *signal, - enum counter_signal_level *level) + u32 *level) { struct interrupt_cnt_priv *priv = counter_priv(counter); int ret; diff --git a/drivers/counter/microchip-tcb-capture.c b/drivers/counter/microchip-tcb-capture.c index e2d1dc6ca668..76bec91fde6c 100644 --- a/drivers/counter/microchip-tcb-capture.c +++ b/drivers/counter/microchip-tcb-capture.c @@ -68,7 +68,7 @@ static struct counter_synapse mchp_tc_count_synapses[] = { static int mchp_tc_count_function_read(struct counter_device *counter, struct counter_count *count, - enum counter_function *function) + u32 *function) { struct mchp_tc_data *const priv = counter_priv(counter); @@ -82,7 +82,7 @@ static int mchp_tc_count_function_read(struct counter_device *counter, static int mchp_tc_count_function_write(struct counter_device *counter, struct counter_count *count, - enum counter_function function) + u32 function) { struct mchp_tc_data *const priv = counter_priv(counter); u32 bmr, cmr; @@ -144,7 +144,7 @@ static int mchp_tc_count_function_write(struct counter_device *counter, static int mchp_tc_count_signal_read(struct counter_device *counter, struct counter_signal *signal, - enum counter_signal_level *lvl) + u32 *lvl) { struct mchp_tc_data *const priv = counter_priv(counter); bool sigstatus; diff --git a/drivers/counter/stm32-lptimer-cnt.c b/drivers/counter/stm32-lptimer-cnt.c index d6b80b6dfc28..2dec0c6421d1 100644 --- a/drivers/counter/stm32-lptimer-cnt.c +++ b/drivers/counter/stm32-lptimer-cnt.c @@ -155,7 +155,7 @@ static int stm32_lptim_cnt_read(struct counter_device *counter, static int stm32_lptim_cnt_function_read(struct counter_device *counter, struct counter_count *count, - enum counter_function *function) + u32 *function) { struct stm32_lptim_cnt *const priv = counter_priv(counter); @@ -174,7 +174,7 @@ static int stm32_lptim_cnt_function_read(struct counter_device *counter, static int stm32_lptim_cnt_function_write(struct counter_device *counter, struct counter_count *count, - enum counter_function function) + u32 function) { struct stm32_lptim_cnt *const priv = counter_priv(counter); diff --git a/drivers/counter/stm32-timer-cnt.c b/drivers/counter/stm32-timer-cnt.c index 9bf20a5d6bda..ece55113ba85 100644 --- a/drivers/counter/stm32-timer-cnt.c +++ b/drivers/counter/stm32-timer-cnt.c @@ -70,7 +70,7 @@ static int stm32_count_write(struct counter_device *counter, static int stm32_count_function_read(struct counter_device *counter, struct counter_count *count, - enum counter_function *function) + u32 *function) { struct stm32_timer_cnt *const priv = counter_priv(counter); u32 smcr; @@ -97,7 +97,7 @@ static int stm32_count_function_read(struct counter_device *counter, static int stm32_count_function_write(struct counter_device *counter, struct counter_count *count, - enum counter_function function) + u32 function) { struct stm32_timer_cnt *const priv = counter_priv(counter); u32 cr1, sms; diff --git a/drivers/counter/ti-ecap-capture.c b/drivers/counter/ti-ecap-capture.c index fb1cb1774674..96e5d1f271b8 100644 --- a/drivers/counter/ti-ecap-capture.c +++ b/drivers/counter/ti-ecap-capture.c @@ -188,7 +188,7 @@ static int ecap_cnt_count_write(struct counter_device *counter, static int ecap_cnt_function_read(struct counter_device *counter, struct counter_count *count, - enum counter_function *function) + u32 *function) { *function = COUNTER_FUNCTION_INCREASE; diff --git a/drivers/counter/ti-eqep.c b/drivers/counter/ti-eqep.c index b0f24cf3e891..d73a8baa49e8 100644 --- a/drivers/counter/ti-eqep.c +++ b/drivers/counter/ti-eqep.c @@ -119,7 +119,7 @@ static int ti_eqep_count_write(struct counter_device *counter, static int ti_eqep_function_read(struct counter_device *counter, struct counter_count *count, - enum counter_function *function) + u32 *function) { struct ti_eqep_cnt *priv = ti_eqep_count_from_counter(counter); u32 qdecctl; @@ -146,7 +146,7 @@ static int ti_eqep_function_read(struct counter_device *counter, static int ti_eqep_function_write(struct counter_device *counter, struct counter_count *count, - enum counter_function function) + u32 function) { struct ti_eqep_cnt *priv = ti_eqep_count_from_counter(counter); enum ti_eqep_count_func qsrc; diff --git a/include/linux/counter.h b/include/linux/counter.h index b63746637de2..976dcbfd6266 100644 --- a/include/linux/counter.h +++ b/include/linux/counter.h @@ -324,17 +324,17 @@ struct counter_event_node { struct counter_ops { int (*signal_read)(struct counter_device *counter, struct counter_signal *signal, - enum counter_signal_level *level); + u32 *level); int (*count_read)(struct counter_device *counter, struct counter_count *count, u64 *value); int (*count_write)(struct counter_device *counter, struct counter_count *count, u64 value); int (*function_read)(struct counter_device *counter, struct counter_count *count, - enum counter_function *function); + u32 *function); int (*function_write)(struct counter_device *counter, struct counter_count *count, - enum counter_function function); + u32 function); int (*action_read)(struct counter_device *counter, struct counter_count *count, struct counter_synapse *synapse, From patchwork Wed Nov 2 17:22:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 14405 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp37404wru; Wed, 2 Nov 2022 10:23:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6nQvTn/JhgPMgTHDR/CHsaygJPpNr9BX4HOlc0ms3PfkDNp74vfgcnGeNCHyr6XK9thmJm X-Received: by 2002:a17:907:9688:b0:7a5:74eb:d12b with SMTP id hd8-20020a170907968800b007a574ebd12bmr25206317ejc.60.1667409832926; Wed, 02 Nov 2022 10:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667409832; cv=none; d=google.com; s=arc-20160816; b=D5s4LkETgaf49KT2dN4V55YsXA4zPiJKx/pN0SvxFiAS5poRn0VLR/85/ADt2DyvT3 U7UmPR/+e4HYfb49RFb++0ZBO9zKls9zAiak8MZTpMVDPmA9ON6BsL1b8n20YE5ZT0KG lDDdXi51k61pHmUvjr+oIz8c4Y2VunVizSU7pRtQnbnCYagAh07oo0dt4dTnQj7RBqUS X1zlIvJ6hVliBQQT0AYjFRZA+9GVrmUoAsHWPal9LaY7g8mTQCc7zxZ5o0UDGj7TsdZh rz74weafLN2R1eGIynsjRqQL0E/FgVqMLaywhFLG+Pi4qiqrxTAq4MdgySADmPx88JnC 7TiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5eO7+503/6Kt1O+FOCcqU79H7fCTQBnrHetgNER5y4o=; b=Vdo91YmZK8kS0us/yssSKxS8a9lY4ATn2f2QSaJIb46Vmv4cnHXMWr6r3ivPc7LSRK 5ctNmTHkccuQewJm0IzbE4y35UypYUfD1goT+/ikcFVDP9HUXUDUmWILZ8DqrBOc0Ucz +BgQfs38AG5gkTHhJJiZ78DCfxaIHNriVNn0qOqBRgGjuG6kyj1Fuqx2FlLfUyUP5Kp7 RqV68Wz8zqzYihYuebmoUmIAff0FN6zpS7eYKsbEMusnJQn1HVKFQMvZAf4RJxJ7/7gV 9aHsE7QJxcuavsKaYEESayN2Ech6vO/EFOHEQtcgKA/CLh3phpl955TtgGdpCU181TAD DZSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZtR38H8a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020aa7cf8b000000b00461bbc0aa47si13620181edx.117.2022.11.02.10.23.29; Wed, 02 Nov 2022 10:23:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZtR38H8a; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231343AbiKBRWm (ORCPT + 99 others); Wed, 2 Nov 2022 13:22:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230348AbiKBRWk (ORCPT ); Wed, 2 Nov 2022 13:22:40 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8325A26139; Wed, 2 Nov 2022 10:22:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2899C61A32; Wed, 2 Nov 2022 17:22:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7984C433D7; Wed, 2 Nov 2022 17:22:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667409758; bh=VOPxx1E3nzgzSX4/T9iDwxmKIdfR07u/REHayG82ioQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZtR38H8afcyKcjaRxplQiaodCrL6U01+2ictVzJ4eHQLw6h4wKkBdIU9rNti2ps1Y TXphRcqiH+UQYvmt9VNEY0vEPDdvb+86uKZpXSicZgUZoBJN1FaZFT0S89R9Td4ev8 +tDz9GkFAhGFTE30cokMoULtgCD+J8197M/VdNPkFqCWjR2HiULLjuLIqd/3/bN7nT SIXXwSuZvJ4SdT/WVIzQoLCIUnlnAR4uo1u1B+EZx7rXmqVpz7E+n8DlbLEZZPucyw VmAV9DBVfsAvOuR40tskWxq/YywPMtvI93YZQAMuIh2QLOy6ZCBhehYTMcbdv8shMR C7srL5Lm0GQ9g== From: Nathan Chancellor To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, Nick Desaulniers , Tom Rix , Kees Cook , Sami Tolvanen , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Nathan Chancellor , Fabrice Gasnier , linux-arm-kernel@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com Subject: [PATCH 2/4] counter: stm32-timer-cnt: Adjust final parameter type of stm32_count_direction_read() Date: Wed, 2 Nov 2022 10:22:15 -0700 Message-Id: <20221102172217.2860740-2-nathan@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102172217.2860740-1-nathan@kernel.org> References: <20221102172217.2860740-1-nathan@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748405932581474559?= X-GMAIL-MSGID: =?utf-8?q?1748405932581474559?= 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 Signed-off-by: Nathan Chancellor --- Cc: Fabrice Gasnier Cc: linux-arm-kernel@lists.infradead.org Cc: linux-stm32@st-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; From patchwork Wed Nov 2 17:22:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 14407 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp37808wru; Wed, 2 Nov 2022 10:24:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6NUVDuMdJohfmXqEP3pow5VvGakHyZWTfNvA0loRK1TNON0OLi+vU+tHKCtDsDY+/hJ3Kh X-Received: by 2002:a05:6402:4282:b0:459:befa:c79c with SMTP id g2-20020a056402428200b00459befac79cmr26415254edc.23.1667409884560; Wed, 02 Nov 2022 10:24:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667409884; cv=none; d=google.com; s=arc-20160816; b=nMIIhYmCBRyBG5uLigIRdxmVNiI4vD7n9C5KP00UXR2BMi9RKcTnSOcSk18g2u+LQW WgCCQ0Q+l6HyoAoX0JKUiID9h5OgfXJnh0y12cC0ISkMZqkzrIPm7ek1Na6lklp0YOpN ZhLM6iz15SygDGvJB2G+B7Hq/2W6kmQYrDW63z0LyxbmRTXwTyYbQ2d1e4ZpE+mbq/k3 dGL8nVGWJjKYSX4nhcMsqO/7KbHtLqh1GBQQ+gzLpAp4yBXWDOshr17V4SDQbkfj9dhR tSKaR9OQvpjOmpwl8u0wAipaFu5UtlRYG8pJehkjZqO4gWCVoN7CRPPXPO7mFWLvLfir H9WQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qvVglSD+kSpxMWZ/bLRkt4wxeG8ffYTSi9JfZD36Csg=; b=EUcDFKb8dGpm2FY1bY9VrhgZRIB1Uw6dR7sCfqnf6/Qsh+70aGHXp018Z/tqeIMMRa NqRAeW35xK9NN+TNvmQoAFoMlyUy3bV2eOqUHYPdx1lcJfSszh7BwUMREg34Q02fH1EM We6x/CSpmktHE5OOTO2OAofxihtSFNg4Cl+EAFDx7B85KYu/uEsFQRMnb+uACmWQtqvg N66bqHro5BYotFxgILTph+If1pXrZN+dql9jNyDdJvKGz/ank++rr1ukv65mx/DFkOz5 n7vOkMah1HIT4fVM68w8hrPekd9ptFMj3IFBR7SRRi7c3h3DD/zLvZTwWI7x6WBT/Cna M6Tg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VrKllPQP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m20-20020a056402511400b0045d27c0ba90si16648909edd.577.2022.11.02.10.24.17; Wed, 02 Nov 2022 10:24:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=VrKllPQP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231383AbiKBRWs (ORCPT + 99 others); Wed, 2 Nov 2022 13:22:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231334AbiKBRWl (ORCPT ); Wed, 2 Nov 2022 13:22:41 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E481248D2; Wed, 2 Nov 2022 10:22:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A17EB61ACE; Wed, 2 Nov 2022 17:22:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5D909C4347C; Wed, 2 Nov 2022 17:22:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667409760; bh=foDU0kOGB3Y9bXEW8iH6cIhgf/I30VbPYNdf7dmOjzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VrKllPQPByJ1N/zF9Dh6x2gj5Mig3NCL28wytBkURpeSdUcqa550up1Ur2N6emiyu Fp1w/T8tr/7XadiZuhbAMLWuL7BRejXRjswOzbAVmUyK8YDnF5EYvjQ7Q/Q5hZEMBW HIcf/vA+phrgUBpnlLfKuPQSUZdjiNzJDXiW61SKwXjICgpK3T4nLOxo2cEPcbIBYF vZXf4DRGljvyqC99CLhzoU9TYKrMTCEHpuV4cZOSBGt7kAmRu8eu+BSEw5Qtq8ovS3 9JZcTo6voD7BE3Z5W4yus0HCEdieagzOVwNEV0XvtMDYOnVJmgc6cBMN+UH6tqPN7s N3G2N7sQ6ucNQ== From: Nathan Chancellor To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, Nick Desaulniers , Tom Rix , Kees Cook , Sami Tolvanen , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Nathan Chancellor , Vignesh Raghavendra , Julien Panis , 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 Message-Id: <20221102172217.2860740-3-nathan@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102172217.2860740-1-nathan@kernel.org> References: <20221102172217.2860740-1-nathan@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748405986698652900?= X-GMAIL-MSGID: =?utf-8?q?1748405986698652900?= 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 Signed-off-by: Nathan Chancellor --- Cc: Vignesh Raghavendra Cc: Julien Panis 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); From patchwork Wed Nov 2 17:22:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Chancellor X-Patchwork-Id: 14408 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp38044wru; Wed, 2 Nov 2022 10:25:13 -0700 (PDT) X-Google-Smtp-Source: AMsMyM67ccq2GMwhBCRSJoLZGdeQvgk9QOi6d3rYh2PoVYfVpWWQevKLhvWRfE+l+xh3S31/Y85i X-Received: by 2002:a17:906:d550:b0:7ad:d367:fabb with SMTP id cr16-20020a170906d55000b007add367fabbmr16714531ejc.285.1667409913130; Wed, 02 Nov 2022 10:25:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667409913; cv=none; d=google.com; s=arc-20160816; b=E2OfC94f7AHKU0tQR8M6s3w7LJx7mZR4FZVCcJYYuP9BZb9rXCWntyh/57pbqKt9ev pqSZWGNu7Y4yg1ID2DsMOW+3XmLIKPzOvVO4y2KSQkUD+Boab3Qk8wHJd9CxL7In3MWC DS/bLbcjTurnm1JjnT0NqAQucsKFSdrDWjHDGAbnqPSc/oSUUMUm2cjBJPlTxhiHq1pB C9/Tqbe03hF1XWK2C/Ng194mVAz2Py2mz0CC0Rc2/hK1/hFwa6ZgqaWeZT4I1BxJel4m jtCeziIj7liAdlcSYiFXbz7ASq/aUiMT4ZtJ3qfFxThonlTycdQPD82hfGfk7nfAADKW B5Ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=naXNVaUtKkqmoR6aZlK3AVLrfLU/M0Ofb9OIPWzR3nw=; b=NY/D7ZfpFYoG4i6+oZ4kCoEkRgEXlaFvaV1wWj55gwStKtvfcji7Bd+8H4qqhCU8MN oaAyr1DvkunklPK4vBQUbFHVKkwJ2QYqisxd+EkC9sdgtdi0AzXvIuFSeUcfCqJn4/ms 2QM4dtNxdhEZ2UZiN9EYObIx1EY4dJqDtN1urQILrkVNhm4NO/dKoecmcfQZBDqncNBR jGA/eIjNKDFV4UXVodN8vOooGBjrX7Xnj9vY9RxjqYqigcbHmWYVk7oR0Zv/k/kiG6Jz BqwJa5pxpDd6pxwxyk8SQNdhJ5GmimkM0VBSnoqLEjVm1wQSTUtyeMcdM1tQjCna+wpX UWjQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WeO7UeLx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz19-20020a1709077d9300b007abafd4d7d0si1746506ejc.702.2022.11.02.10.24.29; Wed, 02 Nov 2022 10:25:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=WeO7UeLx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231409AbiKBRWx (ORCPT + 99 others); Wed, 2 Nov 2022 13:22:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231362AbiKBRWq (ORCPT ); Wed, 2 Nov 2022 13:22:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC2BB275C3; Wed, 2 Nov 2022 10:22:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D8CF9B8240C; Wed, 2 Nov 2022 17:22:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8E11C43141; Wed, 2 Nov 2022 17:22:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667409761; bh=1AhYkLtqf9YhGF/slwawF+EBbzYmnHtSSL7hU6uKaKg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WeO7UeLx7Qw1vFaOTrt5JaOwVYdj6m6yF0wYVIo+f0s8UahkKYjp5cEIKGTAMm61o LObgdW5VvdGnqSlA50DTbhjQEbfNfDAsgAh0qHlxlXomAlviuZhARJ9/bxURTj/h3E ho0EXfpQTepI9a1ucGNqnuTb5twOW6DkcQlFyPNsVGyadD3p0HdNNpxsoAwf/YZvge 8kXrkC06pAjt5+SphEildZnv3Y2/ADJQ7c3rKyzBPHImxBGDJbHVNPtj0jJMz31yEA OogcqUQHsTGQcg5zr+QN5QAV6SNZrnRQtL/egIlTdnnd+oYVbdtgF1HnwvS5Pv1xPQ EODiek7mXCD2g== From: Nathan Chancellor To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, Nick Desaulniers , Tom Rix , Kees Cook , Sami Tolvanen , llvm@lists.linux.dev, linux-kernel@vger.kernel.org, patches@lists.linux.dev, Nathan Chancellor Subject: [PATCH 4/4] counter: 104-quad-8: Adjust final parameter type of certain callback functions Date: Wed, 2 Nov 2022 10:22:17 -0700 Message-Id: <20221102172217.2860740-4-nathan@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102172217.2860740-1-nathan@kernel.org> References: <20221102172217.2860740-1-nathan@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748406016950858755?= X-GMAIL-MSGID: =?utf-8?q?1748406016950858755?= 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/104-quad-8.c:1041:2: error: incompatible function pointer types initializing 'int (*)(struct counter_device *, struct counter_signal *, u32 *)' (aka 'int (*)(struct counter_device *, struct counter_signal *, unsigned int *)') with an expression of type 'int (struct counter_device *, struct counter_signal *, enum counter_signal_polarity *)' [-Werror,-Wincompatible-function-pointer-types-strict] COUNTER_COMP_POLARITY(quad8_polarity_read, quad8_polarity_write, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./include/linux/counter.h:609:21: note: expanded from macro 'COUNTER_COMP_POLARITY' .signal_u32_read = (_read), \ ^~~~~~~ drivers/counter/104-quad-8.c:1041:2: error: incompatible function pointer types initializing 'int (*)(struct counter_device *, struct counter_signal *, u32)' (aka 'int (*)(struct counter_device *, struct counter_signal *, unsigned int)') with an expression of type 'int (struct counter_device *, struct counter_signal *, enum counter_signal_polarity)' [-Werror,-Wincompatible-function-pointer-types-strict] COUNTER_COMP_POLARITY(quad8_polarity_read, quad8_polarity_write, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./include/linux/counter.h:610:22: note: expanded from macro 'COUNTER_COMP_POLARITY' .signal_u32_write = (_write), \ ^~~~~~~~ drivers/counter/104-quad-8.c:1129: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 'i nt (struct counter_device *, struct counter_count *, enum counter_count_mode *)' [-Werror,-Wincompatible-function-pointer-types-strict] COUNTER_COMP_COUNT_MODE(quad8_count_mode_read, quad8_count_mode_write, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./include/linux/counter.h:587:20: note: expanded from macro 'COUNTER_COMP_COUNT_MODE' .count_u32_read = (_read), \ ^~~~~~~ drivers/counter/104-quad-8.c:1129: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_mode)' [-Werror,-Wincompatible-function-pointer-types-strict] COUNTER_COMP_COUNT_MODE(quad8_count_mode_read, quad8_count_mode_write, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./include/linux/counter.h:588:21: note: expanded from macro 'COUNTER_COMP_COUNT_MODE' .count_u32_write = (_write), \ ^~~~~~~~ drivers/counter/104-quad-8.c:1131: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 'i nt (struct counter_device *, struct counter_count *, enum counter_count_direction *)' [-Werror,-Wincompatible-function-pointer-types-strict] COUNTER_COMP_DIRECTION(quad8_direction_read), ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./include/linux/counter.h:596:20: note: expanded from macro 'COUNTER_COMP_DIRECTION' .count_u32_read = (_read), \ ^~~~~~~ 5 errors generated. ->count_u32_{read,write}() and ->count_u32_{read,write}() in 'struct counter_comp' expect a final parameter type of either 'u32' or 'u32 *', not the enumerated types used in the implementations. Adjust the final parameter type in the implementations to match the prototype's to resolve the warning and CFI failures. Link: https://github.com/ClangBuiltLinux/linux/issues/1750 Reported-by: Sami Tolvanen Signed-off-by: Nathan Chancellor --- drivers/counter/104-quad-8.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c index 30b40f805f88..720a88ad59db 100644 --- a/drivers/counter/104-quad-8.c +++ b/drivers/counter/104-quad-8.c @@ -337,7 +337,7 @@ static int quad8_function_write(struct counter_device *counter, static int quad8_direction_read(struct counter_device *counter, struct counter_count *count, - enum counter_count_direction *direction) + u32 *direction) { const struct quad8 *const priv = counter_priv(counter); unsigned int ud_flag; @@ -572,7 +572,7 @@ static int quad8_index_polarity_set(struct counter_device *counter, static int quad8_polarity_read(struct counter_device *counter, struct counter_signal *signal, - enum counter_signal_polarity *polarity) + u32 *polarity) { int err; u32 index_polarity; @@ -589,7 +589,7 @@ static int quad8_polarity_read(struct counter_device *counter, static int quad8_polarity_write(struct counter_device *counter, struct counter_signal *signal, - enum counter_signal_polarity polarity) + u32 polarity) { const u32 pol = (polarity == COUNTER_SIGNAL_POLARITY_POSITIVE) ? 1 : 0; @@ -654,7 +654,7 @@ static int quad8_count_floor_read(struct counter_device *counter, static int quad8_count_mode_read(struct counter_device *counter, struct counter_count *count, - enum counter_count_mode *cnt_mode) + u32 *cnt_mode) { const struct quad8 *const priv = counter_priv(counter); @@ -679,7 +679,7 @@ static int quad8_count_mode_read(struct counter_device *counter, static int quad8_count_mode_write(struct counter_device *counter, struct counter_count *count, - enum counter_count_mode cnt_mode) + u32 cnt_mode) { struct quad8 *const priv = counter_priv(counter); unsigned int count_mode;