From: Kees Cook <keescook@chromium.org>
To: netdev@vger.kernel.org
Cc: Kees Cook <keescook@chromium.org>,
Johannes Berg <johannes@sipsolutions.net>,
"David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: [PATCH] mac80211: Recast pointer for trailing memcpy()
Date: Wed, 16 Jun 2021 21:27:09 -0700 [thread overview]
Message-ID: <20210617042709.2170111-1-keescook@chromium.org> (raw)
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
next reply other threads:[~2021-06-17 4:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-17 4:27 Kees Cook [this message]
2021-06-17 19:30 ` [PATCH] mac80211: Recast pointer for trailing memcpy() Kees Cook
2021-06-18 8:42 ` David Laight
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=20210617042709.2170111-1-keescook@chromium.org \
--to=keescook@chromium.org \
--cc=davem@davemloft.net \
--cc=johannes@sipsolutions.net \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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).