Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

sctp: Use sctp_clone_sock() in sctp_do_peeloff().

sctp_do_peeloff() calls sock_create() to allocate and initialise
struct sock, inet_sock, and sctp_sock, but later sctp_copy_sock()
and sctp_sock_migrate() overwrite most fields.

What sctp_do_peeloff() does is more like accept().

Let's use sock_create_lite() and sctp_clone_sock().

Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
Acked-by: Xin Long <lucien.xin@gmail.com>
Link: https://patch.msgid.link/20251023231751.4168390-8-kuniyu@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Kuniyuki Iwashima and committed by
Jakub Kicinski
b7ddb55f c49ed521

+16 -21
+1
net/ipv4/af_inet.c
··· 788 788 789 789 newsock->state = SS_CONNECTED; 790 790 } 791 + EXPORT_SYMBOL_GPL(__inet_accept); 791 792 792 793 /* 793 794 * Accept a pending connection. The TCP layer now gives BSD semantics.
+15 -21
net/sctp/socket.c
··· 5671 5671 5672 5672 /* Helper routine to branch off an association to a new socket. */ 5673 5673 static int sctp_do_peeloff(struct sock *sk, sctp_assoc_t id, 5674 - struct socket **sockp) 5674 + struct socket **sockp) 5675 5675 { 5676 5676 struct sctp_association *asoc = sctp_id2assoc(sk, id); 5677 - struct sctp_sock *sp = sctp_sk(sk); 5678 5677 struct socket *sock; 5678 + struct sock *newsk; 5679 5679 int err = 0; 5680 5680 5681 5681 /* Do not peel off from one netns to another one. */ ··· 5691 5691 if (!sctp_style(sk, UDP)) 5692 5692 return -EINVAL; 5693 5693 5694 - /* Create a new socket. */ 5695 - err = sock_create(sk->sk_family, SOCK_SEQPACKET, IPPROTO_SCTP, &sock); 5696 - if (err < 0) 5694 + err = sock_create_lite(sk->sk_family, SOCK_SEQPACKET, IPPROTO_SCTP, &sock); 5695 + if (err) 5697 5696 return err; 5698 5697 5699 - sctp_copy_sock(sock->sk, sk, asoc); 5700 - 5701 - /* Make peeled-off sockets more like 1-1 accepted sockets. 5702 - * Set the daddr and initialize id to something more random and also 5703 - * copy over any ip options. 5704 - */ 5705 - sp->pf->to_sk_daddr(&asoc->peer.primary_addr, sock->sk); 5706 - sp->pf->copy_ip_options(sk, sock->sk); 5707 - 5708 - /* Populate the fields of the newsk from the oldsk and migrate the 5709 - * asoc to the newsk. 5710 - */ 5711 - err = sctp_sock_migrate(sk, sock->sk, asoc, 5712 - SCTP_SOCKET_UDP_HIGH_BANDWIDTH); 5713 - if (err) { 5698 + newsk = sctp_clone_sock(sk, asoc, SCTP_SOCKET_UDP_HIGH_BANDWIDTH); 5699 + if (IS_ERR(newsk)) { 5714 5700 sock_release(sock); 5715 - sock = NULL; 5701 + *sockp = NULL; 5702 + return PTR_ERR(newsk); 5716 5703 } 5704 + 5705 + lock_sock_nested(newsk, SINGLE_DEPTH_NESTING); 5706 + __inet_accept(sk->sk_socket, sock, newsk); 5707 + release_sock(newsk); 5708 + 5709 + sock->ops = sk->sk_socket->ops; 5710 + __module_get(sock->ops->owner); 5717 5711 5718 5712 *sockp = sock; 5719 5713