Skip to content

Commit 60fb882

Browse files
fg-cfhnashif
authored andcommitted
net: l2: ieee802154: decouple frame decryption from upper layer fields
The L2 function `ieee802154_decipher_data_frame()` relied on upper layer LL address fields which breaks encapsulation. Also fixes a bug introduced in another fix that went overboard (#53734). Fixes: #78490 Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de> (cherry picked from commit da0371a)
1 parent 110eb53 commit 60fb882

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

subsys/net/l2/ieee802154/ieee802154.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,10 @@ static inline void swap_and_set_pkt_ll_addr(struct net_linkaddr *addr, bool has_
271271
addr->addr = NULL;
272272
}
273273

274-
/* The net stack expects link layer addresses to be in
275-
* big endian format for posix compliance so we must swap it.
276-
* This is ok as the L2 address field comes from the header
277-
* part of the packet buffer which will not be directly accessible
278-
* once the packet reaches the upper layers.
274+
/* The net stack expects big endian link layer addresses for POSIX compliance
275+
* so we must swap it. This is ok as the L2 address field points into the L2
276+
* header of the frame buffer which will no longer be accessible once the
277+
* packet reaches upper layers.
279278
*/
280279
if (addr->len > 0) {
281280
sys_mem_swap(addr->addr, addr->len);
@@ -435,9 +434,9 @@ static enum net_verdict ieee802154_recv(struct net_if *iface, struct net_pkt *pk
435434
return NET_DROP;
436435
}
437436

438-
/* Setting L2 addresses must be done after packet authentication and internal
439-
* packet handling as it will mangle the package header to comply with upper
440-
* network layers' (POSIX) requirement to represent network addresses in big endian.
437+
/* Setting LL addresses for upper layers must be done after L2 packet
438+
* handling as it will mangle the L2 frame header to comply with upper
439+
* layers' (POSIX) requirement to represent network addresses in big endian.
441440
*/
442441
swap_and_set_pkt_ll_addr(net_pkt_lladdr_src(pkt), !fs->fc.pan_id_comp,
443442
fs->fc.src_addr_mode, mpdu.mhr.src_addr);

subsys/net/l2/ieee802154/ieee802154_frame.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -934,8 +934,8 @@ bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_pkt *pkt,
934934
{
935935
struct ieee802154_context *ctx = net_if_l2_data(iface);
936936
uint8_t level, authtag_len, ll_hdr_len, payload_len;
937-
int8_t ext_addr_le[IEEE802154_EXT_ADDR_LENGTH];
938937
struct ieee802154_mhr *mhr = &mpdu->mhr;
938+
struct ieee802154_address *src;
939939
bool ret = false;
940940

941941
k_sem_take(&ctx->ctx_lock, K_FOREVER);
@@ -970,14 +970,15 @@ bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_pkt *pkt,
970970
* This will require to look up in nbr cache with short addr
971971
* in order to get the extended address related to it.
972972
*/
973-
if (net_pkt_lladdr_src(pkt)->len != IEEE802154_EXT_ADDR_LENGTH) {
974-
NET_ERR("Decrypting packages with short source addresses is not supported.");
973+
if (mhr->fs->fc.src_addr_mode != IEEE802154_ADDR_MODE_EXTENDED) {
974+
NET_ERR("Only encrypting packages with extended source addresses is supported.");
975975
goto out;
976976
}
977977

978-
sys_memcpy_swap(ext_addr_le, net_pkt_lladdr_src(pkt)->addr, net_pkt_lladdr_src(pkt)->len);
978+
src = mhr->fs->fc.pan_id_comp ? &mhr->src_addr->comp.addr : &mhr->src_addr->plain.addr;
979+
979980
if (!ieee802154_decrypt_auth(&ctx->sec_ctx, net_pkt_data(pkt), ll_hdr_len, payload_len,
980-
authtag_len, ext_addr_le,
981+
authtag_len, src->ext_addr,
981982
sys_le32_to_cpu(mhr->aux_sec->frame_counter))) {
982983
NET_ERR("Could not decipher the frame");
983984
goto out;

0 commit comments

Comments
 (0)