All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2 v2] ss: drop the /proc parsers for packet and netlink sockets
@ 2026-09-02  3:56 Prabhakar Pujeri
  2026-09-15 21:34 ` Stephen Hemminger
  2026-09-15 21:36 ` [RFC PATCH iproute2 0/3] ss: follow-ups to the packet/netlink /proc removal Stephen Hemminger
  0 siblings, 2 replies; 6+ messages in thread
From: Prabhakar Pujeri @ 2026-09-02  3:56 UTC (permalink / raw)
  To: netdev; +Cc: Prabhakar Pujeri, Stephen Hemminger

packet_show() and netlink_show() fall back to parsing
/proc/net/packet and /proc/net/netlink only when the sock_diag
netlink dump fails.  That fallback exists for kernels without
sock_diag support and parses each record with sscanf() without
checking the conversion count, so truncated or malformed lines
leave fields used by filtering and printing uninitialized.

Remove both sscanf() based parsers instead of trying to validate
them; kernels new enough to matter answer the sock_diag request.
packet_show_line() and the PROC_NET_PACKET/PROC_NET_NETLINK hooks
have no other users.

Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
---
Changes in v2:
- Replace the sscanf() validation series: per Stephen's review of v1, remove
  the /proc fallback parsing for packet and netlink sockets instead of
  hardening it, so the unchecked conversions are gone with the code.
v1: https://lore.kernel.org/netdev/20260831104116.2190-1-prabhakar.pujeri@dell.com/

 misc/ss.c | 79 ++-----------------------------------------------------
 1 file changed, 2 insertions(+), 77 deletions(-)

diff --git a/misc/ss.c b/misc/ss.c
index 26520cee..6ca6d406 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -480,10 +480,6 @@ static void filter_merge_defaults(struct filter *f)
 #define net_raw_open()		generic_proc_open("PROC_NET_RAW", "net/raw")
 #define net_raw6_open()		generic_proc_open("PROC_NET_RAW6", "net/raw6")
 #define net_unix_open()		generic_proc_open("PROC_NET_UNIX", "net/unix")
-#define net_packet_open()	generic_proc_open("PROC_NET_PACKET", \
-							"net/packet")
-#define net_netlink_open()	generic_proc_open("PROC_NET_NETLINK", \
-							"net/netlink")
 #define net_sockstat_open()	generic_proc_open("PROC_NET_SOCKSTAT", \
 							"net/sockstat")
 #define net_sockstat6_open()	generic_proc_open("PROC_NET_SOCKSTAT6", \
@@ -4916,56 +4912,12 @@ static int packet_show_netlink(struct filter *f)
 	return handle_netlink_request(f, &req.nlh, sizeof(req), packet_show_sock);
 }
 
-static int packet_show_line(char *buf, const struct filter *f, int fam)
-{
-	unsigned long long sk;
-	struct sockstat stat = {};
-	int type, prot, iface, state, rq, uid, ino;
-
-	sscanf(buf, "%llx %*d %d %x %d %d %u %u %u",
-			&sk,
-			&type, &prot, &iface, &state,
-			&rq, &uid, &ino);
-
-	if (type == SOCK_RAW && !(f->dbs & (1<<PACKET_R_DB)))
-		return 0;
-	if (type == SOCK_DGRAM && !(f->dbs & (1<<PACKET_DG_DB)))
-		return 0;
-
-	stat.type  = type;
-	stat.prot  = prot;
-	stat.lport = stat.iface = iface;
-	stat.state = state;
-	stat.rq    = rq;
-	stat.uid   = uid;
-	stat.ino   = ino;
-	stat.state = SS_CLOSE;
-
-	if (packet_stats_print(&stat, f))
-		return 0;
-
-	return 0;
-}
-
 static int packet_show(struct filter *f)
 {
-	FILE *fp;
-	int rc = 0;
-
 	if (!filter_af_get(f, AF_PACKET) || !(f->states & (1 << SS_CLOSE)))
 		return 0;
 
-	if (!getenv("PROC_NET_PACKET") && !getenv("PROC_ROOT") &&
-			packet_show_netlink(f) == 0)
-		return 0;
-
-	if ((fp = net_packet_open()) == NULL)
-		return -1;
-	if (generic_record_read(fp, packet_show_line, f, AF_PACKET))
-		rc = -1;
-
-	fclose(fp);
-	return rc;
+	return packet_show_netlink(f);
 }
 
 static int xdp_stats_print(struct sockstat *s, const struct filter *f)
@@ -5276,37 +5228,10 @@ static int netlink_show_netlink(struct filter *f)
 
 static int netlink_show(struct filter *f)
 {
-	FILE *fp;
-	char buf[256];
-	int prot, pid;
-	unsigned int groups;
-	int rq, wq, rc;
-	unsigned long long sk, cb;
-
 	if (!filter_af_get(f, AF_NETLINK) || !(f->states & (1 << SS_CLOSE)))
 		return 0;
 
-	if (!getenv("PROC_NET_NETLINK") && !getenv("PROC_ROOT") &&
-		netlink_show_netlink(f) == 0)
-		return 0;
-
-	if ((fp = net_netlink_open()) == NULL)
-		return -1;
-	if (!fgets(buf, sizeof(buf), fp)) {
-		fclose(fp);
-		return -1;
-	}
-
-	while (fgets(buf, sizeof(buf), fp)) {
-		sscanf(buf, "%llx %d %d %x %d %d %llx %d",
-		       &sk,
-		       &prot, &pid, &groups, &rq, &wq, &cb, &rc);
-
-		netlink_show_one(f, prot, pid, groups, 0, 0, 0, rq, wq, sk, cb);
-	}
-
-	fclose(fp);
-	return 0;
+	return netlink_show_netlink(f);
 }
 
 static bool vsock_type_skip(struct sockstat *s, struct filter *f)
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-09-15 21:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-02  3:56 [PATCH iproute2 v2] ss: drop the /proc parsers for packet and netlink sockets Prabhakar Pujeri
2026-09-15 21:34 ` Stephen Hemminger
2026-09-15 21:36 ` [RFC PATCH iproute2 0/3] ss: follow-ups to the packet/netlink /proc removal Stephen Hemminger
2026-09-15 21:36   ` [RFC 1/3] ss: drop the dead /proc fallback trigger in packet_show_sock() Stephen Hemminger
2026-09-15 21:36   ` [RFC 2/3] ss: warn when packet socket diag is unavailable Stephen Hemminger
2026-09-15 21:36   ` [RFC 3/3] ss: restore packet_raw/packet_dgram filtering Stephen Hemminger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.