Skip to contentSkip to conversation

net: diag: support SOCK_DESTROY for UDP sockets

PATCH Applied David Ahern 2 participants 2 messages Aug 24, 2016

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

PATCH v4 1/1 net: diag: support SOCK_DESTROY for UDP sockets

This implements SOCK_DESTROY for UDP sockets similar to what was done for TCP with commit c1e64e298b8ca ("net: diag: Support destroying TCP sockets.") A process with a UDP socket targeted for destroy is awakened and recvmsg fails with ECONNABORTED.

---
v4
- added support for v4 mapped addresses and return EINVAL for unknown protocol to be consistent with TCP as noted by Lorenzo
- changed locking to have udp_abort call sock_put

v3
- add missing sock_diag_check_cookie check after socket lookup per Eric'c comment

v2
- changed socket lookup to __udp{4,6}_lib_lookup

 include/net/udp.h   |  1 +
 net/ipv4/udp.c      | 15 ++++++++++
 net/ipv4/udp_diag.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 net/ipv6/udp.c      |  1 +
 4 files changed, 96 insertions(+)
include/net/udp.h +1 -0
index 8894d7144189..ea53a87d880f 100644
@@ -251,6 +251,7 @@ int udp_get_port(struct sock *sk, unsigned short snum,
 		 int (*saddr_cmp)(const struct sock *,
 				  const struct sock *));
 void udp_err(struct sk_buff *, u32);
+int udp_abort(struct sock *sk, int err);
 int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len);
 int udp_push_pending_frames(struct sock *sk);
 void udp_flush_pending_frames(struct sock *sk);
net/ipv4/udp.c +15 -0
index 8f5f7f6026f7..e9ffc27b23d0 100644
@@ -2193,6 +2193,20 @@ unsigned int udp_poll(struct file *file, struct socket *sock, poll_table *wait)
 }
 EXPORT_SYMBOL(udp_poll);
 
+int udp_abort(struct sock *sk, int err)
+{
+	lock_sock(sk);
+
+	sk->sk_err = err;
+	sk->sk_error_report(sk);
+	udp_disconnect(sk, 0);
+
+	release_sock(sk);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(udp_abort);
+
 struct proto udp_prot = {
 	.name		   = "UDP",
 	.owner		   = THIS_MODULE,
@@ -2224,6 +2238,7 @@ struct proto udp_prot = {
 	.compat_getsockopt = compat_udp_getsockopt,
 #endif
 	.clear_sk	   = sk_prot_clear_portaddr_nulls,
+	.diag_destroy	   = udp_abort,
 };
 EXPORT_SYMBOL(udp_prot);
 
net/ipv4/udp_diag.c +79 -0

97 lines not on this page · raw message

net/ipv6/udp.c +1 -0
index 81e2f98b958d..16512cf06e73 100644
@@ -1467,6 +1467,7 @@ struct proto udpv6_prot = {
 	.compat_getsockopt = compat_udpv6_getsockopt,
 #endif
 	.clear_sk	   = udp_v6_clear_sk,
+	.diag_destroy      = udp_abort,
 };
 
 static struct inet_protosw udpv6_protosw = {
Signature · 1 line
2.1.4
maintainer Applied
#1 lore raw

From: David Ahern <[email protected]>
Date: Tue, 23 Aug 2016 21:06:33 -0700

Quoted 6 lines

This implements SOCK_DESTROY for UDP sockets similar to what was done for TCP with commit c1e64e298b8ca ("net: diag: Support destroying TCP sockets.") A process with a UDP socket targeted for destroy is awakened and recvmsg fails with ECONNABORTED.

Applied.