Commit bbd97bbe authored by Johannes Berg's avatar Johannes Berg

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: default avatarGregory Greenman <gregory.greenman@intel.com>
Link: https://msgid.link/20231220151952.415232-6-benjamin@sipsolutions.netSigned-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
parent 951c4684
...@@ -13,7 +13,7 @@ MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING); ...@@ -13,7 +13,7 @@ MODULE_IMPORT_NS(EXPORTED_FOR_KUNIT_TESTING);
static const struct mfp_test_case { static const struct mfp_test_case {
const char *desc; const char *desc;
bool sta, mfp, decrypted, unicast; bool sta, mfp, decrypted, unicast, assoc;
u8 category; u8 category;
u8 stype; u8 stype;
u8 action; u8 action;
...@@ -151,13 +151,67 @@ static const struct mfp_test_case { ...@@ -151,13 +151,67 @@ static const struct mfp_test_case {
.mfp = true, .mfp = true,
.result = RX_CONTINUE, .result = RX_CONTINUE,
}, },
/* deauth/disassoc before keys are set */
{
.desc = "deauth: accept unicast with MFP but w/o key",
.stype = IEEE80211_STYPE_DEAUTH,
.sta = true,
.mfp = true,
.unicast = true,
.result = RX_CONTINUE,
},
{
.desc = "disassoc: accept unicast with MFP but w/o key",
.stype = IEEE80211_STYPE_DEAUTH,
.sta = true,
.mfp = true,
.unicast = true,
.result = RX_CONTINUE,
},
/* non-public robust action frame ... */
{
.desc = "BA action: drop unicast before assoc",
.stype = IEEE80211_STYPE_ACTION,
.category = WLAN_CATEGORY_BACK,
.unicast = true,
.sta = true,
.result = RX_DROP_U_UNPROT_ROBUST_ACTION,
},
{
.desc = "BA action: drop unprotected after assoc",
.stype = IEEE80211_STYPE_ACTION,
.category = WLAN_CATEGORY_BACK,
.unicast = true,
.sta = true,
.mfp = true,
.result = RX_DROP_U_UNPROT_UCAST_MGMT,
},
{
.desc = "BA action: accept unprotected without MFP",
.stype = IEEE80211_STYPE_ACTION,
.category = WLAN_CATEGORY_BACK,
.unicast = true,
.sta = true,
.assoc = true,
.mfp = false,
.result = RX_CONTINUE,
},
{
.desc = "BA action: drop unprotected with MFP",
.stype = IEEE80211_STYPE_ACTION,
.category = WLAN_CATEGORY_BACK,
.unicast = true,
.sta = true,
.mfp = true,
.result = RX_DROP_U_UNPROT_UCAST_MGMT,
},
}; };
KUNIT_ARRAY_PARAM_DESC(accept_mfp, accept_mfp_cases, desc); KUNIT_ARRAY_PARAM_DESC(accept_mfp, accept_mfp_cases, desc);
static void accept_mfp(struct kunit *test) static void accept_mfp(struct kunit *test)
{ {
static struct sta_info sta = {}; static struct sta_info sta;
const struct mfp_test_case *params = test->param_value; const struct mfp_test_case *params = test->param_value;
struct ieee80211_rx_data rx = { struct ieee80211_rx_data rx = {
.sta = params->sta ? &sta : NULL, .sta = params->sta ? &sta : NULL,
...@@ -171,6 +225,8 @@ static void accept_mfp(struct kunit *test) ...@@ -171,6 +225,8 @@ static void accept_mfp(struct kunit *test)
/* A3/BSSID doesn't matter here */ /* A3/BSSID doesn't matter here */
}; };
memset(&sta, 0, sizeof(sta));
if (!params->sta) { if (!params->sta) {
KUNIT_ASSERT_FALSE(test, params->mfp); KUNIT_ASSERT_FALSE(test, params->mfp);
KUNIT_ASSERT_FALSE(test, params->decrypted); KUNIT_ASSERT_FALSE(test, params->decrypted);
...@@ -179,6 +235,9 @@ static void accept_mfp(struct kunit *test) ...@@ -179,6 +235,9 @@ static void accept_mfp(struct kunit *test)
if (params->mfp) if (params->mfp)
set_sta_flag(&sta, WLAN_STA_MFP); set_sta_flag(&sta, WLAN_STA_MFP);
if (params->assoc)
set_bit(WLAN_STA_ASSOC, &sta._flags);
rx.skb = kunit_zalloc_skb(test, 128, GFP_KERNEL); rx.skb = kunit_zalloc_skb(test, 128, GFP_KERNEL);
KUNIT_ASSERT_NOT_NULL(test, rx.skb); KUNIT_ASSERT_NOT_NULL(test, rx.skb);
status = IEEE80211_SKB_RXCB(rx.skb); status = IEEE80211_SKB_RXCB(rx.skb);
...@@ -200,11 +259,18 @@ static void accept_mfp(struct kunit *test) ...@@ -200,11 +259,18 @@ static void accept_mfp(struct kunit *test)
skb_put_u8(rx.skb, params->category); skb_put_u8(rx.skb, params->category);
skb_put_u8(rx.skb, params->action); skb_put_u8(rx.skb, params->action);
break; break;
case IEEE80211_STYPE_DEAUTH:
case IEEE80211_STYPE_DISASSOC: {
__le16 reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
skb_put_data(rx.skb, &reason, sizeof(reason));
}
break;
} }
KUNIT_EXPECT_EQ(test, KUNIT_EXPECT_EQ(test,
ieee80211_drop_unencrypted_mgmt(&rx), (__force u32)ieee80211_drop_unencrypted_mgmt(&rx),
params->result); (__force u32)params->result);
} }
static struct kunit_case mfp_test_cases[] = { static struct kunit_case mfp_test_cases[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment