Skip to contentSkip to conversation

net: diag: document swapped src/dst in udp_dump_one.

PATCH Applied Lorenzo Colitti 2 participants 2 messages Oct 29, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: diag: document swapped src/dst in udp_dump_one.

Since its inception, udp_dump_one has had a bug where userspace needs to swap src and dst addresses and ports in order to find the socket it wants. This is because it passes the socket source address to __udp[46]_lib_lookup's saddr argument, but those functions are intended to find local sockets matching received packets, so saddr is the remote address, not the local address.

This can no longer be fixed for backwards compatibility reasons, so add a brief comment explaining that this is the case. This will avoid confusion and help ensure SOCK_DIAG implementations of new protocols don't have the same problem.

Fixes a925aa00a55 ("udp_diag: Implement the get_exact dumping functionality")
---
 net/ipv4/udp_diag.c | 1 +
 1 file changed, 1 insertion(+)
net/ipv4/udp_diag.c +1 -0
index d9ad986c7b..5cbb9be052 100644
@@ -42,6 +42,7 @@ static int udp_dump_one(struct udp_table *tbl, struct sk_buff *in_skb,
 
 	rcu_read_lock();
 	if (req->sdiag_family == AF_INET)
+		/* src and dst are swapped for historical reasons */
 		sk = __udp4_lib_lookup(net,
 				req->id.idiag_src[0], req->id.idiag_sport,
 				req->id.idiag_dst[0], req->id.idiag_dport,
Signature · 1 line
2.19.1.568.g152ad8e336-goog
maintainer Applied
#1 lore raw

From: Lorenzo Colitti <[email protected]>
Date: Mon, 29 Oct 2018 09:15:22 +0900

Quoted 7 lines

Since its inception, udp_dump_one has had a bug where userspace needs to swap src and dst addresses and ports in order to find the socket it wants. This is because it passes the socket source address to __udp[46]_lib_lookup's saddr argument, but those functions are intended to find local sockets matching received packets, so saddr is the remote address, not the local address.

Quoted 7 lines

This can no longer be fixed for backwards compatibility reasons, so add a brief comment explaining that this is the case. This will avoid confusion and help ensure SOCK_DIAG implementations of new protocols don't have the same problem.

Fixes a925aa00a55 ("udp_diag: Implement the get_exact dumping functionality")

Applied, thanks.