🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
3 messages
3 total messages Started by Stephen Hemminger Thu, 12 Nov 2026 19:59
[PATCH iproute2 00/11] ss fixes from an OSS scan
#15447
Author: Stephen Hemminger
Date: Thu, 12 Nov 2026 19:59
39 lines
12173 bytes
Fixes for the ss findings of scan iproute2-20261015-004, plus bugs
found while confirming them.

The biggest change is removing the fallback /proc parsing.
It was buggy and fixing it is not worth bothering.
Every family ss lists that way has had sock_diag support since well before
the oldest supported LTS kernel, and the parsers were untested and
trusted file contents that an unprivileged user can partly control.
A kernel built without netlink socket diagnostics now gets an error
instead of a silent fallback.

The rest escape names chosen by whoever owns the socket, bound state
and type values from the kernel before indexing name tables, stop
treating a netlink port id as the owner's pid, and size the
TCPDIAG_FILE read buffer to the record while rejecting lengths the
parser cannot use.

Stephen Hemminger (11):
  ss: fix double close on sock_diag send failure
  ss: drop /proc fallback for socket listing
  ss: escape names chosen by the socket owner
  ss: size the TCPDIAG_FILE buffer to the record
  ss: replay all dumps in TCPDIAG_FILE
  ss: bound state and type name lookups
  ss: fix rpcbind service cache
  ss: read socket SELinux context only for -z
  ss: check owner before naming a netlink socket
  ss: keep following events after ENOBUFS
  ss: report a failed SCTP or MPTCP dump

 lib/escape.c                  |   7 +-
 man/man8/ss.8                 |   3 +-
 misc/ss.c                     | 884 +++++++++-------------------------
 testsuite/tests/ss/ssfilter.t |  26 +-
 4 files changed, 249 insertions(+), 671 deletions(-)

-- 
2.53.0
[PATCH iproute2 09/11] ss: check owner before naming a netlink socket
#15485
Author: Stephen Hemminger
Date: Thu, 12 Nov 2026 19:59
136 lines
14832 bytes
The netlink port id was taken as the pid of the owning process,
but any process can bind any free port id, so ss could show (and
report the SELinux context of) an unrelated process.

Only name the process if it holds the socket. Port ids that cannot
be checked are shown as numbers.

Reported-by: Anthropic OSS scanner (ANT-2026-1FCHVE1N)
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 man/man8/ss.8 |  3 ++-
 misc/ss.c     | 51 ++++++++++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 48 insertions(+), 6 deletions(-)

diff --git a/man/man8/ss.8 b/man/man8/ss.8
index 54af744a..96d25ab0 100644
--- a/man/man8/ss.8
+++ b/man/man8/ss.8
@@ -337,7 +337,8 @@ sockets the initiating process context is displayed as follows:
 .RS
 .RS
 .IP "1." 4
-If valid pid show the process context.
+If the port id is the pid of a process holding the socket, show the process
+context.
 .IP "2." 4
 If destination is kernel (pid = 0) show kernel initial context.
 .IP "3." 4
diff --git a/misc/ss.c b/misc/ss.c
index 9d2f9891..6d37f676 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -4662,10 +4662,47 @@ static int xdp_show(struct filter *f)
 	return handle_netlink_request(f, &req.nlh, sizeof(req), xdp_show_sock);
 }
 
+/* A netlink port id is chosen by whoever binds the socket; it is the
+ * pid of the owner only by convention. Check that the process holds it.
+ */
+static bool netlink_pid_holds_sock(int pid, unsigned int ino)
+{
+	char path[MAX_PATH_LEN];
+	struct dirent *d;
+	bool ret = false;
+	DIR *dir;
+
+	if (pid <= 0 || !ino)
+		return false;
+
+	snprintf(path, sizeof(path), "%s/%d/fd",
+		 getenv("PROC_ROOT") ? : "/proc", pid);
+	dir = opendir(path);
+	if (!dir)
+		return false;
+
+	while (!ret && (d = readdir(dir)) != NULL) {
+		unsigned int fd_ino;
+		ssize_t link_len;
+		char lnk[64];
+
+		link_len = readlinkat(dirfd(dir), d->d_name, lnk, sizeof(lnk) - 1);
+		if (link_len == -1)
+			continue;
+		lnk[link_len] = '\0';
+
+		if (sscanf(lnk, "socket:[%u]", &fd_ino) == 1)
+			ret = fd_ino == ino;
+	}
+	closedir(dir);
+
+	return ret;
+}
+
 static int netlink_show_one(struct filter *f,
 				int prot, int pid, unsigned int groups,
 				int state, int dst_pid, unsigned int dst_group,
-				int rq, int wq,
+				int rq, int wq, unsigned int ino,
 				unsigned long long sk, unsigned long long cb)
 {
 	struct sockstat st = {
@@ -4679,6 +4716,7 @@ static int netlink_show_one(struct filter *f,
 	SPRINT_BUF(prot_buf) = {};
 	const char *prot_name;
 	char procname[64] = {};
+	bool is_owner = false;
 
 	if (f->f) {
 		st.rport = -1;
@@ -4692,6 +4730,9 @@ static int netlink_show_one(struct filter *f,
 
 	prot_name = nl_proto_n2a(prot, prot_buf, sizeof(prot_buf));
 
+	if (pid > 0 && (!numeric || show_proc_ctx))
+		is_owner = netlink_pid_holds_sock(pid, ino);
+
 	if (pid == -1) {
 		procname[0] = '*';
 	} else if (!numeric) {
@@ -4701,7 +4742,7 @@ static int netlink_show_one(struct filter *f,
 		if (!pid) {
 			done = 1;
 			strncpy(procname, "kernel", 7);
-		} else if (pid > 0) {
+		} else if (is_owner) {
 			if (get_task_name(getenv("PROC_ROOT"), pid,
 					  task, sizeof(task)) == 0) {
 				escape_str(procname, task, sizeof(procname));
@@ -4734,13 +4775,13 @@ static int netlink_show_one(struct filter *f,
 	if (show_proc_ctx) {
 		/* The pid value will either be:
 		 *   0 if destination kernel - show kernel initial context.
-		 *   A valid process pid - use getpidcon.
+		 *   The pid of a process holding the socket - use getpidcon.
 		 *   A unique value allocated by the kernel or netlink user
 		 *   to the process - show context as "not available".
 		 */
 		if (!pid)
 			security_get_initial_context("kernel", &pid_context);
-		else if (pid > 0)
+		else if (is_owner)
 			getpidcon(pid, &pid_context);
 
 		out(" proc_ctx=%s", pid_context ? : "unavailable");
@@ -4779,7 +4820,7 @@ static int netlink_show_sock(struct nlmsghdr *nlh, void *arg)
 
 	if (netlink_show_one(f, r->ndiag_protocol, r->ndiag_portid, groups,
 			 r->ndiag_state, r->ndiag_dst_portid, r->ndiag_dst_group,
-			 rq, wq, 0, 0)) {
+			 rq, wq, r->ndiag_ino, 0, 0)) {
 		return 0;
 	}
 
-- 
2.53.0
Re: [PATCH iproute2 00/11] ss fixes from an OSS scan
#17373
Author: patchwork-bot+netdevbpf
Date: Mon, 16 Nov 2026 18:00
48 lines
10271 bytes
Hello:

This series was applied to iproute2/iproute2.git (main)
by Stephen Hemminger <stephen@networkplumber.org>:

On Thu, 12 Nov 2026 11:59:13 -0800 you wrote:
> Fixes for the ss findings of scan iproute2-20261015-004, plus bugs
> found while confirming them.
> 
> The biggest change is removing the fallback /proc parsing.
> It was buggy and fixing it is not worth bothering.
> Every family ss lists that way has had sock_diag support since well before
> the oldest supported LTS kernel, and the parsers were untested and
> trusted file contents that an unprivileged user can partly control.
> A kernel built without netlink socket diagnostics now gets an error
> instead of a silent fallback.
> 
> [...]

Here is the summary with links:
  - [iproute2,01/11] ss: fix double close on sock_diag send failure
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=b37982780989
  - [iproute2,02/11] ss: drop /proc fallback for socket listing
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=9eefceca4e5b
  - [iproute2,03/11] ss: escape names chosen by the socket owner
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=1f6307cb3b37
  - [iproute2,04/11] ss: size the TCPDIAG_FILE buffer to the record
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=f007c85036d3
  - [iproute2,05/11] ss: replay all dumps in TCPDIAG_FILE
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=3b96ffd85efc
  - [iproute2,06/11] ss: bound state and type name lookups
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=762a5601e91d
  - [iproute2,07/11] ss: fix rpcbind service cache
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=f8db772d8160
  - [iproute2,08/11] ss: read socket SELinux context only for -z
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=d8a4d9d2a774
  - [iproute2,09/11] ss: check owner before naming a netlink socket
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=b4027e7eb849
  - [iproute2,10/11] ss: keep following events after ENOBUFS
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=a71a7aea8356
  - [iproute2,11/11] ss: report a failed SCTP or MPTCP dump
    https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=c9295679ad53

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads