[PATCH v2 4/6] airo: Avoid clashing function prototypes

From: Gustavo A. R. Silva
Date: Thu Oct 27 2022 - 16:20:27 EST


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 32 warnings like these:

../drivers/net/wireless/cisco/airo.c:7570:2: warning: cast from 'int (*)(struct net_device *, struct iw_request_info *, void *, 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) airo_config_commit, /* SIOCSIWCOMMIT */
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The airo 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. There are no resulting binary differences
before/after changes.

Link: https://github.com/KSPP/linux/issues/236
Link: https://reviews.llvm.org/D134831 [1]
Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx>
Signed-off-by: Gustavo A. R. Silva <gustavoars@xxxxxxxxxx>
---
Changes in v2:
- Add RB tag from Kees.

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

drivers/net/wireless/cisco/airo.c | 204 ++++++++++++++++--------------
1 file changed, 108 insertions(+), 96 deletions(-)

diff --git a/drivers/net/wireless/cisco/airo.c b/drivers/net/wireless/cisco/airo.c
index 10daef81c355..cfa8d3f53482 100644
--- a/drivers/net/wireless/cisco/airo.c
+++ b/drivers/net/wireless/cisco/airo.c
@@ -4807,7 +4807,8 @@ static int get_dec_u16(char *buffer, int *start, int limit)
}

static int airo_config_commit(struct net_device *dev,
- struct iw_request_info *info, void *zwrq,
+ struct iw_request_info *info,
+ union iwreq_data *wrqu,
char *extra);

static inline int sniffing_mode(struct airo_info *ai)
@@ -5804,10 +5805,10 @@ static int airo_get_quality (StatusRid *status_rid, CapabilityRid *cap_rid)
*/
static int airo_get_name(struct net_device *dev,
struct iw_request_info *info,
- char *cwrq,
+ union iwreq_data *cwrq,
char *extra)
{
- strcpy(cwrq, "IEEE 802.11-DS");
+ strcpy(cwrq->name, "IEEE 802.11-DS");
return 0;
}

@@ -5817,9 +5818,10 @@ static int airo_get_name(struct net_device *dev,
*/
static int airo_set_freq(struct net_device *dev,
struct iw_request_info *info,
- struct iw_freq *fwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_freq *fwrq = &wrqu->freq;
struct airo_info *local = dev->ml_priv;
int rc = -EINPROGRESS; /* Call commit handler */

@@ -5858,9 +5860,10 @@ static int airo_set_freq(struct net_device *dev,
*/
static int airo_get_freq(struct net_device *dev,
struct iw_request_info *info,
- struct iw_freq *fwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_freq *fwrq = &wrqu->freq;
struct airo_info *local = dev->ml_priv;
StatusRid status_rid; /* Card status info */
int ch;
@@ -5890,9 +5893,10 @@ static int airo_get_freq(struct net_device *dev,
*/
static int airo_set_essid(struct net_device *dev,
struct iw_request_info *info,
- struct iw_point *dwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_point *dwrq = &wrqu->essid;
struct airo_info *local = dev->ml_priv;
SsidRid SSID_rid; /* SSIDs */

@@ -5935,9 +5939,10 @@ static int airo_set_essid(struct net_device *dev,
*/
static int airo_get_essid(struct net_device *dev,
struct iw_request_info *info,
- struct iw_point *dwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_point *dwrq = &wrqu->essid;
struct airo_info *local = dev->ml_priv;
StatusRid status_rid; /* Card status info */

@@ -5963,9 +5968,10 @@ static int airo_get_essid(struct net_device *dev,
*/
static int airo_set_wap(struct net_device *dev,
struct iw_request_info *info,
- struct sockaddr *awrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct sockaddr *awrq = &wrqu->ap_addr;
struct airo_info *local = dev->ml_priv;
Cmd cmd;
Resp rsp;
@@ -5998,9 +6004,10 @@ static int airo_set_wap(struct net_device *dev,
*/
static int airo_get_wap(struct net_device *dev,
struct iw_request_info *info,
- struct sockaddr *awrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct sockaddr *awrq = &wrqu->ap_addr;
struct airo_info *local = dev->ml_priv;
StatusRid status_rid; /* Card status info */

@@ -6019,9 +6026,10 @@ static int airo_get_wap(struct net_device *dev,
*/
static int airo_set_nick(struct net_device *dev,
struct iw_request_info *info,
- struct iw_point *dwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_point *dwrq = &wrqu->data;
struct airo_info *local = dev->ml_priv;

/* Check the size of the string */
@@ -6042,9 +6050,10 @@ static int airo_set_nick(struct net_device *dev,
*/
static int airo_get_nick(struct net_device *dev,
struct iw_request_info *info,
- struct iw_point *dwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_point *dwrq = &wrqu->data;
struct airo_info *local = dev->ml_priv;

readConfigRid(local, 1);
@@ -6061,9 +6070,10 @@ static int airo_get_nick(struct net_device *dev,
*/
static int airo_set_rate(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_param *vwrq = &wrqu->bitrate;
struct airo_info *local = dev->ml_priv;
CapabilityRid cap_rid; /* Card capability info */
u8 brate = 0;
@@ -6131,9 +6141,10 @@ static int airo_set_rate(struct net_device *dev,
*/
static int airo_get_rate(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_param *vwrq = &wrqu->bitrate;
struct airo_info *local = dev->ml_priv;
StatusRid status_rid; /* Card status info */

@@ -6153,9 +6164,10 @@ static int airo_get_rate(struct net_device *dev,
*/
static int airo_set_rts(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_param *vwrq = &wrqu->rts;
struct airo_info *local = dev->ml_priv;
int rthr = vwrq->value;

@@ -6177,9 +6189,10 @@ static int airo_set_rts(struct net_device *dev,
*/
static int airo_get_rts(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_param *vwrq = &wrqu->rts;
struct airo_info *local = dev->ml_priv;

readConfigRid(local, 1);
@@ -6196,9 +6209,9 @@ static int airo_get_rts(struct net_device *dev,
*/
static int airo_set_frag(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
+ union iwreq_data *wrqu, char *extra)
{
+ struct iw_param *vwrq = &wrqu->frag;
struct airo_info *local = dev->ml_priv;
int fthr = vwrq->value;

@@ -6221,9 +6234,10 @@ static int airo_set_frag(struct net_device *dev,
*/
static int airo_get_frag(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_param *vwrq = &wrqu->frag;
struct airo_info *local = dev->ml_priv;

readConfigRid(local, 1);
@@ -6240,9 +6254,10 @@ static int airo_get_frag(struct net_device *dev,
*/
static int airo_set_mode(struct net_device *dev,
struct iw_request_info *info,
- __u32 *uwrq,
+ union iwreq_data *uwrq,
char *extra)
{
+ __u32 mode = uwrq->mode;
struct airo_info *local = dev->ml_priv;
int reset = 0;

@@ -6250,7 +6265,7 @@ static int airo_set_mode(struct net_device *dev,
if (sniffing_mode(local))
reset = 1;

- switch(*uwrq) {
+ switch (mode) {
case IW_MODE_ADHOC:
local->config.opmode &= ~MODE_CFG_MASK;
local->config.opmode |= MODE_STA_IBSS;
@@ -6303,7 +6318,7 @@ static int airo_set_mode(struct net_device *dev,
*/
static int airo_get_mode(struct net_device *dev,
struct iw_request_info *info,
- __u32 *uwrq,
+ union iwreq_data *uwrq,
char *extra)
{
struct airo_info *local = dev->ml_priv;
@@ -6312,16 +6327,16 @@ static int airo_get_mode(struct net_device *dev,
/* If not managed, assume it's ad-hoc */
switch (local->config.opmode & MODE_CFG_MASK) {
case MODE_STA_ESS:
- *uwrq = IW_MODE_INFRA;
+ uwrq->mode = IW_MODE_INFRA;
break;
case MODE_AP:
- *uwrq = IW_MODE_MASTER;
+ uwrq->mode = IW_MODE_MASTER;
break;
case MODE_AP_RPTR:
- *uwrq = IW_MODE_REPEAT;
+ uwrq->mode = IW_MODE_REPEAT;
break;
default:
- *uwrq = IW_MODE_ADHOC;
+ uwrq->mode = IW_MODE_ADHOC;
}

return 0;
@@ -6338,9 +6353,10 @@ static inline int valid_index(struct airo_info *ai, int index)
*/
static int airo_set_encode(struct net_device *dev,
struct iw_request_info *info,
- struct iw_point *dwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_point *dwrq = &wrqu->encoding;
struct airo_info *local = dev->ml_priv;
int perm = (dwrq->flags & IW_ENCODE_TEMP ? 0 : 1);
__le16 currentAuthType = local->config.authType;
@@ -6437,9 +6453,10 @@ static int airo_set_encode(struct net_device *dev,
*/
static int airo_get_encode(struct net_device *dev,
struct iw_request_info *info,
- struct iw_point *dwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_point *dwrq = &wrqu->encoding;
struct airo_info *local = dev->ml_priv;
int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
int wep_key_len;
@@ -6784,9 +6801,10 @@ static int airo_get_auth(struct net_device *dev,
*/
static int airo_set_txpow(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_param *vwrq = &wrqu->txpower;
struct airo_info *local = dev->ml_priv;
CapabilityRid cap_rid; /* Card capability info */
int i;
@@ -6821,9 +6839,10 @@ static int airo_set_txpow(struct net_device *dev,
*/
static int airo_get_txpow(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_param *vwrq = &wrqu->txpower;
struct airo_info *local = dev->ml_priv;

readConfigRid(local, 1);
@@ -6841,9 +6860,10 @@ static int airo_get_txpow(struct net_device *dev,
*/
static int airo_set_retry(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_param *vwrq = &wrqu->retry;
struct airo_info *local = dev->ml_priv;
int rc = -EINVAL;

@@ -6879,9 +6899,10 @@ static int airo_set_retry(struct net_device *dev,
*/
static int airo_get_retry(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_param *vwrq = &wrqu->retry;
struct airo_info *local = dev->ml_priv;

vwrq->disabled = 0; /* Can't be disabled */
@@ -6910,9 +6931,10 @@ static int airo_get_retry(struct net_device *dev,
*/
static int airo_get_range(struct net_device *dev,
struct iw_request_info *info,
- struct iw_point *dwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_point *dwrq = &wrqu->data;
struct airo_info *local = dev->ml_priv;
struct iw_range *range = (struct iw_range *) extra;
CapabilityRid cap_rid; /* Card capability info */
@@ -7036,9 +7058,9 @@ static int airo_get_range(struct net_device *dev,
*/
static int airo_set_power(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
- char *extra)
+ union iwreq_data *wrqu, char *extra)
{
+ struct iw_param *vwrq = &wrqu->power;
struct airo_info *local = dev->ml_priv;

readConfigRid(local, 1);
@@ -7094,9 +7116,10 @@ static int airo_set_power(struct net_device *dev,
*/
static int airo_get_power(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_param *vwrq = &wrqu->power;
struct airo_info *local = dev->ml_priv;
__le16 mode;

@@ -7125,9 +7148,10 @@ static int airo_get_power(struct net_device *dev,
*/
static int airo_set_sens(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_param *vwrq = &wrqu->sens;
struct airo_info *local = dev->ml_priv;

readConfigRid(local, 1);
@@ -7144,9 +7168,10 @@ static int airo_set_sens(struct net_device *dev,
*/
static int airo_get_sens(struct net_device *dev,
struct iw_request_info *info,
- struct iw_param *vwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_param *vwrq = &wrqu->sens;
struct airo_info *local = dev->ml_priv;

readConfigRid(local, 1);
@@ -7164,9 +7189,10 @@ static int airo_get_sens(struct net_device *dev,
*/
static int airo_get_aplist(struct net_device *dev,
struct iw_request_info *info,
- struct iw_point *dwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_point *dwrq = &wrqu->data;
struct airo_info *local = dev->ml_priv;
struct sockaddr *address = (struct sockaddr *) extra;
struct iw_quality *qual;
@@ -7242,7 +7268,7 @@ static int airo_get_aplist(struct net_device *dev,
*/
static int airo_set_scan(struct net_device *dev,
struct iw_request_info *info,
- struct iw_point *dwrq,
+ union iwreq_data *wrqu,
char *extra)
{
struct airo_info *ai = dev->ml_priv;
@@ -7473,9 +7499,10 @@ static inline char *airo_translate_scan(struct net_device *dev,
*/
static int airo_get_scan(struct net_device *dev,
struct iw_request_info *info,
- struct iw_point *dwrq,
+ union iwreq_data *wrqu,
char *extra)
{
+ struct iw_point *dwrq = &wrqu->data;
struct airo_info *ai = dev->ml_priv;
BSSListElement *net;
int err = 0;
@@ -7517,7 +7544,7 @@ static int airo_get_scan(struct net_device *dev,
*/
static int airo_config_commit(struct net_device *dev,
struct iw_request_info *info, /* NULL */
- void *zwrq, /* NULL */
+ union iwreq_data *wrqu, /* NULL */
char *extra) /* NULL */
{
struct airo_info *local = dev->ml_priv;
@@ -7567,61 +7594,46 @@ static const struct iw_priv_args airo_private_args[] = {

static const iw_handler airo_handler[] =
{
- (iw_handler) airo_config_commit, /* SIOCSIWCOMMIT */
- (iw_handler) airo_get_name, /* SIOCGIWNAME */
- (iw_handler) NULL, /* SIOCSIWNWID */
- (iw_handler) NULL, /* SIOCGIWNWID */
- (iw_handler) airo_set_freq, /* SIOCSIWFREQ */
- (iw_handler) airo_get_freq, /* SIOCGIWFREQ */
- (iw_handler) airo_set_mode, /* SIOCSIWMODE */
- (iw_handler) airo_get_mode, /* SIOCGIWMODE */
- (iw_handler) airo_set_sens, /* SIOCSIWSENS */
- (iw_handler) airo_get_sens, /* SIOCGIWSENS */
- (iw_handler) NULL, /* SIOCSIWRANGE */
- (iw_handler) airo_get_range, /* SIOCGIWRANGE */
- (iw_handler) NULL, /* SIOCSIWPRIV */
- (iw_handler) NULL, /* SIOCGIWPRIV */
- (iw_handler) NULL, /* SIOCSIWSTATS */
- (iw_handler) NULL, /* SIOCGIWSTATS */
- iw_handler_set_spy, /* SIOCSIWSPY */
- iw_handler_get_spy, /* SIOCGIWSPY */
- iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
- iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
- (iw_handler) airo_set_wap, /* SIOCSIWAP */
- (iw_handler) airo_get_wap, /* SIOCGIWAP */
- (iw_handler) NULL, /* -- hole -- */
- (iw_handler) airo_get_aplist, /* SIOCGIWAPLIST */
- (iw_handler) airo_set_scan, /* SIOCSIWSCAN */
- (iw_handler) airo_get_scan, /* SIOCGIWSCAN */
- (iw_handler) airo_set_essid, /* SIOCSIWESSID */
- (iw_handler) airo_get_essid, /* SIOCGIWESSID */
- (iw_handler) airo_set_nick, /* SIOCSIWNICKN */
- (iw_handler) airo_get_nick, /* SIOCGIWNICKN */
- (iw_handler) NULL, /* -- hole -- */
- (iw_handler) NULL, /* -- hole -- */
- (iw_handler) airo_set_rate, /* SIOCSIWRATE */
- (iw_handler) airo_get_rate, /* SIOCGIWRATE */
- (iw_handler) airo_set_rts, /* SIOCSIWRTS */
- (iw_handler) airo_get_rts, /* SIOCGIWRTS */
- (iw_handler) airo_set_frag, /* SIOCSIWFRAG */
- (iw_handler) airo_get_frag, /* SIOCGIWFRAG */
- (iw_handler) airo_set_txpow, /* SIOCSIWTXPOW */
- (iw_handler) airo_get_txpow, /* SIOCGIWTXPOW */
- (iw_handler) airo_set_retry, /* SIOCSIWRETRY */
- (iw_handler) airo_get_retry, /* SIOCGIWRETRY */
- (iw_handler) airo_set_encode, /* SIOCSIWENCODE */
- (iw_handler) airo_get_encode, /* SIOCGIWENCODE */
- (iw_handler) airo_set_power, /* SIOCSIWPOWER */
- (iw_handler) airo_get_power, /* SIOCGIWPOWER */
- (iw_handler) NULL, /* -- hole -- */
- (iw_handler) NULL, /* -- hole -- */
- (iw_handler) NULL, /* SIOCSIWGENIE */
- (iw_handler) NULL, /* SIOCGIWGENIE */
- (iw_handler) airo_set_auth, /* SIOCSIWAUTH */
- (iw_handler) airo_get_auth, /* SIOCGIWAUTH */
- (iw_handler) airo_set_encodeext, /* SIOCSIWENCODEEXT */
- (iw_handler) airo_get_encodeext, /* SIOCGIWENCODEEXT */
- (iw_handler) NULL, /* SIOCSIWPMKSA */
+ IW_HANDLER(SIOCSIWCOMMIT, airo_config_commit),
+ IW_HANDLER(SIOCGIWNAME, airo_get_name),
+ IW_HANDLER(SIOCSIWFREQ, airo_set_freq),
+ IW_HANDLER(SIOCGIWFREQ, airo_get_freq),
+ IW_HANDLER(SIOCSIWMODE, airo_set_mode),
+ IW_HANDLER(SIOCGIWMODE, airo_get_mode),
+ IW_HANDLER(SIOCSIWSENS, airo_set_sens),
+ IW_HANDLER(SIOCGIWSENS, airo_get_sens),
+ IW_HANDLER(SIOCGIWRANGE, airo_get_range),
+ IW_HANDLER(SIOCSIWSPY, iw_handler_set_spy),
+ IW_HANDLER(SIOCGIWSPY, iw_handler_get_spy),
+ IW_HANDLER(SIOCSIWTHRSPY, iw_handler_set_thrspy),
+ IW_HANDLER(SIOCGIWTHRSPY, iw_handler_get_thrspy),
+ IW_HANDLER(SIOCSIWAP, airo_set_wap),
+ IW_HANDLER(SIOCGIWAP, airo_get_wap),
+ IW_HANDLER(SIOCGIWAPLIST, airo_get_aplist),
+ IW_HANDLER(SIOCSIWSCAN, airo_set_scan),
+ IW_HANDLER(SIOCGIWSCAN, airo_get_scan),
+ IW_HANDLER(SIOCSIWESSID, airo_set_essid),
+ IW_HANDLER(SIOCGIWESSID, airo_get_essid),
+ IW_HANDLER(SIOCSIWNICKN, airo_set_nick),
+ IW_HANDLER(SIOCGIWNICKN, airo_get_nick),
+ IW_HANDLER(SIOCSIWRATE, airo_set_rate),
+ IW_HANDLER(SIOCGIWRATE, airo_get_rate),
+ IW_HANDLER(SIOCSIWRTS, airo_set_rts),
+ IW_HANDLER(SIOCGIWRTS, airo_get_rts),
+ IW_HANDLER(SIOCSIWFRAG, airo_set_frag),
+ IW_HANDLER(SIOCGIWFRAG, airo_get_frag),
+ IW_HANDLER(SIOCSIWTXPOW, airo_set_txpow),
+ IW_HANDLER(SIOCGIWTXPOW, airo_get_txpow),
+ IW_HANDLER(SIOCSIWRETRY, airo_set_retry),
+ IW_HANDLER(SIOCGIWRETRY, airo_get_retry),
+ IW_HANDLER(SIOCSIWENCODE, airo_set_encode),
+ IW_HANDLER(SIOCGIWENCODE, airo_get_encode),
+ IW_HANDLER(SIOCSIWPOWER, airo_set_power),
+ IW_HANDLER(SIOCGIWPOWER, airo_get_power),
+ IW_HANDLER(SIOCSIWAUTH, airo_set_auth),
+ IW_HANDLER(SIOCGIWAUTH, airo_get_auth),
+ IW_HANDLER(SIOCSIWENCODEEXT, airo_set_encodeext),
+ IW_HANDLER(SIOCGIWENCODEEXT, airo_get_encodeext),
};

/* Note : don't describe AIROIDIFC and AIROOLDIDIFC in here.
--
2.34.1