From: Luigi Leonardi <leonardi@redhat.com>
To: Stefano Garzarella <sgarzare@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
netdev@vger.kernel.org, Luigi Leonardi <leonardi@redhat.com>
Cc: Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2 v2 2/2] ss: fix vsock port filter
Date: Mon, 17 Aug 2026 14:54:21 +0200 [thread overview]
Message-ID: <20260817-fix_vsock-v2-2-47e544221eae@redhat.com> (raw)
In-Reply-To: <20260817-fix_vsock-v2-0-47e544221eae@redhat.com>
parse_hostcond() initializes aafilter.port to -1L (0xFFFFFFFFFFFFFFFF)
as a sentinel for "no port filter". When parsing a vsock port it called
get_u32() via a cast:
get_u32((__u32 *)&a.port, port, 0)
get_u32() only writes 4 bytes, leaving the upper 32 bits of the 8-byte
long set from the -1 initialization. For example, for port 27354 this
produces 0xFFFFFFFF00006ADA, which never compares equal to sockstat.lport and
causes all vsock port filters to silently match nothing.
Fix by parsing into a temporary __u32 and assigning it to a.port, which
zero-extends the value correctly. When the user specifies '*' the if
block is skipped entirely and the -1 sentinel is preserved.
Fixes: 012cb515 ("ss: change aafilter port from int to long (inode support)")
Suggested-by: Stephen Hemminger <stephen@networkplumber.org>
Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
---
misc/ss.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/misc/ss.c b/misc/ss.c
index ff1a88de..a3570715 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -2322,9 +2322,13 @@ void *parse_hostcond(char *addr, bool is_port)
port = find_port(addr, is_port);
- if (port && strcmp(port, "*") &&
- get_u32((__u32 *)&a.port, port, 0))
- return NULL;
+ if (port && strcmp(port, "*")) {
+ __u32 vport;
+
+ if (get_u32(&vport, port, 0))
+ return NULL;
+ a.port = vport;
+ }
if (!is_port && addr[0] && strcmp(addr, "*")) {
a.addr.bitlen = 32;
--
2.55.0
prev parent reply other threads:[~2026-08-17 12:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-17 12:54 [PATCH iproute2 v2 0/2] ss: fix vsock port filtering Luigi Leonardi
2026-08-17 12:54 ` [PATCH iproute2 v2 1/2] ss: move lport and rport in struct sockstat from int to long Luigi Leonardi
2026-08-17 12:54 ` Luigi Leonardi [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=20260817-fix_vsock-v2-2-47e544221eae@redhat.com \
--to=leonardi@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=sgarzare@redhat.com \
--cc=stefanha@redhat.com \
--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