mac802154: llsec: reject frames shorter than the authentication tag
Subsystems (4)
PATCH 1/1 mac802154: llsec: reject frames shorter than the authentication tag
llsec_do_decrypt_auth() computes the associated-data length for the AEAD request as
assoclen += datalen - authlen;
where datalen is the number of bytes after the MAC header and authlen (4, 8 or 16) is the length of the authentication tag. Nothing verifies that the frame actually carries at least authlen payload bytes. A secured frame whose payload is shorter than the tag makes datalen - authlen negative; assoclen is then passed to aead_request_set_ad() as an unsigned value close to 4 GiB, so crypto_aead_decrypt() walks far off the end of the scatterlist that only spans the real frame.
The frame is fully attacker-controlled and reaches this path from any IEEE 802.15.4 peer in radio range. Reject frames whose payload is shorter than the authentication tag before the subtraction.
Dynamically reproduced on a KASAN kernel as a general-protection-fault in the AEAD scatterwalk, and the fix confirmed.
--- net/mac802154/llsec.c | 5 +++++ 1 file changed, 5 insertions(+)
net/mac802154/llsec.c +5 -0
@@ -893,6 +893,11 @@ llsec_do_decrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec,sg_init_one (&sg,skb_mac_header (skb), assoclen + datalen); +if (datalen < authlen) { +kfree_sensitive (req); +return -EBADMSG ; + } +if (!(hdr->sec.level &IEEE802154_SCF_SECLEVEL_ENC )) { assoclen += datalen - authlen; datalen = authlen;
Signature · 1 line
2.43.0
Quoted 18 lines · Doruk Tan Ozturk
llsec_do_decrypt_auth()computes the associated-data length for the AEAD request asassoclen += datalen - authlen;where datalen is the number of bytes after the MAC header and authlen (4, 8 or 16) is the length of the authentication tag. Nothing verifies that the frame actually carries at least authlen payload bytes. A secured frame whose payload is shorter than the tag makes datalen - authlen negative; assoclen is then passed to
aead_request_set_ad()as an unsigned value close to 4 GiB, socrypto_aead_decrypt()walks far off the end of the scatterlist that only spans the real frame.The frame is fully attacker-controlled and reaches this path from any IEEE 802.15.4 peer in radio range. Reject frames whose payload is shorter than the authentication tag before the subtraction.
Quoted 8 lines
Dynamically reproduced on a KASAN kernel as a general-protection-fault in the AEAD scatterwalk, and the fix confirmed.
Fixes 4c14a2fb5d14 ("mac802154: add llsec decryption method")Reported-by Doruk Tan Ozturk <[email protected]>Assisted-by 0sec:claude-opus-4-8Signed-off-by Doruk Tan Ozturk <[email protected]>
Quoted 2 lines · Doruk Tan Ozturk
Reported-by Doruk Tan Ozturk <[email protected]>Signed-off-by Doruk Tan Ozturk <[email protected]>
Usually you don't have Reported-by if you are fixing something yourself.
net/mac802154/llsec.c llsec_do_decrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec,
Quoted 9 lines
--- net/mac802154/llsec.c | 5 +++++ 1 file changed, 5 insertions(+)net/mac802154/llsec.c +0
-0@@ -893,6 +893,11 @@ llsec_do_decrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec,
Why not returning here, before sg_init_one()? here you alrady have datalen and authlen.
Quoted 14 lines
net/mac802154/llsec.c +5
-0sg_init_one (&sg,skb_mac_header (skb), assoclen + datalen); +if (datalen < authlen) { +kfree_sensitive (req); +return -EBADMSG ; + } +if (!(hdr->sec.level &IEEE802154_SCF_SECLEVEL_ENC )) { assoclen += datalen - authlen; datalen = authlen;Signature · 1 line
2.43.0
Will do both in v2, thanks.
-Doruk
PATCH v2 1/1 mac802154: llsec: reject frames shorter than the authentication tag
In reply to Doruk Tan Ozturkllsec_do_decrypt_auth() computes the associated-data length for the AEAD request as
assoclen += datalen - authlen;
where datalen is the number of bytes after the MAC header and authlen (4, 8 or 16) is the length of the authentication tag. Nothing verifies that the frame actually carries at least authlen payload bytes. A secured frame whose payload is shorter than the tag makes datalen - authlen negative; assoclen is then passed to aead_request_set_ad() as an unsigned value close to 4 GiB, so crypto_aead_decrypt() walks far off the end of the scatterlist that only spans the real frame.
The frame is fully attacker-controlled and reaches this path from any IEEE 802.15.4 peer in radio range. Reject frames whose payload is shorter than the authentication tag before the subtraction.
Dynamically reproduced on a KASAN kernel as a general-protection-fault in the AEAD scatterwalk, and the fix confirmed.
---
v2 (Breno Leitao review):
- drop the redundant self-Reported-by.
- move the length check above sg_init_one() (datalen/authlen are already available there).
- Assisted-by trailer -> 0sec:multi-model.
Carrying Simon Horman Reviewed-by; v2 only moves the same check earlier.
net/mac802154/llsec.c | 5 +++++ 1 file changed, 5 insertions(+)
net/mac802154/llsec.c +5 -0
@@ -891,6 +891,11 @@ llsec_do_decrypt_auth(struct sk_buff *skb, const struct mac802154_llsec *sec, data =skb_mac_header (skb) + skb->mac_len; datalen =skb_tail_pointer (skb) - data; +if (datalen < authlen) { +kfree_sensitive (req); +return -EBADMSG ; + } +sg_init_one (&sg,skb_mac_header (skb), assoclen + datalen);if (!(hdr->sec.level &IEEE802154_SCF_SECLEVEL_ENC )) {
Signature · 1 line
2.43.0
Quoted 18 lines · Doruk Tan Ozturk
llsec_do_decrypt_auth()computes the associated-data length for the AEAD request asassoclen += datalen - authlen;where datalen is the number of bytes after the MAC header and authlen (4, 8 or 16) is the length of the authentication tag. Nothing verifies that the frame actually carries at least authlen payload bytes. A secured frame whose payload is shorter than the tag makes datalen - authlen negative; assoclen is then passed to
aead_request_set_ad()as an unsigned value close to 4 GiB, socrypto_aead_decrypt()walks far off the end of the scatterlist that only spans the real frame.The frame is fully attacker-controlled and reaches this path from any IEEE 802.15.4 peer in radio range. Reject frames whose payload is shorter than the authentication tag before the subtraction.
Quoted 8 lines
Dynamically reproduced on a KASAN kernel as a general-protection-fault in the AEAD scatterwalk, and the fix confirmed.
Fixes 4c14a2fb5d14 ("mac802154: add llsec decryption method")Assisted-by 0sec:multi-modelReviewed-by Simon Horman <[email protected]>Signed-off-by Doruk Tan Ozturk <[email protected]>