selinux: suppress warning flood for retired DCCP netlink messages
PATCH v2 1/1 selinux: suppress warning flood for retired DCCP netlink messages
When deploying linux-6.18.y stable kernel to production servers, we observed kernel dmesg being flooded with SELinux warnings when running ss:
SELinux: unrecognized netlink message: protocol=4 nlmsg_type=19 \
sclass=netlink_tcpdiag_socket pid=188945 comm=ssThe root cause is that DCCP support was retired in
commit 2a63dd0edf38 ("net: Retire DCCP socket."). Consequently, DCCPDIAG_GETSOCK was removed from nlmsg_tcpdiag_perms. This causes nlmsg_perm() to return -EINVAL, triggering the SELinux warning for every ss -d invocation [0].
Use pr_warn_once() for the retired DCCPDIAG_GETSOCK to prevent message flooding.
--- security/selinux/hooks.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)
security/selinux/hooks.c +11 -6
@@ -94,6 +94,7 @@#include <linux/io_uring/cmd.h> #include <uapi/linux/lsm.h> #include <linux/memfd.h> +#include <uapi/linux/inet_diag.h> #include "initcalls.h" #include "avc.h"
@@ -6272,12 +6273,16 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb)return rc; }else if (rc == -EINVAL ) {/* -EINVAL is a missing msg/perm mapping */ -pr_warn_ratelimited ("SELinux: unrecognized netlink" -" message: protocol=%hu nlmsg_type=%hu sclass=%s" -" pid=%d comm=%s\n" , - sk->sk_protocol, nlh->nlmsg_type, - secclass_map[sclass -1 ].name, -task_pid_nr (current), current->comm); +if (nlh->nlmsg_type ==DCCPDIAG_GETSOCK ) +pr_warn_once ("SELinux: DCCP has been removed, pid=%d comm=%s\n" , +task_pid_nr (current), current->comm); +else +pr_warn_ratelimited ("SELinux: unrecognized netlink" +" message: protocol=%hu nlmsg_type=%hu sclass=%s" +" pid=%d comm=%s\n" , + sk->sk_protocol, nlh->nlmsg_type, + secclass_map[sclass -1 ].name, +task_pid_nr (current), current->comm);if (enforcing_enabled () && !security_get_allow_unknown ())return rc;
Signature · 1 line
2.52.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The check for DCCPDIAG_GETSOCK does not verify the socket's protocol family or SELinux class…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The check for DCCPDIAG_GETSOCK does not verify the socket's protocol family or SELinux class, incorrectly intercepting invalid messages sent to other netlink subsystems like NETLINK_AUDIT. --
commit 0ed2e4bbea68b959f81f6b7c06db4d7b3ae85534
Author: Yafang Shao <[email protected]>
selinux: suppress warning flood for retired DCCP netlink messages
This commit modifies the SELinux netlink send hook to suppress repeated warnings for the retired DCCP netlink messages. It intercepts the specific message type (DCCPDIAG_GETSOCK) and logs a warning only once, rather than rate-limiting, to avoid log flooding from tools like ss.
Quoted 4 lines
security/selinux/hooks.c +0
-0
[ ... ]
security/selinux/hooks.c static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) · line 6282
Quoted 13 lines
security/selinux/hooks.c +3
-6@@ -6276,12 +6277,16 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb)return rc; }else if (rc == -EINVAL ) {/* -EINVAL is a missing msg/perm mapping */ -pr_warn_ratelimited ("SELinux: unrecognized netlink" -" message: protocol=%hu nlmsg_type=%hu sclass=%s" -" pid=%d comm=%s\n" , - sk->sk_protocol, nlh->nlmsg_type, - secclass_map[sclass -1 ].name, -task_pid_nr (current), current->comm); +if (nlh->nlmsg_type ==DCCPDIAG_GETSOCK ) +pr_warn_once ("SELinux: DCCP has been removed, pid=%d comm=%s\n" , +task_pid_nr (current), current->comm);
[Severity: Medium]
Will this check incorrectly match other netlink subsystems?
Since DCCPDIAG_GETSOCK evaluates to 19, if a user sends a message with nlmsg_type 19 to an unrelated socket family (like NETLINK_AUDIT), it could trigger this path because type 19 is unmapped for Audit sockets.
This would result in a misleading "DCCP has been removed" warning instead of the standard "unrecognized netlink message" warning.
Furthermore, because pr_warn_once() is used, this one occurrence will permanently consume the warning allowance globally, suppressing legitimate generic warnings for type 19 across all protocols.
Should this check also verify the socket's protocol family or SELinux class (sclass) before assuming the message is DCCPDIAG_GETSOCK?
Quoted 10 lines
security/selinux/hooks.c +7
-0+else +pr_warn_ratelimited ("SELinux: unrecognized netlink" +" message: protocol=%hu nlmsg_type=%hu sclass=%s" +" pid=%d comm=%s\n" , + sk->sk_protocol, nlh->nlmsg_type, + secclass_map[sclass -1 ].name, +task_pid_nr (current), current->comm);if (enforcing_enabled () && !security_get_allow_unknown ())return rc;
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Stephen Smalley
maintainerQuoted 39 lines · Yafang Shao
When deploying linux-6.18.y stable kernel to production servers, we observed kernel dmesg being flooded with SELinux warnings when running
ss:SELinux: unrecognized netlink message: protocol=4 nlmsg_type=19 \ sclass=netlink_tcpdiag_socket pid=188945 comm=ssThe root cause is that DCCP support was retired in
commit2a63dd0edf38("net: Retire DCCP socket."). Consequently,DCCPDIAG_GETSOCKwas removed fromnlmsg_tcpdiag_perms. This causesnlmsg_perm()to return-EINVAL, triggering the SELinux warning for everyss -dinvocation [0].Use
pr_warn_once()for the retiredDCCPDIAG_GETSOCKto prevent message flooding.Fixes 2a63dd0edf38 ("net: Retire DCCP socket.")Suggested-by Paul Moore <[email protected]>Signed-off-by Yafang Shao <[email protected]>Cc Kuniyuki Iwashima <[email protected]>--- security/selinux/hooks.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)security/selinux/hooks.c +1
-0@@ -94,6 +94,7 @@#include <linux/io_uring/cmd.h> #include <uapi/linux/lsm.h> #include <linux/memfd.h> +#include <uapi/linux/inet_diag.h> #include "initcalls.h" #include "avc.h"
security/selinux/hooks.c static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) · line 6276
Quoted 10 lines
security/selinux/hooks.c +1
-6@@ -6272,12 +6273,16 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb)return rc; }else if (rc == -EINVAL ) {/* -EINVAL is a missing msg/perm mapping */ -pr_warn_ratelimited ("SELinux: unrecognized netlink" -" message: protocol=%hu nlmsg_type=%hu sclass=%s" -" pid=%d comm=%s\n" , - sk->sk_protocol, nlh->nlmsg_type, - secclass_map[sclass -1 ].name, -task_pid_nr (current), current->comm); +if (nlh->nlmsg_type ==DCCPDIAG_GETSOCK )
sashiko noted that checking DCCPDIAG_GETSOCK above without first checking the protocol family or security class might trigger this message on a different protocol family instead [1]
Quoted 56 lines · Stephen Smalley
Quoted 39 lines · Yafang Shao
When deploying linux-6.18.y stable kernel to production servers, we observed kernel dmesg being flooded with SELinux warnings when running
ss:SELinux: unrecognized netlink message: protocol=4 nlmsg_type=19 \ sclass=netlink_tcpdiag_socket pid=188945 comm=ssThe root cause is that DCCP support was retired in
commit2a63dd0edf38("net: Retire DCCP socket."). Consequently,DCCPDIAG_GETSOCKwas removed fromnlmsg_tcpdiag_perms. This causesnlmsg_perm()to return-EINVAL, triggering the SELinux warning for everyss -dinvocation [0].Use
pr_warn_once()for the retiredDCCPDIAG_GETSOCKto prevent message flooding.Fixes 2a63dd0edf38 ("net: Retire DCCP socket.")Suggested-by Paul Moore <[email protected]>Signed-off-by Yafang Shao <[email protected]>Cc Kuniyuki Iwashima <[email protected]>--- security/selinux/hooks.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)security/selinux/hooks.c +1
-0@@ -94,6 +94,7 @@#include <linux/io_uring/cmd.h> #include <uapi/linux/lsm.h> #include <linux/memfd.h> +#include <uapi/linux/inet_diag.h> #include "initcalls.h" #include "avc.h" security/selinux/hooks.c static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb) · line 6276
Quoted 10 lines
security/selinux/hooks.c +1
-6@@ -6272,12 +6273,16 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb)return rc; }else if (rc == -EINVAL ) {/* -EINVAL is a missing msg/perm mapping */ -pr_warn_ratelimited ("SELinux: unrecognized netlink" -" message: protocol=%hu nlmsg_type=%hu sclass=%s" -" pid=%d comm=%s\n" , - sk->sk_protocol, nlh->nlmsg_type, - secclass_map[sclass -1 ].name, -task_pid_nr (current), current->comm); +if (nlh->nlmsg_type ==DCCPDIAG_GETSOCK )sashiko noted that checking
DCCPDIAG_GETSOCKabove without first checking the protocol family or security class might trigger this message on a different protocol family instead [1]
Quoted 1 line
I will update it.
Thanks for the information.
Signature · 2 lines
Regards Yafang