Skip to contentSkip to conversation

net: sock: add sk_copy_sanitize for use in modules

RFC PATCH In review Daniel Borkmann 1 participant 1 message Dec 24, 2013

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

RFC PATCH 2/3 net: sock: add sk_copy_sanitize for use in modules

Combine socket copy and sanitise routines and export them, so that it can be used in modules such as SCTP.

---
 include/net/sock.h |  1 +
 net/core/sock.c    | 15 ++++++++++-----
 2 files changed, 11 insertions(+), 5 deletions(-)
include/net/sock.h +1 -0
index 2ef3c3e..1789690 100644
@@ -1532,6 +1532,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
 void sk_free(struct sock *sk);
 void sk_release_kernel(struct sock *sk);
 struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority);
+struct sock *sk_copy_sanitize(struct sock *nsk, const struct sock *osk);
 
 struct sk_buff *sock_wmalloc(struct sock *sk, unsigned long size, int force,
 			     gfp_t priority);
net/core/sock.c +10 -5
index 68a4251..46920a3 100644
@@ -1520,6 +1520,13 @@ void sk_release_kernel(struct sock *sk)
 }
 EXPORT_SYMBOL(sk_release_kernel);
 
+struct sock *sk_copy_sanitize(struct sock *nsk, const struct sock *osk)
+{
+	sock_copy(nsk, osk);
+	return sock_sanitize(nsk, osk);
+}
+EXPORT_SYMBOL_GPL(sk_copy_sanitize);
+
 /**
  *	sk_clone_lock - clone a socket, and lock its clone
  *	@sk: the socket to clone
@@ -1532,12 +1539,10 @@ struct sock *sk_clone_lock(const struct sock *sk, const gfp_t priority)
 	struct sock *newsk;
 
 	newsk = sk_prot_alloc(sk->sk_prot, priority, sk->sk_family);
-	if (newsk = NULL)
+	if (unlikely(newsk = NULL))
 		return NULL;
-
-	sock_copy(newsk, sk);
-
-	return sock_sanitize(newsk, sk);
+	else
+		return sk_copy_sanitize(newsk, sk);
 }
 EXPORT_SYMBOL_GPL(sk_clone_lock);
 
Signature · 1 line
1.8.3.1