Add the '__counted_by()' compiler attribute to the flexible array member
'match[]' to improve access bounds-checking via CONFIG_UBSAN_BOUNDS and
CONFIG_FORTIFY_SOURCE, adjust 'cfg80211_mlme_register_mgmt()' accordingly.

Signed-off-by: Dmitry Antipov <[email protected]>
---
 net/wireless/mlme.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/wireless/mlme.c b/net/wireless/mlme.c
index 9d577523462d..4790136758d5 100644
--- a/net/wireless/mlme.c
+++ b/net/wireless/mlme.c
@@ -575,7 +575,7 @@ struct cfg80211_mgmt_registration {
 
        bool multicast_rx;
 
-       u8 match[];
+       u8 match[] __counted_by(match_len);
 };
 
 static void cfg80211_mgmt_registrations_update(struct wireless_dev *wdev)
@@ -710,8 +710,8 @@ int cfg80211_mlme_register_mgmt(struct wireless_dev *wdev, 
u32 snd_portid,
        if (update_multicast) {
                kfree(nreg);
        } else {
-               memcpy(nreg->match, match_data, match_len);
                nreg->match_len = match_len;
+               memcpy(nreg->match, match_data, match_len);
                nreg->nlportid = snd_portid;
                nreg->frame_type = cpu_to_le16(frame_type);
                nreg->wdev = wdev;
-- 
2.47.1


Reply via email to