Skip to content

Commit 49b7d37

Browse files
karstengrkuba-moo
authored andcommitted
net/smc: Fix af_ops of child socket pointing to released memory
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: 8270d9c ("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>
1 parent d22f4f9 commit 49b7d37

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

net/smc/af_smc.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk,
121121
bool *own_req)
122122
{
123123
struct smc_sock *smc;
124+
struct sock *child;
124125

125126
smc = smc_clcsock_user_data(sk);
126127

@@ -134,8 +135,17 @@ static struct sock *smc_tcp_syn_recv_sock(const struct sock *sk,
134135
}
135136

136137
/* passthrough to original syn recv sock fct */
137-
return smc->ori_af_ops->syn_recv_sock(sk, skb, req, dst, req_unhash,
138-
own_req);
138+
child = smc->ori_af_ops->syn_recv_sock(sk, skb, req, dst, req_unhash,
139+
own_req);
140+
/* child must not inherit smc or its ops */
141+
if (child) {
142+
rcu_assign_sk_user_data(child, NULL);
143+
144+
/* v4-mapped sockets don't inherit parent ops. Don't restore. */
145+
if (inet_csk(child)->icsk_af_ops == inet_csk(sk)->icsk_af_ops)
146+
inet_csk(child)->icsk_af_ops = smc->ori_af_ops;
147+
}
148+
return child;
139149

140150
drop:
141151
dst_release(dst);

0 commit comments

Comments
 (0)