Skip to content

Commit 8fc29ff

Browse files
Cong Wangkuba-moo
authored andcommitted
kcm: fix strp_init() order and cleanup
strp_init() is called just a few lines above this csk->sk_user_data check, it also initializes strp->work etc., therefore, it is unnecessary to call strp_done() to cancel the freshly initialized work. And if sk_user_data is already used by KCM, psock->strp should not be touched, particularly strp->work state, so we need to move strp_init() after the csk->sk_user_data check. This also makes a lockdep warning reported by syzbot go away. Reported-and-tested-by: [email protected] Reported-by: [email protected] Fixes: e557124 ("kcm: Check if sk_user_data already set in kcm_attach") Fixes: dff8baa ("kcm: Call strp_stop before strp_done in kcm_attach") Cc: Tom Herbert <[email protected]> Signed-off-by: Cong Wang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3a1a274 commit 8fc29ff

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

net/kcm/kcmsock.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,26 +1412,25 @@ static int kcm_attach(struct socket *sock, struct socket *csock,
14121412
psock->sk = csk;
14131413
psock->bpf_prog = prog;
14141414

1415-
err = strp_init(&psock->strp, csk, &cb);
1416-
if (err) {
1417-
kmem_cache_free(kcm_psockp, psock);
1418-
goto out;
1419-
}
1420-
14211415
write_lock_bh(&csk->sk_callback_lock);
14221416

14231417
/* Check if sk_user_data is already by KCM or someone else.
14241418
* Must be done under lock to prevent race conditions.
14251419
*/
14261420
if (csk->sk_user_data) {
14271421
write_unlock_bh(&csk->sk_callback_lock);
1428-
strp_stop(&psock->strp);
1429-
strp_done(&psock->strp);
14301422
kmem_cache_free(kcm_psockp, psock);
14311423
err = -EALREADY;
14321424
goto out;
14331425
}
14341426

1427+
err = strp_init(&psock->strp, csk, &cb);
1428+
if (err) {
1429+
write_unlock_bh(&csk->sk_callback_lock);
1430+
kmem_cache_free(kcm_psockp, psock);
1431+
goto out;
1432+
}
1433+
14351434
psock->save_data_ready = csk->sk_data_ready;
14361435
psock->save_write_space = csk->sk_write_space;
14371436
psock->save_state_change = csk->sk_state_change;

0 commit comments

Comments
 (0)