* [PATCH] smack: Hold rcu_read_lock() for the IPv6 host label lookups
@ 2026-12-04 18:51 Praneeth Balasubramanian
0 siblings, 0 replies; only message in thread
From: Praneeth Balasubramanian @ 2026-12-04 18:51 UTC (permalink / raw)
To: Casey Schaufler
Cc: Paul Moore, James Morris, Serge E . Hallyn, linux-security-module,
linux-kernel, Praneeth Balasubramanian, stable
smack_ipv6host_label() walks smk_net6addr_list with
list_for_each_entry_rcu(), and its comment says that the caller must
hold the RCU read lock. The IPv4 lookups do this: smk_ipv4_check() and
smack_inet_conn_request() take rcu_read_lock() around
smack_ipv4host_label(). The IPv6 lookups in process context do not:
smack_socket_connect() and smack_socket_sendmsg() call it directly with
SMACK_IPV6_SECMARK_LABELING, and smk_ipv6_port_check() calls it from the
same two hooks with SMACK_IPV6_PORT_LABELING. Only the receive path,
smack_socket_sock_rcv_skb(), runs inside an RCU read-side section.
smk_write_net6addr() adds entries with list_add_rcu() while these
lookups run. Entries and labels are never freed, so this is not a
use-after-free. But the walk is outside any reader section, and with
CONFIG_PROVE_RCU_LIST an IPv6 connect() warns:
WARNING: suspicious RCU usage
security/smack/smack_lsm.c:2590 RCU-list traversed in non-reader section!!
...
Call Trace:
lockdep_rcu_suspicious+0x11a/0x160
smack_ipv6host_label+0x71/0x110
smk_ipv6_port_check+0x63/0x530
security_socket_connect+0x27/0x60
__sys_connect+0xc0/0x140
Take rcu_read_lock() around the lookups. The returned smack_known is
never freed, so it can be used after the unlock, as
smack_inet_conn_request() already does.
The missing lock was found by a static check that turns the locking rule
in a function's comment into a Clang context-analysis requirement on its
callers.
Fixes: 21abb1ec414c ("Smack: IPv6 host labeling")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
This was found by a compiler-based check, part of research at UCSB SecLab.
The locking rule stated in the kernel-doc comment of the called function
was turned into a Clang context-analysis requirement (__must_hold) on that
function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every
caller. An LLM was used only to turn the comment into a machine-readable
rule; the report itself comes from the compiler. The patch and changelog
were drafted with Claude Opus 5.5. I reviewed the patch and take
responsibility for it.
Testing: builds without new warnings with W=1 (x86_64, clang 23,
allmodconfig). smack_lsm.o builds without warnings in both the
SMACK_IPV6_PORT_LABELING and SMACK_IPV6_SECMARK_LABELING variants.
Booted next-20261116 in QEMU with CONFIG_PROVE_RCU_LIST and
lsm=landlock,lockdown,yama,smack. Without the patch, sshd's IPv6
connect() at boot gives the warning above. With the patch, a UDP
connect() to 2001:db8::1 gives no warning, and /proc/lockdep_stats
still shows debug_locks: 1 afterwards. The SECMARK and sendmsg() paths
were compiled but not run.
The same kernel also warns at three other Smack list walks that this
patch does not touch: smk_copy_rules() from smack_cred_prepare(),
smk_access_entry() from smk_tskacc(), and smk_find_entry() from
smack_sb_eat_lsm_opts(). Those lists are also never freed. I left them
out to keep this patch to the IPv6 lookups that the comment covers.
security/smack/smack_lsm.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 2192cdcabfe2..ab124cd3a843 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -2861,6 +2861,7 @@ static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address,
unsigned short port;
struct smack_known *object;
+ rcu_read_lock();
if (act == SMK_RECEIVING) {
skp = smack_ipv6host_label(address);
object = ssp->smk_in;
@@ -2868,6 +2869,7 @@ static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address,
skp = ssp->smk_out;
object = smack_ipv6host_label(address);
}
+ rcu_read_unlock();
/*
* The other end is a single label host.
@@ -3095,8 +3097,11 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
if (addrlen < SIN6_LEN_RFC2133)
return 0;
- if (__is_defined(SMACK_IPV6_SECMARK_LABELING))
+ if (__is_defined(SMACK_IPV6_SECMARK_LABELING)) {
+ rcu_read_lock();
rsp = smack_ipv6host_label(sip);
+ rcu_read_unlock();
+ }
if (rsp != NULL) {
struct socket_smack *ssp = smack_sock(sock->sk);
@@ -4078,7 +4083,9 @@ static int smack_socket_sendmsg(struct socket *sock, struct msghdr *msg,
sap->sin6_family != AF_INET6)
return -EINVAL;
#ifdef SMACK_IPV6_SECMARK_LABELING
+ rcu_read_lock();
rsp = smack_ipv6host_label(sap);
+ rcu_read_unlock();
if (rsp != NULL)
rc = smk_ipv6_check(ssp->smk_out, rsp, sap,
SMK_CONNECTING);
--
2.25.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-12-04 18:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 18:51 [PATCH] smack: Hold rcu_read_lock() for the IPv6 host label lookups Praneeth Balasubramanian
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox