mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eduard Orehov <e.orehov@ideco.ru>
To: Paul Moore <paul@paul-moore.com>,
	Stephen Smalley <stephen.smalley.work@gmail.com>
Cc: Ondrej Mosnacek <omosnacek@gmail.com>,
	selinux@vger.kernel.org, linux-kernel@vger.kernel.org,
	lvc-project@linuxtesting.org, Eduard Orehov <e.orehov@ideco.ru>
Subject: [PATCH] selinux: initialize sport/dport in __ad_net_init()
Date: Mon, 23 Nov 2026 16:37:24 +0500	[thread overview]
Message-ID: <20261123113724.35381-1-e.orehov@ideco.ru> (raw)

Since commit dd51fcd42fd6 ("selinux: introduce and use lsm_ad_net_init*()
helpers") the struct lsm_network_audit used by the SELinux network hooks
is no longer zeroed; __ad_net_init() sets only netif, sk and family.
The addresses are always filled in by selinux_parse_skb(), but sport
and dport are set by selinux_parse_skb_ipv4()/selinux_parse_skb_ipv6()
only for TCP, UDP and SCTP. For any other protocol (e.g. a raw
socket with IPPROTO_IGMP, UDP-Lite) and for non-first fragments they
are left uninitialized.

When such a packet hits an AVC denial (e.g. with NetLabel or secmark
peer labeling enabled), dump_common_audit_data() passes the garbage
ports to print_ipv4_addr()/print_ipv6_addr(), which leaks up to four
bytes of kernel stack into the audit log as "src=" / "dest=" and is
reported by KMSAN:

  BUG: KMSAN: uninit-value in common_lsm_audit+0x2196/0x2ff0
   print_ipv6_addr security/lsm_audit.c:178 [inline]
   dump_common_audit_data security/lsm_audit.c:373 [inline]
   common_lsm_audit+0x2196/0x2ff0 security/lsm_audit.c:458
   slow_avc_audit+0x17f/0x1d0 security/selinux/avc.c:773
   avc_has_perm+0x2d6/0x360 security/selinux/avc.c:1191
   selinux_inet_sys_rcv_skb+0x116/0x280 security/selinux/hooks.c:5326
   selinux_socket_sock_rcv_skb+0xaae/0x1270 security/selinux/hooks.c:5408
   security_sock_rcv_skb+0x79/0x120 security/security.c:4853
   sk_filter_trim_cap+0x18b/0xa60 net/core/filter.c:151
   sock_queue_rcv_skb_reason+0x46/0x1a0 net/core/sock.c:522
   rawv6_rcv+0x1b17/0x1c20 net/ipv6/raw.c:371
   ...
  Local variable net created at:
   selinux_socket_sock_rcv_skb+0x118/0x1270 security/selinux/hooks.c

Initialize sport and dport in __ad_net_init(). Zeroing only these two
fields keeps the cost low, which was the point of dd51fcd42fd6.

Found by Ideco on behalf of Linux Verification Center
(linuxtesting.org) with Syzkaller.

Fixes: dd51fcd42fd6 ("selinux: introduce and use lsm_ad_net_init*() helpers")
Cc: stable@vger.kernel.org
Signed-off-by: Eduard Orehov <e.orehov@ideco.ru>
---
Tested on a 6.12.114-based kernel with KMSAN: the reproducer (NetLabel
static default label + raw IPv4/IPv6 socket with protocol 2, and UDP-Lite
over IPv6) triggers the report on the unpatched kernel and no longer does
with the fix. Mainline was not booted; the affected code there is
identical.

 security/selinux/hooks.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 9950f89dfaa2..9029e2ab072a 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -242,6 +242,8 @@ static void __ad_net_init(struct common_audit_data *ad,
 	net->netif = ifindex;
 	net->sk = sk;
 	net->family = family;
+	net->sport = 0;
+	net->dport = 0;
 }
 
 static void ad_net_init_from_sk(struct common_audit_data *ad,
-- 
2.56.1



                 reply	other threads:[~2026-11-23 11:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261123113724.35381-1-e.orehov@ideco.ru \
    --to=e.orehov@ideco.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lvc-project@linuxtesting.org \
    --cc=omosnacek@gmail.com \
    --cc=paul@paul-moore.com \
    --cc=selinux@vger.kernel.org \
    --cc=stephen.smalley.work@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®