mac80211: consider Order bit to fill CCMP AAD
PATCH 1/1 mac80211: consider Order bit to fill CCMP AAD
Follow IEEE 802.11-21 that HTC subfield masked to 0 for all data frames containing a QoS Control field. It also defines the AAD length depends on QC and A4 fields, so change logic to determine length accordingly.
--- net/mac80211/wpa.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
net/mac80211/wpa.c +9 -7
@@ -317,13 +317,12 @@ static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad)__le16 mask_fc;int a4_included, mgmt;u8 qos_tid; -u16 len_a; -unsigned int hdrlen; +u16 len_a =22 ;struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;/* * Mask FC: zero subtype b4 b5 b6 (if not mgmt) -* Retry, PwrMgt, MoreData; set Protected +* Retry, PwrMgt, MoreData, Order (if Qos Data); set Protected */ mgmt =ieee80211_is_mgmt (hdr->frame_control); mask_fc = hdr->frame_control;
@@ -333,14 +332,17 @@ static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad) mask_fc &= ~cpu_to_le16 (0x0070 ); mask_fc |=cpu_to_le16 (IEEE80211_FCTL_PROTECTED ); - hdrlen =ieee80211_hdrlen (hdr->frame_control); - len_a = hdrlen -2 ; a4_included =ieee80211_has_a4 (hdr->frame_control); +if (a4_included) + len_a +=6 ; -if (ieee80211_is_data_qos (hdr->frame_control)) +if (ieee80211_is_data_qos (hdr->frame_control)) { qos_tid =ieee80211_get_tid (hdr); -else + mask_fc &= ~cpu_to_le16 (IEEE80211_FCTL_ORDER ); + len_a +=2 ; + }else { qos_tid =0 ; + }/* In CCM, the initial vectors (IV) used for CTR mode encryption and CBC * mode authentication are not allowed to collide, yet both are derived
Signature · 1 line
2.25.1
Johannes Berg
maintainerQuoted 3 lines · Ping-Ke Shih
Follow IEEE 802.11-21 that HTC subfield masked to 0 for all data frames containing a QoS Control field.
That seems fine, though not sure it's actually _relevant_ - how would we possibly generate such frames in mac80211?
Quoted 2 lines
It also defines the AAD length depends on
QC and A4 fields, so change logic to determine length accordingly.
This I don't understand.
The code
net/mac80211/wpa.c static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad) · line 337
Quoted 2 lines
net/mac80211/wpa.c +0
-2- hdrlen =ieee80211_hdrlen (hdr->frame_control); - len_a = hdrlen -2 ;
sets it to the same thing, no?
Oh, I see - again you're worried about IEEE80211_HT_CTL_LEN I guess?
Maybe just subtract that again?
But either way, I'm not sure how we'd generate these in the first place.
johannes
Quoted 8 lines
-----Original Message-----
From: Johannes Berg <[email protected]>
Sent: Monday, April 11, 2022 5:12 PM
To: Pkshih <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] mac80211: consider Order bit to fill CCMP AAD
Quoted 7 lines
Quoted 3 lines · Ping-Ke Shih
Follow IEEE 802.11-21 that HTC subfield masked to 0 for all data frames containing a QoS Control field.
That seems fine, though not sure it's actually _relevant_ - how would we possibly generate such frames in mac80211?
I suddenly meet this case, because hardware decryption isn't configured properly during development, so it falls into software decryption. The received packets can possibly contain HTC.
After I fix my driver, I don't need this, but I think it is worth to have this patch.
Quoted 5 lines
Quoted 3 lines
It also defines the AAD length depends on
QC and A4 fields, so change logic to determine length accordingly.This I don't understand.
IEEE 802.11-21 illustrate the use cases as below
QC Field A4 Field AAD length
------- -------- ---------
x x 22
o x 24
x o 28
o o 30I write logic along with this table, because it would be clear and simple.
Quoted 8 lines
The code
net/mac80211/wpa.c static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad) · line 337
Quoted 2 lines
net/mac80211/wpa.c +0
-2- hdrlen =ieee80211_hdrlen (hdr->frame_control); - len_a = hdrlen -2 ;sets it to the same thing, no?
Since AAD consists of "FC | A1 | A2 | A3 | SC | [A4] | [QC]" I think '-2' here means AAD doesn't contain 'Duration' field.
Quoted 4 lines
Oh, I see - again you're worried about
IEEE80211_HT_CTL_LENI guess?Maybe just subtract that again?
Yes, we can subtract length from ieee80211_hdrlen().
But, this function is called in data path that means every packet can use it. Is it reasonable to += IEEE80211_HT_CTL_LEN in ieee80211_hdrlen() and -= IEEE80211_HT_CTL_LEN right after leaving ieee80211_hdrlen() if the packet is ieee80211_has_order()?
Ping-Ke
Johannes Berg
maintainerQuoted 10 lines · Pkshih
Quoted 4 lines
That seems fine, though not sure it's actually _relevant_ - how would we
possibly generate such frames in mac80211?I suddenly meet this case, because hardware decryption isn't configured properly
during development, so it falls into software decryption. The received packets
can possibly contain HTC.
Haha, right. I'm an idiot I guess, why did I not think of RX?
Quoted 3 lines
After I fix my driver, I don't need this, but I think it is worth to have
this patch.
OK. But I guess that means no hurry.
Quoted 5 lines
Quoted 4 lines
Oh, I see - again you're worried about
IEEE80211_HT_CTL_LENI guess?Maybe just subtract that again?
Quoted 7 lines
Yes, we can subtract length from
ieee80211_hdrlen().
But, this function is called in data path that means every packet can use it.
Is it reasonable to +=IEEE80211_HT_CTL_LENinieee80211_hdrlen()and -=IEEE80211_HT_CTL_LENright after leavingieee80211_hdrlen()if the packet isieee80211_has_order()?
Yeah, thinking about that, I guess you're right. Maybe we can express the 22 a bit better (some headerlen - 2 with a comment?), but I can look at that when I apply the patch.
Thanks!
johannes
Quoted 8 lines
-----Original Message-----
From: Johannes Berg <[email protected]>
Sent: Tuesday, April 12, 2022 1:47 PM
To: Pkshih <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH] mac80211: consider Order bit to fill CCMP AAD
Quoted 6 lines
Quoted 3 lines · Pkshih
After I fix my driver, I don't need this, but I think it is worth to have
this patch.OK. But I guess that means no hurry.
Yes.
Quoted 4 lines
Yeah, thinking about that, I guess you're right. Maybe we can express the 22 a bit better (some headerlen - 2 with a comment?), but I can look at that when I apply the patch.
How about replacing 22 by 2 + 6 + 6 + 6 + 2 because of "FC | A1 | A2 | A3 | SC | [A4] | [QC]" ?
Ping-Ke
net/mac80211/wpa.c static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad) · line 320
Quoted 11 lines · Ping-Ke Shih
Follow IEEE 802.11-21 that HTC subfield masked to 0 for all data frames containing a QoS Control field. It also defines the AAD length depends on QC and A4 fields, so change logic to determine length accordingly.
net/mac80211/wpa.c +1
-1@@ -317,13 +317,12 @@ static void ccmp_special_blocks(struct sk_buff *skb, u8 *pn, u8 *b_0, u8 *aad)/* * Mask FC: zero subtype b4 b5 b6 (if not mgmt) -* Retry, PwrMgt, MoreData; set Protected +* Retry, PwrMgt, MoreData, Order (if Qos Data); set Protected */
...
For completeness, we should really do the same got GCMP AAD which is identical to the CCMP AAD. In other words, these changes should be done in gcmp_special_blocks() as well. Those functions should really have next to identical implementation for the AAD part (nonce construction is different, though). There were already some differences in the design before.. Maybe all this AAD stuff should really be moved into a separate helper function that both CCMP and GCMP could use.
Signature · 1 line
Jouni Malinen PGP id EFC895FA