linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mwl8k: Avoid memcpy() over-reading of ETH_SS_STATS
@ 2021-06-16 19:52 Kees Cook
  2021-06-16 19:58 ` Andrew Lunn
  0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2021-06-16 19:52 UTC (permalink / raw)
  To: netdev
  Cc: Kees Cook, Lennert Buytenhek, Kalle Valo, David S. Miller,
	Jakub Kicinski, Romain Perier, Allen Pais, Gustavo A. R. Silva,
	Arnd Bergmann, wengjianfeng, Christophe JAILLET, Lv Yunlong,
	linux-kernel, linux-wireless, linux-hardening

In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memcpy(), memmove(), and memset(), avoid
intentionally reading across neighboring array fields. Use the
sub-structure address directly.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 drivers/net/wireless/marvell/mwl8k.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/wireless/marvell/mwl8k.c b/drivers/net/wireless/marvell/mwl8k.c
index 84b32a5f01ee..3bf6571f4149 100644
--- a/drivers/net/wireless/marvell/mwl8k.c
+++ b/drivers/net/wireless/marvell/mwl8k.c
@@ -4552,7 +4552,7 @@ static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
 	else
 		rates = sta->supp_rates[NL80211_BAND_5GHZ] << 5;
 	legacy_rate_mask_to_array(p->legacy_rates, rates);
-	memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
+	memcpy(p->ht_rates, &sta->ht_cap.mcs, 16);
 	p->interop = 1;
 	p->amsdu_enabled = 0;
 
@@ -5034,7 +5034,7 @@ mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
 			ap_legacy_rates =
 				ap->supp_rates[NL80211_BAND_5GHZ] << 5;
 		}
-		memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
+		memcpy(ap_mcs_rates, &ap->ht_cap.mcs, 16);
 
 		rcu_read_unlock();
 
-- 
2.25.1


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

* Re: [PATCH] mwl8k: Avoid memcpy() over-reading of ETH_SS_STATS
  2021-06-16 19:52 [PATCH] mwl8k: Avoid memcpy() over-reading of ETH_SS_STATS Kees Cook
@ 2021-06-16 19:58 ` Andrew Lunn
  2021-06-17  3:22   ` Kees Cook
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2021-06-16 19:58 UTC (permalink / raw)
  To: Kees Cook
  Cc: netdev, Lennert Buytenhek, Kalle Valo, David S. Miller,
	Jakub Kicinski, Romain Perier, Allen Pais, Gustavo A. R. Silva,
	Arnd Bergmann, wengjianfeng, Christophe JAILLET, Lv Yunlong,
	linux-kernel, linux-wireless, linux-hardening

On Wed, Jun 16, 2021 at 12:52:42PM -0700, Kees Cook wrote:
> In preparation for FORTIFY_SOURCE performing compile-time and run-time
> field bounds checking for memcpy(), memmove(), and memset(), avoid
> intentionally reading across neighboring array fields. Use the
> sub-structure address directly.
> 
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
>  drivers/net/wireless/marvell/mwl8k.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/wireless/marvell/mwl8k.c b/drivers/net/wireless/marvell/mwl8k.c
> index 84b32a5f01ee..3bf6571f4149 100644
> --- a/drivers/net/wireless/marvell/mwl8k.c
> +++ b/drivers/net/wireless/marvell/mwl8k.c
> @@ -4552,7 +4552,7 @@ static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
>  	else
>  		rates = sta->supp_rates[NL80211_BAND_5GHZ] << 5;
>  	legacy_rate_mask_to_array(p->legacy_rates, rates);
> -	memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
> +	memcpy(p->ht_rates, &sta->ht_cap.mcs, 16);
>  	p->interop = 1;
>  	p->amsdu_enabled = 0;
>  
> @@ -5034,7 +5034,7 @@ mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
>  			ap_legacy_rates =
>  				ap->supp_rates[NL80211_BAND_5GHZ] << 5;
>  		}
> -		memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
> +		memcpy(ap_mcs_rates, &ap->ht_cap.mcs, 16);
>  
>  		rcu_read_unlock();

This does not appear to have anything to do with ETH_SS_STATS which is
what the Subject: says.

     Andrew

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

* Re: [PATCH] mwl8k: Avoid memcpy() over-reading of ETH_SS_STATS
  2021-06-16 19:58 ` Andrew Lunn
@ 2021-06-17  3:22   ` Kees Cook
  0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2021-06-17  3:22 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: netdev, Lennert Buytenhek, Kalle Valo, David S. Miller,
	Jakub Kicinski, Romain Perier, Allen Pais, Gustavo A. R. Silva,
	Arnd Bergmann, wengjianfeng, Christophe JAILLET, Lv Yunlong,
	linux-kernel, linux-wireless, linux-hardening

On Wed, Jun 16, 2021 at 09:58:09PM +0200, Andrew Lunn wrote:
> On Wed, Jun 16, 2021 at 12:52:42PM -0700, Kees Cook wrote:
> > In preparation for FORTIFY_SOURCE performing compile-time and run-time
> > field bounds checking for memcpy(), memmove(), and memset(), avoid
> > intentionally reading across neighboring array fields. Use the
> > sub-structure address directly.
> > 
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> > ---
> >  drivers/net/wireless/marvell/mwl8k.c | 4 ++--
> >  1 file changed, 2 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/net/wireless/marvell/mwl8k.c b/drivers/net/wireless/marvell/mwl8k.c
> > index 84b32a5f01ee..3bf6571f4149 100644
> > --- a/drivers/net/wireless/marvell/mwl8k.c
> > +++ b/drivers/net/wireless/marvell/mwl8k.c
> > @@ -4552,7 +4552,7 @@ static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
> >  	else
> >  		rates = sta->supp_rates[NL80211_BAND_5GHZ] << 5;
> >  	legacy_rate_mask_to_array(p->legacy_rates, rates);
> > -	memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
> > +	memcpy(p->ht_rates, &sta->ht_cap.mcs, 16);
> >  	p->interop = 1;
> >  	p->amsdu_enabled = 0;
> >  
> > @@ -5034,7 +5034,7 @@ mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
> >  			ap_legacy_rates =
> >  				ap->supp_rates[NL80211_BAND_5GHZ] << 5;
> >  		}
> > -		memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
> > +		memcpy(ap_mcs_rates, &ap->ht_cap.mcs, 16);
> >  
> >  		rcu_read_unlock();
> 
> This does not appear to have anything to do with ETH_SS_STATS which is
> what the Subject: says.

Whoops! I was off-by-one in my Subject edits. I will respin.

-Kees

-- 
Kees Cook

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

end of thread, other threads:[~2021-06-17  3:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-16 19:52 [PATCH] mwl8k: Avoid memcpy() over-reading of ETH_SS_STATS Kees Cook
2021-06-16 19:58 ` Andrew Lunn
2021-06-17  3:22   ` Kees Cook

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).