From: Prabhakar Pujeri <prabhakar.pujeri@dell.com>
To: netdev@vger.kernel.org
Cc: Prabhakar Pujeri <prabhakar.pujeri@dell.com>,
Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2 1/2] ss: validate sscanf() return value in packet_show_line()
Date: Mon, 31 Aug 2026 10:41:15 +0000 [thread overview]
Message-ID: <20260831104116.2190-2-prabhakar.pujeri@dell.com> (raw)
In-Reply-To: <20260831104116.2190-1-prabhakar.pujeri@dell.com>
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
next prev parent reply other threads:[~2026-08-31 10:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 10:41 [PATCH iproute2 0/2] ss: reject malformed /proc fallback records Prabhakar Pujeri
2026-08-31 10:41 ` Prabhakar Pujeri [this message]
2026-09-01 13:45 ` [PATCH iproute2 1/2] ss: validate sscanf() return value in packet_show_line() Stephen Hemminger
2026-08-31 10:41 ` [PATCH iproute2 2/2] ss: validate sscanf() return value in netlink_show() Prabhakar Pujeri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260831104116.2190-2-prabhakar.pujeri@dell.com \
--to=prabhakar.pujeri@dell.com \
--cc=netdev@vger.kernel.org \
--cc=stephen@networkplumber.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.