linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mac80211: Recast pointer for trailing memcpy()
@ 2021-06-17  4:27 Kees Cook
  2021-06-17 19:30 ` Kees Cook
  2021-06-18  8:42 ` David Laight
  0 siblings, 2 replies; 3+ messages in thread
From: Kees Cook @ 2021-06-17  4:27 UTC (permalink / raw)
  To: netdev
  Cc: Kees Cook, Johannes Berg, David S. Miller, Jakub Kicinski,
	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 writing across neighboring array fields.

Give memcpy() a specific source pointer type so it can correctly
calculate the bounds of the copy.

Signed-off-by: Kees Cook <keescook@chromium.org>
---
 net/mac80211/rx.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index af0ef456eb0f..cb141bb788a8 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -559,6 +559,8 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
 
 	if (status->encoding == RX_ENC_HE &&
 	    status->flag & RX_FLAG_RADIOTAP_HE) {
+		struct ieee80211_radiotap_he *he_ptr;
+
 #define HE_PREP(f, val)	le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
 
 		if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
@@ -626,18 +628,22 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
 		while ((pos - (u8 *)rthdr) & 1)
 			pos++;
 		rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE);
-		memcpy(pos, &he, sizeof(he));
-		pos += sizeof(he);
+		he_ptr = (void *)pos;
+		memcpy(he_ptr, &he, sizeof(he));
+		pos += sizeof(*he_ptr);
 	}
 
 	if (status->encoding == RX_ENC_HE &&
 	    status->flag & RX_FLAG_RADIOTAP_HE_MU) {
+		struct ieee80211_radiotap_he_mu *he_mu_ptr;
+
 		/* ensure 2 byte alignment */
 		while ((pos - (u8 *)rthdr) & 1)
 			pos++;
 		rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_HE_MU);
-		memcpy(pos, &he_mu, sizeof(he_mu));
-		pos += sizeof(he_mu);
+		he_mu_ptr = (void *)pos;
+		memcpy(he_mu_ptr, &he_mu, sizeof(he_mu));
+		pos += sizeof(*he_mu_ptr);
 	}
 
 	if (status->flag & RX_FLAG_NO_PSDU) {
@@ -647,12 +653,14 @@ ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
 	}
 
 	if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
+		struct ieee80211_radiotap_lsig *lsig_ptr;
 		/* ensure 2 byte alignment */
 		while ((pos - (u8 *)rthdr) & 1)
 			pos++;
 		rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_LSIG);
-		memcpy(pos, &lsig, sizeof(lsig));
-		pos += sizeof(lsig);
+		lsig_ptr = (void *)pos;
+		memcpy(lsig_ptr, &lsig, sizeof(lsig));
+		pos += sizeof(*lsig_ptr);
 	}
 
 	for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
-- 
2.25.1


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

* Re: [PATCH] mac80211: Recast pointer for trailing memcpy()
  2021-06-17  4:27 [PATCH] mac80211: Recast pointer for trailing memcpy() Kees Cook
@ 2021-06-17 19:30 ` Kees Cook
  2021-06-18  8:42 ` David Laight
  1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2021-06-17 19:30 UTC (permalink / raw)
  To: netdev
  Cc: Johannes Berg, David S. Miller, Jakub Kicinski, linux-kernel,
	linux-wireless, linux-hardening

On Wed, Jun 16, 2021 at 09:27:09PM -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 writing across neighboring array fields.
> 
> Give memcpy() a specific source pointer type so it can correctly
> calculate the bounds of the copy.

Hmpf, please ignore this patch; sorry for the noise. This fix got
mis-tested on my end and does not solve the problem I was trying to solve.
I will return with a v2. :)

-- 
Kees Cook

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

* RE: [PATCH] mac80211: Recast pointer for trailing memcpy()
  2021-06-17  4:27 [PATCH] mac80211: Recast pointer for trailing memcpy() Kees Cook
  2021-06-17 19:30 ` Kees Cook
@ 2021-06-18  8:42 ` David Laight
  1 sibling, 0 replies; 3+ messages in thread
From: David Laight @ 2021-06-18  8:42 UTC (permalink / raw)
  To: 'Kees Cook', netdev
  Cc: Johannes Berg, David S. Miller, Jakub Kicinski, linux-kernel,
	linux-wireless, linux-hardening

From: Kees Cook
> Sent: 17 June 2021 05:27
> 
> In preparation for FORTIFY_SOURCE performing compile-time and run-time
> field bounds checking for memcpy(), memmove(), and memset(), avoid
> intentionally writing across neighboring array fields.
> 
> Give memcpy() a specific source pointer type so it can correctly
> calculate the bounds of the copy.

Doesn't the necessity of this sort of patch just sidestep the
run-time checking and really indicate that it is just a complete
waste of cpu resources?

I bet code changes to avoid/fix the reported errors will
introduce more bugs than the test itself will really find.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

end of thread, other threads:[~2021-06-18  8:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-17  4:27 [PATCH] mac80211: Recast pointer for trailing memcpy() Kees Cook
2021-06-17 19:30 ` Kees Cook
2021-06-18  8:42 ` David Laight

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