[RFC net-next v11 1/2] inet_diag: pass net_admin to get_info
From: Kalpan Jani
Date: Wed Oct 28 2026 - 04:28:11 EST
Pass the request's CAP_NET_ADMIN status to idiag_get_info()
so protocol-specific diagnostic handlers can restrict privileged
information.
Socket-destruction notifications have no individual requesting user,
so the callback receives net_admin set to false for that path.
Signed-off-by: Kalpan Jani <kalpan.jani@xxxxxxxxxxxxxxxxxx>
---
include/linux/inet_diag.h | 3 ++-
net/ipv4/inet_diag.c | 6 +++---
net/ipv4/raw_diag.c | 2 +-
net/ipv4/tcp_diag.c | 2 +-
net/ipv4/udp_diag.c | 2 +-
net/mptcp/mptcp_diag.c | 2 +-
net/sctp/diag.c | 6 +++---
7 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/include/linux/inet_diag.h b/include/linux/inet_diag.h
index 704fd415c2b49..8db96bfd3e67f 100644
--- a/include/linux/inet_diag.h
+++ b/include/linux/inet_diag.h
@@ -18,7 +18,8 @@ struct inet_diag_handler {
void (*idiag_get_info)(struct sock *sk,
struct inet_diag_msg *r,
- void *info);
+ void *info,
+ bool net_admin);
int (*idiag_get_aux)(struct sock *sk,
bool net_admin,
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index 34b77aa87d0a4..362161bf39fe3 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -276,7 +276,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
}
if (!icsk) {
- handler->idiag_get_info(sk, r, NULL);
+ handler->idiag_get_info(sk, r, NULL, net_admin);
goto out;
}
@@ -327,7 +327,7 @@ int inet_sk_diag_fill(struct sock *sk, struct inet_connection_sock *icsk,
goto errout;
}
- handler->idiag_get_info(sk, r, info);
+ handler->idiag_get_info(sk, r, info, net_admin);
if (ext & (1 << (INET_DIAG_INFO - 1)) && handler->idiag_get_aux)
if (handler->idiag_get_aux(sk, net_admin, skb) < 0)
@@ -1027,7 +1027,7 @@ int inet_diag_handler_get_info(struct sk_buff *skb, struct sock *sk)
if (attr)
info = nla_data(attr);
- handler->idiag_get_info(sk, r, info);
+ handler->idiag_get_info(sk, r, info, false);
inet_diag_unlock_handler(handler);
nlmsg_end(skb, nlh);
diff --git a/net/ipv4/raw_diag.c b/net/ipv4/raw_diag.c
index 943e5998e0ad5..264912d0cb9fc 100644
--- a/net/ipv4/raw_diag.c
+++ b/net/ipv4/raw_diag.c
@@ -185,7 +185,7 @@ static void raw_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
}
static void raw_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
- void *info)
+ void *info, bool net_admin)
{
r->idiag_rqueue = sk_rmem_alloc_get(sk);
r->idiag_wqueue = sk_wmem_alloc_get(sk);
diff --git a/net/ipv4/tcp_diag.c b/net/ipv4/tcp_diag.c
index ba1fdbe9807fd..cac32575282e3 100644
--- a/net/ipv4/tcp_diag.c
+++ b/net/ipv4/tcp_diag.c
@@ -19,7 +19,7 @@
#include <net/tcp.h>
static void tcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
- void *_info)
+ void *_info, bool net_admin)
{
struct tcp_info *info = _info;
diff --git a/net/ipv4/udp_diag.c b/net/ipv4/udp_diag.c
index f4b24e628cf8d..5a1fa627cbee8 100644
--- a/net/ipv4/udp_diag.c
+++ b/net/ipv4/udp_diag.c
@@ -142,7 +142,7 @@ static void udp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
}
static void udp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
- void *info)
+ void *info, bool net_admin)
{
r->idiag_rqueue = udp_rqueue_get(sk);
r->idiag_wqueue = sk_wmem_alloc_get(sk);
diff --git a/net/mptcp/mptcp_diag.c b/net/mptcp/mptcp_diag.c
index 136c2d05c0eeb..9ed7a6be1e628 100644
--- a/net/mptcp/mptcp_diag.c
+++ b/net/mptcp/mptcp_diag.c
@@ -190,7 +190,7 @@ static void mptcp_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
}
static void mptcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
- void *_info)
+ void *_info, bool net_admin)
{
struct mptcp_sock *msk = mptcp_sk(sk);
struct mptcp_info *info = _info;
diff --git a/net/sctp/diag.c b/net/sctp/diag.c
index c2a0de2adf6fd..ab6c560fde053 100644
--- a/net/sctp/diag.c
+++ b/net/sctp/diag.c
@@ -20,7 +20,7 @@
#include <net/sctp/sctp.h>
static void sctp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
- void *info);
+ void *info, bool net_admin);
/* define some functions to make asoc/ep fill look clean */
static void inet_diag_msg_sctpasoc_fill(struct inet_diag_msg *r,
@@ -200,7 +200,7 @@ static int inet_sctp_diag_fill(struct sock *sk, struct sctp_association *asoc,
}
infox.sctpinfo = (struct sctp_info *)info;
infox.asoc = asoc;
- sctp_diag_get_info(sk, r, &infox);
+ sctp_diag_get_info(sk, r, &infox, net_admin);
addr_list = asoc ? &asoc->base.bind_addr.address_list
: &ep->base.bind_addr.address_list;
@@ -412,7 +412,7 @@ static int sctp_ep_dump(struct sctp_endpoint *ep, void *p)
/* define the functions for sctp_diag_handler*/
static void sctp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
- void *info)
+ void *info, bool net_admin)
{
struct sctp_infox *infox = (struct sctp_infox *)info;
--
2.43.0