mbox series

[v3,0/7] Avoid clashing function prototypes

Message ID cover.1667934775.git.gustavoars@kernel.org
Headers show
Series Avoid clashing function prototypes | expand

Message

Gustavo A. R. Silva Nov. 8, 2022, 8:18 p.m. UTC
When built with Control Flow Integrity, function prototypes between
caller and function declaration must match. These mismatches are visible
at compile time with the new -Wcast-function-type-strict in Clang[1].

This series fixes a total of 424 -Wcast-function-type-strict warnings.

Link: https://reviews.llvm.org/D134831 [1]

Changes in v3:
 - Split non-related orinoco changes out of cgf80211 into a separate
   patch.
 - Mention Coccinelle in some of the patches where it was used
   to make some changes.
 - Add RB tags to a couple of patches.

Changes in v2:
 - Squash patches 1, 2 and 3 into a single patch cfg80211.
 - Add a couple more patches: bna and staging.
 - Fix 254 (227 in bna and 27 in staging) more
   -Wcast-function-type-strict warnings.
 - Link: https://lore.kernel.org/linux-hardening/cover.1666894751.git.gustavoars@kernel.org/

v1:
 - Link: https://lore.kernel.org/linux-hardening/cover.1666038048.git.gustavoars@kernel.org/

Gustavo A. R. Silva (7):
  wifi: orinoco: Avoid clashing function prototypes
  cfg80211: Avoid clashing function prototypes
  wifi: hostap: Avoid clashing function prototypes
  wifi: zd1201: Avoid clashing function prototypes
  wifi: airo: Avoid clashing function prototypes
  bna: Avoid clashing function prototypes
  staging: ks7010: Avoid clashing function prototypes

 drivers/net/ethernet/brocade/bna/bfa_cs.h     |  60 +++--
 drivers/net/ethernet/brocade/bna/bfa_ioc.c    |  10 +-
 drivers/net/ethernet/brocade/bna/bfa_ioc.h    |   8 +-
 drivers/net/ethernet/brocade/bna/bfa_msgq.h   |   8 +-
 drivers/net/ethernet/brocade/bna/bna_enet.c   |   6 +-
 drivers/net/ethernet/brocade/bna/bna_tx_rx.c  |   6 +-
 drivers/net/ethernet/brocade/bna/bna_types.h  |  27 +-
 drivers/net/wireless/cisco/airo.c             | 204 +++++++-------
 drivers/net/wireless/intel/ipw2x00/ipw2200.c  |   2 +-
 .../wireless/intersil/hostap/hostap_ioctl.c   | 244 +++++++++--------
 drivers/net/wireless/intersil/orinoco/wext.c  | 131 +++++----
 drivers/net/wireless/zydas/zd1201.c           | 174 ++++++------
 drivers/staging/ks7010/ks_wlan_net.c          | 248 +++++++++---------
 include/net/cfg80211-wext.h                   |  20 +-
 net/wireless/scan.c                           |   3 +-
 net/wireless/wext-compat.c                    | 180 ++++++-------
 net/wireless/wext-compat.h                    |   8 +-
 net/wireless/wext-sme.c                       |   5 +-
 18 files changed, 713 insertions(+), 631 deletions(-)

Comments

Kees Cook Nov. 10, 2022, 12:06 a.m. UTC | #1
On Tue, Nov 08, 2022 at 02:21:24PM -0600, Gustavo A. R. Silva wrote:
> When built with Control Flow Integrity, function prototypes between
> caller and function declaration must match. These mismatches are visible
> at compile time with the new -Wcast-function-type-strict in Clang[1].
> 
> Fix a total of 43 warnings like these:
> 
> drivers/net/wireless/intersil/orinoco/wext.c:1379:27: warning: cast from 'int (*)(struct net_device *, struct iw_request_info *, struct iw_param *, char *)' to 'iw_handler' (aka 'int (*)(struct net_device *, struct iw_request_info *, union iwreq_data *, char *)') converts to incompatible function type [-Wcast-function-type-strict]
>         IW_HANDLER(SIOCGIWPOWER,        (iw_handler)orinoco_ioctl_getpower),
>                                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> The orinoco Wireless Extension handler callbacks (iw_handler) use a
> union for the data argument. Actually use the union and perform explicit
> member selection in the function body instead of having a function
> prototype mismatch. No significant binary differences were seen
> before/after changes.
> 
> These changes were made partly manually and partly with the help of
> Coccinelle.
> 
> Link: https://github.com/KSPP/linux/issues/234
> Link: https://reviews.llvm.org/D134831 [1]
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>

Reviewed-by: Kees Cook <keescook@chromium.org>
Kalle Valo Nov. 10, 2022, 5:43 a.m. UTC | #2
"Gustavo A. R. Silva" <gustavoars@kernel.org> writes:

> When built with Control Flow Integrity, function prototypes between
> caller and function declaration must match. These mismatches are visible
> at compile time with the new -Wcast-function-type-strict in Clang[1].
>
> Fix a total of 227 warnings like these:
>
> drivers/net/ethernet/brocade/bna/bna_enet.c:519:3: warning: cast from 'void (*)(struct bna_ethport *, enum bna_ethport_event)' to 'bfa_fsm_t' (aka 'void (*)(void *, int)') converts to incompatible function type [-Wcast-function-type-strict]
>                 bfa_fsm_set_state(ethport, bna_ethport_sm_down);
>                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> The bna state machine code heavily overloads its state machine functions,
> so these have been separated into their own sets of structs, enums,
> typedefs, and helper functions. There are almost zero binary code changes,
> all seem to be related to header file line numbers changing, or the
> addition of the new stats helper.
>
> Important to mention is that while I was manually implementing this changes
> I was staring at this[2] patch from Kees Cook. Thanks, Kees. :)
>
> [1] https://reviews.llvm.org/D134831
> [2] https://lore.kernel.org/linux-hardening/20220929230334.2109344-1-keescook@chromium.org/
> Reviewed-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> Changes in v3:
>  - Add RB tag from Kees.
>  - Update changelog text.
>
> Changes in v2:
>  - None. This patch is new in the series.
>  - Link: https://lore.kernel.org/linux-hardening/2812afc0de278b97413a142d39d939a08ac74025.1666894751.git.gustavoars@kernel.org/
>
>  drivers/net/ethernet/brocade/bna/bfa_cs.h    | 60 +++++++++++++-------
>  drivers/net/ethernet/brocade/bna/bfa_ioc.c   | 10 ++--
>  drivers/net/ethernet/brocade/bna/bfa_ioc.h   |  8 ++-
>  drivers/net/ethernet/brocade/bna/bfa_msgq.h  |  8 ++-
>  drivers/net/ethernet/brocade/bna/bna_enet.c  |  6 +-
>  drivers/net/ethernet/brocade/bna/bna_tx_rx.c |  6 +-
>  drivers/net/ethernet/brocade/bna/bna_types.h | 27 +++++++--

Mixing wifi and ethernet patches in the same patch is not a good idea,
the network maintainers might miss this patch. I recommend submitting
patch 6 separately.
Gustavo A. R. Silva Nov. 11, 2022, 4:46 p.m. UTC | #3
> Mixing wifi and ethernet patches in the same patch is not a good idea,
> the network maintainers might miss this patch. I recommend submitting
> patch 6 separately.

OK.

In the meantime, can you take patches 1-5? :)

Thanks!
--
Gustavo