diff options
author | Karsten Graul <kgraul@linux.ibm.com> | 2022-04-08 17:10:35 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2024-12-14 19:51:47 +0100 |
commit | 5e71985e855c40443244ba51e69f36627f78fb41 (patch) | |
tree | e09ed6f892211f15c491bbb23bca748d095872cf | |
parent | 5cedfe8aaf1875a5305897107b7f298db4260019 (diff) |
net/smc: Fix af_ops of child socket pointing to released memory
commit 49b7d376abe54a49e8bd5e64824032b7c97c62d4 upstream.
Child sockets may inherit the af_ops from the parent listen socket.
When the listen socket is released then the af_ops of the child socket
points to released memory.
Solve that by restoring the original af_ops for child sockets which
inherited the parent af_ops. And clear any inherited user_data of the
parent socket.
Fixes: 8270d9c21041 ("net/smc: Limit backlog connections")
Reviewed-by: Wenjia Zhang <wenjia@linux.ibm.com>
Signed-off-by: Karsten Graul <kgraul@linux.ibm.com>
Reviewed-by: D. Wythe <alibuda@linux.alibaba.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | net/smc/af_smc.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c index 1072b32a1d75..4019f2dc9dee 100644 --- a/net/smc/af_smc.c +++ b/net/smc/af_smc.c @@ -79,6 +79,7 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk, bool *own_req) { struct smc_sock *smc; + struct sock *child; smc = smc_clcsock_user_data(sk); @@ -92,8 +93,17 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk, } /* passthrough to original syn recv sock fct */ - return smc->ori_af_ops->syn_recv_sock(sk, skb, req, dst, req_unhash, - own_req); + child = smc->ori_af_ops->syn_recv_sock(sk, skb, req, dst, req_unhash, + own_req); + /* child must not inherit smc or its ops */ + if (child) { + rcu_assign_sk_user_data(child, NULL); + + /* v4-mapped sockets don't inherit parent ops. Don't restore. */ + if (inet_csk(child)->icsk_af_ops == inet_csk(sk)->icsk_af_ops) + inet_csk(child)->icsk_af_ops = smc->ori_af_ops; + } + return child; drop: dst_release(dst); |