public inbox for linux-staging@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH] staging: rtl8723bs: Use array_size() in rtw_spt_band_alloc
@ 2026-04-01 17:39 Joshua David Crofts
  2026-04-01 18:15 ` Greg KH
  0 siblings, 1 reply; 3+ messages in thread
From: Joshua David Crofts @ 2026-04-01 17:39 UTC (permalink / raw)
  To: gregkh; +Cc: joshua.crofts1, grondon, linux-staging, linux-kernel

Replaced raw multiplication with array_size() macro to prevent
integer overflows. Found using Coccinelle.

Signed-off-by: Joshua David Crofts <joshua.crofts1@gmail.com>
---
 drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
index 098456e97..7f0ca5a5e 100644
--- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
+++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
@@ -128,7 +128,8 @@ static struct ieee80211_supported_band *rtw_spt_band_alloc(
 		goto exit;
 
 	spt_band->channels = (struct ieee80211_channel *)(((u8 *)spt_band) + sizeof(struct ieee80211_supported_band));
-	spt_band->bitrates = (struct ieee80211_rate *)(((u8 *)spt_band->channels) + sizeof(struct ieee80211_channel) * n_channels);
+	spt_band->bitrates = (struct ieee80211_rate *)(((u8 *)spt_band->channels) +
+			     array_size(n_channels, sizeof(struct ieee80211_channel)));
 	spt_band->band = band;
 	spt_band->n_channels = n_channels;
 	spt_band->n_bitrates = n_bitrates;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: rtl8723bs: Use array_size() in rtw_spt_band_alloc
  2026-04-01 17:39 [PATCH] staging: rtl8723bs: Use array_size() in rtw_spt_band_alloc Joshua David Crofts
@ 2026-04-01 18:15 ` Greg KH
  2026-04-01 20:52   ` Joshua Crofts
  0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2026-04-01 18:15 UTC (permalink / raw)
  To: Joshua David Crofts; +Cc: grondon, linux-staging, linux-kernel

On Wed, Apr 01, 2026 at 07:39:17PM +0200, Joshua David Crofts wrote:
> Replaced raw multiplication with array_size() macro to prevent
> integer overflows. Found using Coccinelle.
> 
> Signed-off-by: Joshua David Crofts <joshua.crofts1@gmail.com>
> ---
>  drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
> index 098456e97..7f0ca5a5e 100644
> --- a/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
> +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_cfg80211.c
> @@ -128,7 +128,8 @@ static struct ieee80211_supported_band *rtw_spt_band_alloc(
>  		goto exit;
>  
>  	spt_band->channels = (struct ieee80211_channel *)(((u8 *)spt_band) + sizeof(struct ieee80211_supported_band));
> -	spt_band->bitrates = (struct ieee80211_rate *)(((u8 *)spt_band->channels) + sizeof(struct ieee80211_channel) * n_channels);
> +	spt_band->bitrates = (struct ieee80211_rate *)(((u8 *)spt_band->channels) +
> +			     array_size(n_channels, sizeof(struct ieee80211_channel)));

Can this ever overflow?  Who controls n_channels, and why isn't it
bounds check before this?  Also, this is just getting a pointer to a
structure, it's not overflowing a size of an allocation.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] staging: rtl8723bs: Use array_size() in rtw_spt_band_alloc
  2026-04-01 18:15 ` Greg KH
@ 2026-04-01 20:52   ` Joshua Crofts
  0 siblings, 0 replies; 3+ messages in thread
From: Joshua Crofts @ 2026-04-01 20:52 UTC (permalink / raw)
  To: Greg KH; +Cc: grondon, linux-staging, linux-kernel

On Wed, 1 Apr 2026 at 20:15, Greg KH <gregkh@linuxfoundation.org> wrote:
>
> Can this ever overflow?  Who controls n_channels, and why isn't it
> bounds check before this?  Also, this is just getting a pointer to a
> structure, it's not overflowing a size of an allocation.

Hi Greg,

You're right, this is pointer arithmetic, not an alloc. I was investigating a
Coccinelle warning and hadn't fully considered the context. This is my
first kernel patch after all.

Please drop this patch and thanks for your time reviewing it.

Kind regards

CJD

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-01 20:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-01 17:39 [PATCH] staging: rtl8723bs: Use array_size() in rtw_spt_band_alloc Joshua David Crofts
2026-04-01 18:15 ` Greg KH
2026-04-01 20:52   ` Joshua Crofts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox