netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johannes Berg <johannes@sipsolutions.net>
To: Jakub Kicinski <kuba@kernel.org>, kvalo@kernel.org
Cc: netdev@vger.kernel.org, linux-wireless@vger.kernel.org,
	libertas-dev@lists.infradead.org
Subject: Re: [PATCH net-next 7/8] wifi: libertas: silence a GCC 12 -Warray-bounds warning
Date: Sun, 22 May 2022 00:03:22 +0200	[thread overview]
Message-ID: <dfc9d27acf3eaf6222b920701e478c3e9c22fefc.camel@sipsolutions.net> (raw)
In-Reply-To: <20220520194320.2356236-8-kuba@kernel.org>

On Fri, 2022-05-20 at 12:43 -0700, Jakub Kicinski wrote:
> This driver does a lot of casting of smaller buffers to
> a larger command response struct, GCC 12 does not like that:
> 
> drivers/net/wireless/marvell/libertas/cfg.c:1198:63: warning: array subscript ‘struct cmd_ds_802_11_associate_response[0]’ is partly outside array bounds of ‘unsigned char[203]’ [-Warray-bounds]
>  1198 |                       "aid 0x%04x\n", status, le16_to_cpu(resp->statuscode),
>       |                                                               ^~
> 

I had a similar issue in our driver, and I could work around it there
with a simple cast ... here not, but perhaps we should consider
something like the below?

johannes

diff --git a/drivers/net/wireless/marvell/libertas/cfg.c
b/drivers/net/wireless/marvell/libertas/cfg.c
index 4e3de684928b..b0b3f59dabc6 100644
--- a/drivers/net/wireless/marvell/libertas/cfg.c
+++ b/drivers/net/wireless/marvell/libertas/cfg.c
@@ -1053,7 +1053,6 @@ static int lbs_set_authtype(struct lbs_private
*priv,
  */
 #define LBS_ASSOC_MAX_CMD_SIZE                     \
 	(sizeof(struct cmd_ds_802_11_associate)    \
-	 - 512 /* cmd_ds_802_11_associate.iebuf */ \
 	 + LBS_MAX_SSID_TLV_SIZE                   \
 	 + LBS_MAX_CHANNEL_TLV_SIZE                \
 	 + LBS_MAX_CF_PARAM_TLV_SIZE               \
@@ -1130,8 +1129,7 @@ static int lbs_associate(struct lbs_private *priv,
 	if (sme->ie && sme->ie_len)
 		pos += lbs_add_wpa_tlv(pos, sme->ie, sme->ie_len);
 
-	len = (sizeof(*cmd) - sizeof(cmd->iebuf)) +
-		(u16)(pos - (u8 *) &cmd->iebuf);
+	len = sizeof(*cmd) + (u16)(pos - (u8 *) &cmd->iebuf);
 	cmd->hdr.size = cpu_to_le16(len);
 
 	lbs_deb_hex(LBS_DEB_ASSOC, "ASSOC_CMD", (u8 *) cmd,
diff --git a/drivers/net/wireless/marvell/libertas/host.h
b/drivers/net/wireless/marvell/libertas/host.h
index ceff4b92e7a1..a202b716ad5d 100644
--- a/drivers/net/wireless/marvell/libertas/host.h
+++ b/drivers/net/wireless/marvell/libertas/host.h
@@ -528,7 +528,8 @@ struct cmd_ds_802_11_associate {
 	__le16 listeninterval;
 	__le16 bcnperiod;
 	u8 dtimperiod;
-	u8 iebuf[512];    /* Enough for required and most optional IEs
*/
+	/* 512 permitted - enough for required and most optional IEs */
+	u8 iebuf[];
 } __packed;
 
 struct cmd_ds_802_11_associate_response {
@@ -537,7 +538,8 @@ struct cmd_ds_802_11_associate_response {
 	__le16 capability;
 	__le16 statuscode;
 	__le16 aid;
-	u8 iebuf[512];
+	/* max 512 */
+	u8 iebuf[];
 } __packed;
 
 struct cmd_ds_802_11_set_wep {


  reply	other threads:[~2022-05-21 22:03 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-20 19:43 [PATCH net-next 0/8] Fix/silence GCC 12 warnings in drivers/net/wireless/ Jakub Kicinski
2022-05-20 19:43 ` [PATCH net-next 1/8] wifi: plfxlc: remove redundant NULL-check for GCC 12 Jakub Kicinski
2022-05-20 19:43 ` [PATCH net-next 2/8] wifi: ath9k: silence array-bounds warning on " Jakub Kicinski
2022-05-21  6:58   ` Kalle Valo
2022-05-21 17:53     ` Jakub Kicinski
2022-05-22 12:06       ` Kalle Valo
2022-05-23 19:31     ` Kees Cook
2022-05-20 19:43 ` [PATCH net-next 3/8] wifi: rtlwifi: remove always-true condition pointed out by " Jakub Kicinski
2022-05-23  2:35   ` Ping-Ke Shih
2022-05-23 15:57     ` Jakub Kicinski
2022-05-24  0:41       ` Ping-Ke Shih
2022-05-20 19:43 ` [PATCH net-next 4/8] wifi: ath6k: silence false positive -Wno-dangling-pointer warning on " Jakub Kicinski
2022-05-20 19:43 ` [PATCH net-next 5/8] wifi: iwlwifi: use unsigned to silence a GCC 12 warning Jakub Kicinski
2022-05-20 19:43 ` [PATCH net-next 6/8] wifi: brcmfmac: work around a GCC 12 -Warray-bounds warning Jakub Kicinski
2022-05-20 19:43 ` [PATCH net-next 7/8] wifi: libertas: silence " Jakub Kicinski
2022-05-21 22:03   ` Johannes Berg [this message]
2022-05-22 16:56     ` Jakub Kicinski
2022-05-20 19:43 ` [PATCH net-next 8/8] wifi: carl9170: " Jakub Kicinski
2022-05-20 19:58   ` Christian Lamparter
2022-05-22 12:19 ` [PATCH net-next 0/8] Fix/silence GCC 12 warnings in drivers/net/wireless/ Kalle Valo

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=dfc9d27acf3eaf6222b920701e478c3e9c22fefc.camel@sipsolutions.net \
    --to=johannes@sipsolutions.net \
    --cc=kuba@kernel.org \
    --cc=kvalo@kernel.org \
    --cc=libertas-dev@lists.infradead.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=netdev@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).