Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

wifi: mac80211: kunit: extend MFP tests

Extend the MFP tests to handle the case of deauth/disassoc
and robust action frames (that are not protected dual of
public action frames).

Reviewed-by: Gregory Greenman <gregory.greenman@intel.com>
Link: https://msgid.link/20231220151952.415232-6-benjamin@sipsolutions.net
Signed-off-by: Johannes Berg <johannes.berg@intel.com>

+70 -4
+70 -4
net/mac80211/tests/mfp.c
··· 13 13 14 14 static const struct mfp_test_case { 15 15 const char *desc; 16 - bool sta, mfp, decrypted, unicast; 16 + bool sta, mfp, decrypted, unicast, assoc; 17 17 u8 category; 18 18 u8 stype; 19 19 u8 action; ··· 151 151 .mfp = true, 152 152 .result = RX_CONTINUE, 153 153 }, 154 + /* deauth/disassoc before keys are set */ 155 + { 156 + .desc = "deauth: accept unicast with MFP but w/o key", 157 + .stype = IEEE80211_STYPE_DEAUTH, 158 + .sta = true, 159 + .mfp = true, 160 + .unicast = true, 161 + .result = RX_CONTINUE, 162 + }, 163 + { 164 + .desc = "disassoc: accept unicast with MFP but w/o key", 165 + .stype = IEEE80211_STYPE_DEAUTH, 166 + .sta = true, 167 + .mfp = true, 168 + .unicast = true, 169 + .result = RX_CONTINUE, 170 + }, 171 + /* non-public robust action frame ... */ 172 + { 173 + .desc = "BA action: drop unicast before assoc", 174 + .stype = IEEE80211_STYPE_ACTION, 175 + .category = WLAN_CATEGORY_BACK, 176 + .unicast = true, 177 + .sta = true, 178 + .result = RX_DROP_U_UNPROT_ROBUST_ACTION, 179 + }, 180 + { 181 + .desc = "BA action: drop unprotected after assoc", 182 + .stype = IEEE80211_STYPE_ACTION, 183 + .category = WLAN_CATEGORY_BACK, 184 + .unicast = true, 185 + .sta = true, 186 + .mfp = true, 187 + .result = RX_DROP_U_UNPROT_UCAST_MGMT, 188 + }, 189 + { 190 + .desc = "BA action: accept unprotected without MFP", 191 + .stype = IEEE80211_STYPE_ACTION, 192 + .category = WLAN_CATEGORY_BACK, 193 + .unicast = true, 194 + .sta = true, 195 + .assoc = true, 196 + .mfp = false, 197 + .result = RX_CONTINUE, 198 + }, 199 + { 200 + .desc = "BA action: drop unprotected with MFP", 201 + .stype = IEEE80211_STYPE_ACTION, 202 + .category = WLAN_CATEGORY_BACK, 203 + .unicast = true, 204 + .sta = true, 205 + .mfp = true, 206 + .result = RX_DROP_U_UNPROT_UCAST_MGMT, 207 + }, 154 208 }; 155 209 156 210 KUNIT_ARRAY_PARAM_DESC(accept_mfp, accept_mfp_cases, desc); 157 211 158 212 static void accept_mfp(struct kunit *test) 159 213 { 160 - static struct sta_info sta = {}; 214 + static struct sta_info sta; 161 215 const struct mfp_test_case *params = test->param_value; 162 216 struct ieee80211_rx_data rx = { 163 217 .sta = params->sta ? &sta : NULL, ··· 225 171 /* A3/BSSID doesn't matter here */ 226 172 }; 227 173 174 + memset(&sta, 0, sizeof(sta)); 175 + 228 176 if (!params->sta) { 229 177 KUNIT_ASSERT_FALSE(test, params->mfp); 230 178 KUNIT_ASSERT_FALSE(test, params->decrypted); ··· 234 178 235 179 if (params->mfp) 236 180 set_sta_flag(&sta, WLAN_STA_MFP); 181 + 182 + if (params->assoc) 183 + set_bit(WLAN_STA_ASSOC, &sta._flags); 237 184 238 185 rx.skb = kunit_zalloc_skb(test, 128, GFP_KERNEL); 239 186 KUNIT_ASSERT_NOT_NULL(test, rx.skb); ··· 259 200 skb_put_u8(rx.skb, params->category); 260 201 skb_put_u8(rx.skb, params->action); 261 202 break; 203 + case IEEE80211_STYPE_DEAUTH: 204 + case IEEE80211_STYPE_DISASSOC: { 205 + __le16 reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); 206 + 207 + skb_put_data(rx.skb, &reason, sizeof(reason)); 208 + } 209 + break; 262 210 } 263 211 264 212 KUNIT_EXPECT_EQ(test, 265 - ieee80211_drop_unencrypted_mgmt(&rx), 266 - params->result); 213 + (__force u32)ieee80211_drop_unencrypted_mgmt(&rx), 214 + (__force u32)params->result); 267 215 } 268 216 269 217 static struct kunit_case mfp_test_cases[] = {