* [PATCH iproute2 1/2] ss: validate sscanf() return value in packet_show_line()
2026-08-31 10:41 [PATCH iproute2 0/2] ss: reject malformed /proc fallback records Prabhakar Pujeri
@ 2026-08-31 10:41 ` Prabhakar Pujeri
2026-09-01 13:45 ` Stephen Hemminger
2026-08-31 10:41 ` [PATCH iproute2 2/2] ss: validate sscanf() return value in netlink_show() Prabhakar Pujeri
1 sibling, 1 reply; 4+ messages in thread
From: Prabhakar Pujeri @ 2026-08-31 10:41 UTC (permalink / raw)
To: netdev; +Cc: Prabhakar Pujeri, Stephen Hemminger
The /proc/net/packet fallback parser never checks the return value of
sscanf(). On a malformed or truncated line some of the output
variables (type, prot, iface, state, rq, uid, ino) stay
uninitialized and garbage values are used both for type based
filtering and for the printed socket state.
Require all eight fields to be converted before using the values and
return -1 on failure, which makes generic_record_read() stop
processing, the same way tcp_show_line() bails out on a malformed
/proc/net/tcp line.
Fixes: aba5acdfdb34 ("(Logical change 1.3)")
Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
---
misc/ss.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/misc/ss.c b/misc/ss.c
index 26520cee..098eed27 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -4922,10 +4922,11 @@ static int packet_show_line(char *buf, const struct filter *f, int fam)
struct sockstat stat = {};
int type, prot, iface, state, rq, uid, ino;
- sscanf(buf, "%llx %*d %d %x %d %d %u %u %u",
+ if (sscanf(buf, "%llx %*d %d %x %d %d %u %u %u",
&sk,
&type, &prot, &iface, &state,
- &rq, &uid, &ino);
+ &rq, &uid, &ino) != 8)
+ return -1;
if (type == SOCK_RAW && !(f->dbs & (1<<PACKET_R_DB)))
return 0;
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH iproute2 2/2] ss: validate sscanf() return value in netlink_show()
2026-08-31 10:41 [PATCH iproute2 0/2] ss: reject malformed /proc fallback records Prabhakar Pujeri
2026-08-31 10:41 ` [PATCH iproute2 1/2] ss: validate sscanf() return value in packet_show_line() Prabhakar Pujeri
@ 2026-08-31 10:41 ` Prabhakar Pujeri
1 sibling, 0 replies; 4+ messages in thread
From: Prabhakar Pujeri @ 2026-08-31 10:41 UTC (permalink / raw)
To: netdev; +Cc: Prabhakar Pujeri, Stephen Hemminger
The /proc/net/netlink fallback loop never checks the return value of
sscanf(). On a malformed or truncated line the output variables
(sk, prot, pid, groups, rq, wq, cb) stay uninitialized and garbage
values are passed on to netlink_show_one() and printed as socket
state.
Require all eight fields to be converted before using the values and
stop the read loop on failure, consistent with the other /proc
parsers in ss.c.
Fixes: aba5acdfdb34 ("(Logical change 1.3)")
Signed-off-by: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
---
misc/ss.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/misc/ss.c b/misc/ss.c
index 098eed27..7d9c5e91 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -5299,9 +5299,10 @@ static int netlink_show(struct filter *f)
}
while (fgets(buf, sizeof(buf), fp)) {
- sscanf(buf, "%llx %d %d %x %d %d %llx %d",
- &sk,
- &prot, &pid, &groups, &rq, &wq, &cb, &rc);
+ if (sscanf(buf, "%llx %d %d %x %d %d %llx %d",
+ &sk,
+ &prot, &pid, &groups, &rq, &wq, &cb, &rc) != 8)
+ break;
netlink_show_one(f, prot, pid, groups, 0, 0, 0, rq, wq, sk, cb);
}
--
2.55.0
^ permalink raw reply related [flat|nested] 4+ messages in thread