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 2/2] ss: validate sscanf() return value in netlink_show()
Date: Mon, 31 Aug 2026 10:41:16 +0000 [thread overview]
Message-ID: <20260831104116.2190-3-prabhakar.pujeri@dell.com> (raw)
In-Reply-To: <20260831104116.2190-1-prabhakar.pujeri@dell.com>
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
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 ` [PATCH iproute2 1/2] ss: validate sscanf() return value in packet_show_line() Prabhakar Pujeri
2026-09-01 13:45 ` Stephen Hemminger
2026-08-31 10:41 ` Prabhakar Pujeri [this message]
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-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox