* [PATCH] smack: Hold rcu_read_lock() for the IPv6 host label lookups
@ 2026-12-04 18:51 Praneeth Balasubramanian
2026-12-04 19:27 ` sashiko-bot
0 siblings, 1 reply; 2+ messages 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] 2+ messages in thread
* Re: [PATCH] smack: Hold rcu_read_lock() for the IPv6 host label lookups
2026-12-04 18:51 [PATCH] smack: Hold rcu_read_lock() for the IPv6 host label lookups Praneeth Balasubramanian
@ 2026-12-04 19:27 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-12-04 19:27 UTC (permalink / raw)
Cc: linux-security-module
Thank you for your contribution! Sashiko AI review found no new issues
in this patch, but noticed 1 related pre-existing issue it does not
introduce:
- [High] smack: missing rcu_read_lock() in smk_find_entry() [1]
--
commit 9573453fc6b675d33a1f2efa5ab515e7e7d7c7e2
Author: Praneeth Balasubramanian <praneethb2002@gmail.com>
smack: Hold rcu_read_lock() for the IPv6 host label lookups
This commit wraps process-context calls to smack_ipv6host_label() in
smk_ipv6_port_check(), smack_socket_connect(), and smack_socket_sendmsg()
with rcu_read_lock() and rcu_read_unlock().
> diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
> index 8e88ac65fd7fc..5329955a71402 100644
> --- a/security/smack/smack_lsm.c
> +++ b/security/smack/smack_lsm.c
> @@ -2855,6 +2855,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;
> @@ -2862,6 +2863,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();
[Severity: High]
This problem wasn't introduced by this patch, but does smk_find_entry()
have the same missing RCU read lock [1]?
security/smack/smack_access.c:smk_find_entry() {
...
hlist_for_each_entry_rcu(skp, head, smk_hashed)
if (strcmp(skp->smk_known, string) == 0)
return skp;
...
}
Callers such as smack_secctx_to_secid() in security/smack/smack_lsm.c
invoke smk_find_entry() without holding rcu_read_lock() or
smack_known_lock. smk_import_allocated_label() calls it under
smack_known_lock, but hlist_for_each_entry_rcu() has no lockdep condition.
With CONFIG_PROVE_RCU_LIST=y, traversing smack_known_hash this way
triggers the same lockdep warning about an RCU list walked outside a
reader section.
[1] https://sashiko.dev/#/bug/linux-29d4d0ee-96d6-4850-9369-f2bc7143c107
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204185112.1687982-1-praneethb2002@gmail.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-04 19:27 UTC | newest]
Thread overview: 2+ messages (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
2026-12-04 19:27 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox