Skip to contentSkip to conversation

mac802154: remove redundant security_enabled assignment

PATCH In review Petr Vaganov 3 participants 5 messages Nov 16 – Nov 20

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mac802154: remove redundant security_enabled assignment

During fuzz testing, the following issue was discovered:

BUG: KMSAN: uninit-value in ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:54 [inline]
BUG: KMSAN: uninit-value in ieee802154_hdr_push+0xa62/0xb20 net/ieee802154/header_ops.c:108
 ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:54 [inline]
 ieee802154_hdr_push+0xa62/0xb20 net/ieee802154/header_ops.c:108
 ieee802154_header_create+0xa83/0xd20 net/mac802154/iface.c:396
 wpan_dev_hard_header include/net/cfg802154.h:525 [inline]
 dgram_sendmsg+0xc6d/0x15d0 net/ieee802154/socket.c:677
 ieee802154_sock_sendmsg+0x8f/0xd0 net/ieee802154/socket.c:96
 sock_sendmsg_nosec net/socket.c:711 [inline]
 __sock_sendmsg+0x2f3/0x360 net/socket.c:726
 ____sys_sendmsg+0x960/0xc30 net/socket.c:2581
 ___sys_sendmsg+0x285/0x3e0 net/socket.c:2635
 __sys_sendmmsg+0x33c/0x950 net/socket.c:2724
 __do_sys_sendmmsg net/socket.c:2751 [inline]
 __se_sys_sendmmsg net/socket.c:2748 [inline]
 __x64_sys_sendmmsg+0xc6/0x150 net/socket.c:2748
 x64_sys_call+0x12a8/0x3cf0 arch/x86/include/generated/asm/syscalls_64.h:308
 do_syscall_x64 arch/x86/entry/common.c:47 [inline]
 do_syscall_64+0xd9/0x1c0 arch/x86/entry/common.c:78
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Uninit was stored to memory at:

 ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:51 [inline]
 ieee802154_hdr_push+0xa5b/0xb20 net/ieee802154/header_ops.c:108
 ieee802154_header_create+0xa83/0xd20 net/mac802154/iface.c:396
 wpan_dev_hard_header include/net/cfg802154.h:525 [inline]
 dgram_sendmsg+0xc6d/0x15d0 net/ieee802154/socket.c:677
 ieee802154_sock_sendmsg+0x8f/0xd0 net/ieee802154/socket.c:96
 sock_sendmsg_nosec net/socket.c:711 [inline]
 __sock_sendmsg+0x2f3/0x360 net/socket.c:726
 ____sys_sendmsg+0x960/0xc30 net/socket.c:2581
 ___sys_sendmsg+0x285/0x3e0 net/socket.c:2635
 __sys_sendmmsg+0x33c/0x950 net/socket.c:2724
 __do_sys_sendmmsg net/socket.c:2751 [inline]
 __se_sys_sendmmsg net/socket.c:2748 [inline]
 __x64_sys_sendmmsg+0xc6/0x150 net/socket.c:2748
 x64_sys_call+0x12a8/0x3cf0 arch/x86/include/generated/asm/syscalls_64.h:308
 do_syscall_x64 arch/x86/entry/common.c:47 [inline]
 do_syscall_64+0xd9/0x1c0 arch/x86/entry/common.c:78
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Commit f30be4d53cad ("mac802154: integrate llsec with wpan devices") introduced mac802154_set_header_security() as the sole function responsible for enabling frame-level security: it sets both hdr->fc.security_enabled = 1 and initializes hdr->sec together, maintaining the invariant that security_enabled = 1 implies hdr->sec is initialized.

However, ieee802154_header_create() was left with a pre-existing assignment:

    hdr.fc.security_enabled = cb->secen;

This assignment can set security_enabled = 1 (from a stale cb->secen) even when mac802154_set_header_security() returns 0 without initializing hdr.sec, violating that invariant. ieee802154_hdr_push_sechdr() then reads uninitialized hdr.sec fields.

The stale value in cb->secen arises from a specific setsockopt()
sequence: calling WPAN_SECURITY_ON (secen_override=1, secen=1) and then WPAN_SECURITY_DEFAULT (secen_override=0, secen unchanged at 1). This undocumented combination likely explains why the bug was rarely triggered.

Remove the redundant assignment; mac802154_set_header_security() is the only correct place to set security_enabled.

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

---
 net/mac802154/iface.c | 1 -
 1 file changed, 1 deletion(-)
net/mac802154/iface.c +0 -1
index f437b8daa00d..7b7332805ecc 100644
@@ -368,7 +368,6 @@ static int ieee802154_header_create(struct sk_buff *skb,
 
 	memset(&hdr.fc, 0, sizeof(hdr.fc));
 	hdr.fc.type = cb->type;
-	hdr.fc.security_enabled = cb->secen;
 	hdr.fc.ack_request = cb->ackreq;
 	hdr.seq = atomic_inc_return(&dev->ieee802154_ptr->dsn) & 0xFF;
 
Signature · 1 line
2.55.0
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 85 lines · Petr Vaganov

During fuzz testing, the following issue was discovered:

BUG: KMSAN: uninit-value in ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:54 [inline]
BUG: KMSAN: uninit-value in ieee802154_hdr_push+0xa62/0xb20 net/ieee802154/header_ops.c:108
 ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:54 [inline]
 ieee802154_hdr_push+0xa62/0xb20 net/ieee802154/header_ops.c:108
 ieee802154_header_create+0xa83/0xd20 net/mac802154/iface.c:396
 wpan_dev_hard_header include/net/cfg802154.h:525 [inline]
 dgram_sendmsg+0xc6d/0x15d0 net/ieee802154/socket.c:677
 ieee802154_sock_sendmsg+0x8f/0xd0 net/ieee802154/socket.c:96
 sock_sendmsg_nosec net/socket.c:711 [inline]
 __sock_sendmsg+0x2f3/0x360 net/socket.c:726
 ____sys_sendmsg+0x960/0xc30 net/socket.c:2581
 ___sys_sendmsg+0x285/0x3e0 net/socket.c:2635
 __sys_sendmmsg+0x33c/0x950 net/socket.c:2724
 __do_sys_sendmmsg net/socket.c:2751 [inline]
 __se_sys_sendmmsg net/socket.c:2748 [inline]
 __x64_sys_sendmmsg+0xc6/0x150 net/socket.c:2748
 x64_sys_call+0x12a8/0x3cf0 arch/x86/include/generated/asm/syscalls_64.h:308
 do_syscall_x64 arch/x86/entry/common.c:47 [inline]
 do_syscall_64+0xd9/0x1c0 arch/x86/entry/common.c:78
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Uninit was stored to memory at:

 ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:51 [inline]
 ieee802154_hdr_push+0xa5b/0xb20 net/ieee802154/header_ops.c:108
 ieee802154_header_create+0xa83/0xd20 net/mac802154/iface.c:396
 wpan_dev_hard_header include/net/cfg802154.h:525 [inline]
 dgram_sendmsg+0xc6d/0x15d0 net/ieee802154/socket.c:677
 ieee802154_sock_sendmsg+0x8f/0xd0 net/ieee802154/socket.c:96
 sock_sendmsg_nosec net/socket.c:711 [inline]
 __sock_sendmsg+0x2f3/0x360 net/socket.c:726
 ____sys_sendmsg+0x960/0xc30 net/socket.c:2581
 ___sys_sendmsg+0x285/0x3e0 net/socket.c:2635
 __sys_sendmmsg+0x33c/0x950 net/socket.c:2724
 __do_sys_sendmmsg net/socket.c:2751 [inline]
 __se_sys_sendmmsg net/socket.c:2748 [inline]
 __x64_sys_sendmmsg+0xc6/0x150 net/socket.c:2748
 x64_sys_call+0x12a8/0x3cf0 arch/x86/include/generated/asm/syscalls_64.h:308
 do_syscall_x64 arch/x86/entry/common.c:47 [inline]
 do_syscall_64+0xd9/0x1c0 arch/x86/entry/common.c:78
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Commit f30be4d53cad ("mac802154: integrate llsec with wpan devices") introduced mac802154_set_header_security() as the sole function responsible for enabling frame-level security: it sets both hdr->fc.security_enabled = 1 and initializes hdr->sec together, maintaining the invariant that security_enabled = 1 implies hdr->sec is initialized.

However, ieee802154_header_create() was left with a pre-existing assignment:

    hdr.fc.security_enabled = cb->secen;

This assignment can set security_enabled = 1 (from a stale cb->secen) even when mac802154_set_header_security() returns 0 without initializing hdr.sec, violating that invariant. ieee802154_hdr_push_sechdr() then reads uninitialized hdr.sec fields.

The stale value in cb->secen arises from a specific setsockopt()
sequence: calling WPAN_SECURITY_ON (secen_override=1, secen=1) and then WPAN_SECURITY_DEFAULT (secen_override=0, secen unchanged at 1). This undocumented combination likely explains why the bug was rarely triggered.

Remove the redundant assignment; mac802154_set_header_security() is the only correct place to set security_enabled.

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

---
 net/mac802154/iface.c | 1 -
 1 file changed, 1 deletion(-)
net/mac802154/iface.c +0 -0
index f437b8daa00d..7b7332805ecc 100644

net/mac802154/iface.c static int ieee802154_header_create(struct sk_buff *skb, · line 372

Quoted 6 lines
net/mac802154/iface.c +0 -1
@@ -368,7 +368,6 @@ static int ieee802154_header_create(struct sk_buff *skb,
 
 	memset(&hdr.fc, 0, sizeof(hdr.fc));
 	hdr.fc.type = cb->type;
-	hdr.fc.security_enabled = cb->secen;
 	hdr.fc.ack_request = cb->ackreq;
 	hdr.seq = atomic_inc_return(&dev->ieee802154_ptr->dsn) & 0xFF;

There has been a similar patch in 2023 but it was never updated by the author. Fixes tag is better here, it should be taken.

Thanks,
Miquèl

#2 lore raw
In reply to Petr Vaganov
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [High] The fix relies on an invariant that does not hold.
- [Low] The subject 'mac802154: remove redundant security_enabled assignment' presents a bug fix as a cleanup.

--

mac802154: remove redundant security_enabled assignment

The commit removes the assignment hdr.fc.security_enabled = cb->secen from ieee802154_header_create(). After that, mac802154_set_header_security() is the only place that sets the security bit. This targets a KMSAN uninit-value report in ieee802154_hdr_push_sechdr(), triggered by a stale cb->secen after WPAN_SECURITY_ON followed by WPAN_SECURITY_DEFAULT.

Quoted 1 line

mac802154: remove redundant security_enabled assignment

[Severity: Low]
This isn't a bug, but is "redundant" the right word for this line?

Removing it changes the transmitted frame. When mac802154_set_header_security() takes this early return, the removed line was the only thing setting fc.security_enabled:

	if (!params.enabled ||
	    (cb->secen_override && !cb->secen) ||
	    !params.out_level)
		return 0;

This is a fix tagged for stable. Would a subject like "mac802154: fix uninit-value in ieee802154_header_create()" be more accurate?

net/mac802154/iface.c static int ieee802154_header_create(struct sk_buff *skb, · line 371

Quoted 9 lines
net/mac802154/iface.c +0 -1
index f437b8daa00d0..7b7332805ecce 100644
@@ -368,7 +368,6 @@ static int ieee802154_header_create(struct sk_buff *skb,
 
 	memset(&hdr.fc, 0, sizeof(hdr.fc));
 	hdr.fc.type = cb->type;
-	hdr.fc.security_enabled = cb->secen;

[Severity: High]
Does this fully close the uninitialized hdr.sec read in ieee802154_hdr_push_sechdr()?

The commit message relies on mac802154_set_header_security() keeping the invariant that security_enabled = 1 implies hdr->sec is initialized. That function only writes some of the fields:

net/mac802154/iface.c:mac802154_set_header_security() {
    ...
	hdr->fc.security_enabled = 1;
	hdr->sec.level = level;
	hdr->sec.key_id_mode = params.out_key.mode;
	if (params.out_key.mode == IEEE802154_SCF_KEY_SHORT_INDEX)
		hdr->sec.short_src = params.out_key.short_source;
	else if (params.out_key.mode == IEEE802154_SCF_KEY_HW_INDEX)
		hdr->sec.extended_src = params.out_key.extended_source;
	hdr->sec.key_id = params.out_key.id;
    ...
}

It never writes sec.frame_counter or the reserved bits that share a byte with level and key_id_mode. In ieee802154_header_create(), hdr is on the stack and only hdr.fc is cleared by the memset above. mac802154_header_create() has the same pattern.

So on the normal llsec TX path (llsec enabled, out_level != 0), ieee802154_hdr_push_sechdr() still copies stack memory into the skb:

	memcpy(buf, hdr, 1);
	memcpy(buf + 1, &hdr->frame_counter, 4);

frame_counter is overwritten only later, in mac802154_llsec_encrypt(). By then, packet taps in dev_queue_xmit_nit() have already seen the header, as the TODO comment in net/mac802154/tx.c notes:

dgram_sendmsg()
wpan_dev_hard_header()

    ieee802154_header_create()
      mac802154_set_header_security()
      ieee802154_hdr_push()
        ieee802154_hdr_push_sechdr()
  dev_queue_xmit()
    dev_queue_xmit_nit()
    ieee802154_subif_start_xmit()
      mac802154_llsec_encrypt()

If encryption fails with -ENOKEY or -EOVERFLOW, mac802154_llsec_encrypt() returns before it pushes the header again. The 4 uninitialized frame_counter bytes then stay in the data that AF_PACKET taps copy to userspace.

The reserved bits survive the memcpy(hdr, buf, 1) in ieee802154_hdr_get_sechdr(). mac802154_llsec_encrypt() then pushes them again, so they also go out over the air and into the CCM AAD.

Should hdr (or at least hdr.sec) be zero-initialized in both ieee802154_header_create() and mac802154_header_create()? Another option is to memset hdr->sec in mac802154_set_header_security() before filling it.

Quoted 3 lines
net/mac802154/iface.c +0 -0
 	hdr.fc.ack_request = cb->ackreq;
 	hdr.seq = atomic_inc_return(&dev->ieee802154_ptr->dsn) & 0xFF;
 
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116065235.27348-1-petrvaganoff%40gmail.com
#3 lore raw

PATCH v2 1/1 mac802154: fix uninit-value in ieee802154_header_create()

In reply to Petr Vaganov

During fuzz testing, the following issue was discovered:

BUG: KMSAN: uninit-value in ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:54 [inline]
BUG: KMSAN: uninit-value in ieee802154_hdr_push+0xa62/0xb20 net/ieee802154/header_ops.c:108
 ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:54 [inline]
 ieee802154_hdr_push+0xa62/0xb20 net/ieee802154/header_ops.c:108
 ieee802154_header_create+0xa83/0xd20 net/mac802154/iface.c:396
 wpan_dev_hard_header include/net/cfg802154.h:525 [inline]
 dgram_sendmsg+0xc6d/0x15d0 net/ieee802154/socket.c:677
 ieee802154_sock_sendmsg+0x8f/0xd0 net/ieee802154/socket.c:96
 sock_sendmsg_nosec net/socket.c:711 [inline]
 __sock_sendmsg+0x2f3/0x360 net/socket.c:726
 ____sys_sendmsg+0x960/0xc30 net/socket.c:2581
 ___sys_sendmsg+0x285/0x3e0 net/socket.c:2635
 __sys_sendmmsg+0x33c/0x950 net/socket.c:2724
 __do_sys_sendmmsg net/socket.c:2751 [inline]
 __se_sys_sendmmsg net/socket.c:2748 [inline]
 __x64_sys_sendmmsg+0xc6/0x150 net/socket.c:2748
 x64_sys_call+0x12a8/0x3cf0 arch/x86/include/generated/asm/syscalls_64.h:308
 do_syscall_x64 arch/x86/entry/common.c:47 [inline]
 do_syscall_64+0xd9/0x1c0 arch/x86/entry/common.c:78
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Uninit was stored to memory at:

 ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:51 [inline]
 ieee802154_hdr_push+0xa5b/0xb20 net/ieee802154/header_ops.c:108
 ieee802154_header_create+0xa83/0xd20 net/mac802154/iface.c:396
 wpan_dev_hard_header include/net/cfg802154.h:525 [inline]
 dgram_sendmsg+0xc6d/0x15d0 net/ieee802154/socket.c:677
 ieee802154_sock_sendmsg+0x8f/0xd0 net/ieee802154/socket.c:96
 sock_sendmsg_nosec net/socket.c:711 [inline]
 __sock_sendmsg+0x2f3/0x360 net/socket.c:726
 ____sys_sendmsg+0x960/0xc30 net/socket.c:2581
 ___sys_sendmsg+0x285/0x3e0 net/socket.c:2635
 __sys_sendmmsg+0x33c/0x950 net/socket.c:2724
 __do_sys_sendmmsg net/socket.c:2751 [inline]
 __se_sys_sendmmsg net/socket.c:2748 [inline]
 __x64_sys_sendmmsg+0xc6/0x150 net/socket.c:2748
 x64_sys_call+0x12a8/0x3cf0 arch/x86/include/generated/asm/syscalls_64.h:310
 do_syscall_x64 arch/x86/entry/common.c:47 [inline]
 do_syscall_64+0xd9/0x1c0 arch/x86/entry/common.c:78
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Both ieee802154_header_create() and mac802154_header_create() declare struct ieee802154_hdr hdr on the stack and clear only hdr.fc via memset. This leaves hdr.sec uninitialized.

There are two ways uninitialized hdr.sec fields can be read:

1. ieee802154_header_create() had a pre-existing assignment:

       hdr.fc.security_enabled = cb->secen;

This could set security_enabled = 1 from a stale cb->secen (e.g., after WPAN_SECURITY_ON followed by WPAN_SECURITY_DEFAULT), even when mac802154_set_header_security() returns without initializing hdr.sec. ieee802154_hdr_push_sechdr() would then read uninitialized hdr.sec.

2. mac802154_set_header_security() never writes sec.frame_counter. ieee802154_hdr_push_sechdr() copies it from the stack into the skb before mac802154_llsec_encrypt() sets the real value. If encryption fails, or via AF_PACKET taps in dev_queue_xmit_nit(), the uninitialized bytes are exposed to userspace.

Fix both issues by replacing memset(&hdr.fc, ...) with memset(&hdr, ...) in both functions, which zeros hdr.sec entirely before mac802154_set_header_security() is called. The stale hdr.fc.security_enabled assignment is also removed as it is now superseded by the full zero-initialization.

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.

---
Changes in v2:
- Replace memset(&hdr.fc, ...) with memset(&hdr, ...) in both ieee802154_header_create() and mac802154_header_create() to also zero hdr.sec, closing the pre-existing uninitialized sec.frame_counter read on the normal TX path (noted by Sashiko AI review).
- Rename subject to reflect this is a bug fix, not a cleanup.

 net/mac802154/iface.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
net/mac802154/iface.c +2 -3
index f437b8daa00d..36bdd7558810 100644
@@ -366,9 +366,8 @@ static int ieee802154_header_create(struct sk_buff *skb,
 	if (!daddr)
 		return -EINVAL;
 
-	memset(&hdr.fc, 0, sizeof(hdr.fc));
+	memset(&hdr, 0, sizeof(hdr));
 	hdr.fc.type = cb->type;
-	hdr.fc.security_enabled = cb->secen;
 	hdr.fc.ack_request = cb->ackreq;
 	hdr.seq = atomic_inc_return(&dev->ieee802154_ptr->dsn) & 0xFF;
 
@@ -433,7 +432,7 @@ static int mac802154_header_create(struct sk_buff *skb,
 	if (!daddr)
 		return -EINVAL;
 
-	memset(&hdr.fc, 0, sizeof(hdr.fc));
+	memset(&hdr, 0, sizeof(hdr));
 	hdr.fc.type = IEEE802154_FC_TYPE_DATA;
 	hdr.fc.ack_request = wpan_dev->ackreq;
 	hdr.seq = atomic_inc_return(&dev->ieee802154_ptr->dsn) & 0xFF;
Signature · 1 line
2.55.0
maintainer Reviewed-by on v2 1/1
#4 lore raw

Re: [PATCH v2 net] mac802154: fix uninit-value in ieee802154_header_create()

Quoted 70 lines · Petr Vaganov

During fuzz testing, the following issue was discovered:

BUG: KMSAN: uninit-value in ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:54 [inline]
BUG: KMSAN: uninit-value in ieee802154_hdr_push+0xa62/0xb20 net/ieee802154/header_ops.c:108
 ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:54 [inline]
 ieee802154_hdr_push+0xa62/0xb20 net/ieee802154/header_ops.c:108
 ieee802154_header_create+0xa83/0xd20 net/mac802154/iface.c:396
 wpan_dev_hard_header include/net/cfg802154.h:525 [inline]
 dgram_sendmsg+0xc6d/0x15d0 net/ieee802154/socket.c:677
 ieee802154_sock_sendmsg+0x8f/0xd0 net/ieee802154/socket.c:96
 sock_sendmsg_nosec net/socket.c:711 [inline]
 __sock_sendmsg+0x2f3/0x360 net/socket.c:726
 ____sys_sendmsg+0x960/0xc30 net/socket.c:2581
 ___sys_sendmsg+0x285/0x3e0 net/socket.c:2635
 __sys_sendmmsg+0x33c/0x950 net/socket.c:2724
 __do_sys_sendmmsg net/socket.c:2751 [inline]
 __se_sys_sendmmsg net/socket.c:2748 [inline]
 __x64_sys_sendmmsg+0xc6/0x150 net/socket.c:2748
 x64_sys_call+0x12a8/0x3cf0 arch/x86/include/generated/asm/syscalls_64.h:308
 do_syscall_x64 arch/x86/entry/common.c:47 [inline]
 do_syscall_64+0xd9/0x1c0 arch/x86/entry/common.c:78
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Uninit was stored to memory at:

 ieee802154_hdr_push_sechdr net/ieee802154/header_ops.c:51 [inline]
 ieee802154_hdr_push+0xa5b/0xb20 net/ieee802154/header_ops.c:108
 ieee802154_header_create+0xa83/0xd20 net/mac802154/iface.c:396
 wpan_dev_hard_header include/net/cfg802154.h:525 [inline]
 dgram_sendmsg+0xc6d/0x15d0 net/ieee802154/socket.c:677
 ieee802154_sock_sendmsg+0x8f/0xd0 net/ieee802154/socket.c:96
 sock_sendmsg_nosec net/socket.c:711 [inline]
 __sock_sendmsg+0x2f3/0x360 net/socket.c:726
 ____sys_sendmsg+0x960/0xc30 net/socket.c:2581
 ___sys_sendmsg+0x285/0x3e0 net/socket.c:2635
 __sys_sendmmsg+0x33c/0x950 net/socket.c:2724
 __do_sys_sendmmsg net/socket.c:2751 [inline]
 __se_sys_sendmmsg net/socket.c:2748 [inline]
 __x64_sys_sendmmsg+0xc6/0x150 net/socket.c:2748
 x64_sys_call+0x12a8/0x3cf0 arch/x86/include/generated/asm/syscalls_64.h:310
 do_syscall_x64 arch/x86/entry/common.c:47 [inline]
 do_syscall_64+0xd9/0x1c0 arch/x86/entry/common.c:78
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

Both ieee802154_header_create() and mac802154_header_create() declare struct ieee802154_hdr hdr on the stack and clear only hdr.fc via memset. This leaves hdr.sec uninitialized.

There are two ways uninitialized hdr.sec fields can be read:

1. ieee802154_header_create() had a pre-existing assignment:

       hdr.fc.security_enabled = cb->secen;

This could set security_enabled = 1 from a stale cb->secen (e.g., after WPAN_SECURITY_ON followed by WPAN_SECURITY_DEFAULT), even when mac802154_set_header_security() returns without initializing hdr.sec. ieee802154_hdr_push_sechdr() would then read uninitialized hdr.sec.

2. mac802154_set_header_security() never writes sec.frame_counter. ieee802154_hdr_push_sechdr() copies it from the stack into the skb before mac802154_llsec_encrypt() sets the real value. If encryption fails, or via AF_PACKET taps in dev_queue_xmit_nit(), the uninitialized bytes are exposed to userspace.

Fix both issues by replacing memset(&hdr.fc, ...) with memset(&hdr, ...) in both functions, which zeros hdr.sec entirely before mac802154_set_header_security() is called. The stale hdr.fc.security_enabled assignment is also removed as it is now superseded by the full zero-initialization.

Quoted 7 lines

Found by Linux Verification Center (linuxtesting.org) with Syzkaller.