smc: move unhash as early as possible in smc_release()
PATCH 1/1 smc: move unhash as early as possible in smc_release()
In smc_release() we release smc->clcsock before unhash the smc sock, but a parallel smc_diag_dump() may be still reading smc->clcsock, therefore this could cause a use-after-free as reported by syzbot.
--- net/smc/af_smc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/smc/af_smc.c +3 -1
@@ -146,6 +146,9 @@ static int smc_release(struct socket *sock)sock_set_flag (sk,SOCK_DEAD ); sk->sk_shutdown |=SHUTDOWN_MASK ; } + + sk->sk_prot->unhash (sk); +if (smc->clcsock) {if (smc->use_fallback && sk->sk_state ==SMC_LISTEN ) {/* wake up clcsock accept */
@@ -170,7 +173,6 @@ static int smc_release(struct socket *sock)smc_conn_free (&smc->conn);release_sock (sk); - sk->sk_prot->unhash (sk);sock_put (sk);/* final sock_put */ out:return rc;
Signature · 1 line
2.20.1
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Sat, 5 Jan 2019 23:45:26 -0800
Quoted 9 lines
In
smc_release()we releasesmc->clcsockbefore unhash the smc sock, but a parallelsmc_diag_dump()may be still readingsmc->clcsock, therefore this could cause a use-after-free as reported by syzbot.Reported-and-tested-by [email protected]Fixes 51f1de79ad8e ("net/smc: replace sock_put worker by socket refcounting")Cc Ursula Braun <[email protected]>Signed-off-by Cong Wang <[email protected]>
We have two patches messing around in here, seeming to deal with release visibility and ordering problems in two different ways.
https://patchwork.ozlabs.org/patch/1020608/
https://patchwork.ozlabs.org/patch/1021044/
Quoted 13 lines · David Miller
From: Cong Wang <[email protected]>
Date: Sat, 5 Jan 2019 23:45:26 -0800Quoted 9 lines
In
smc_release()we releasesmc->clcsockbefore unhash the smc sock, but a parallelsmc_diag_dump()may be still readingsmc->clcsock, therefore this could cause a use-after-free as reported by syzbot.Reported-and-tested-by [email protected]Fixes 51f1de79ad8e ("net/smc: replace sock_put worker by socket refcounting")Cc Ursula Braun <[email protected]>Signed-off-by Cong Wang <[email protected]>
Quoted 9 lines
We have two patches messing around in here, seeming to deal with release visibility and ordering problems in two different ways.
https://patchwork.ozlabs.org/patch/1020608/
https://patchwork.ozlabs.org/patch/1021044/Reported-by [email protected]Reported-by [email protected]
The patches from Myungho Jung fix a closing problem for listening SMC-sockets. The patch by Cong Wang fixes a closing problem for SMC-sockets when smc_diag_dump() is running in parallel. Both are valuable in my eyes.
Quoted 14 lines · David Miller
From: Cong Wang <[email protected]>
Date: Sat, 5 Jan 2019 23:45:26 -0800Quoted 9 lines
In
smc_release()we releasesmc->clcsockbefore unhash the smc sock, but a parallelsmc_diag_dump()may be still readingsmc->clcsock, therefore this could cause a use-after-free as reported by syzbot.Reported-and-tested-by [email protected]Fixes 51f1de79ad8e ("net/smc: replace sock_put worker by socket refcounting")Cc Ursula Braun <[email protected]>Signed-off-by Cong Wang <[email protected]>
Quoted 8 lines
We have two patches messing around in here, seeming to deal with release visibility and ordering problems in two different ways.
https://patchwork.ozlabs.org/patch/1020608/
https://patchwork.ozlabs.org/patch/1021044/Reported-by [email protected]Reported-by [email protected]
Isn't Myungho's patch already merged as commit 78abe3d0dfad? :)
So I believe the syzbot reported this bug on top of that commit.
Thanks.
David Miller
maintainerFrom: Cong Wang <[email protected]>
Date: Mon, 7 Jan 2019 11:25:12 -0800
Quoted 3 lines
Isn't Myungho's patch already merged as commit
78abe3d0dfad? :)So I believe the syzbot reported this bug on top of that commit.
Aha, now it makes sense.
Yeah I'll apply your patch Cong.