Combine socket copy and sanitise routines and export them, so that it can be used in modules such as SCTP. Signed-off-by: Daniel Borkmann <dborkman@xxxxxxxxxx> --- include/net/sock.h | 1 + net/core/sock.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/include/net/sock.h b/include/net/sock.h index 2ef3c3e..1789690 100644 --- a/include/net/sock.h +++ b/include/net/sock.h @@ -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); diff --git a/net/core/sock.c b/net/core/sock.c index 68a4251..46920a3 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -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); -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-sctp" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html