Skip to contentSkip to conversation

kcm: get rid of unnecessary cleanup

PATCH In review Cong Wang 2 participants 2 messages Aug 22, 2022 – Aug 23, 2022

Subsystems (2)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 kcm: get rid of unnecessary cleanup

From: Cong Wang <[email protected]>

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.

This also makes a lockdep warning reported by syzbot go away.

Reported-and-tested-by [email protected]
Reported-by [email protected]
Fixes e5571240236c ("kcm: Check if sk_user_data already set in kcm_attach")
Fixes dff8baa26117 ("kcm: Call strp_stop before strp_done in kcm_attach")
Cc Jakub Kicinski <[email protected]>
Cc Tom Herbert <[email protected]>
---
 net/kcm/kcmsock.c | 2 --
 1 file changed, 2 deletions(-)
net/kcm/kcmsock.c +0 -2
index 71899e5a5a11..661c40cdab3e 100644
@@ -1425,8 +1425,6 @@ static int kcm_attach(struct socket *sock, struct socket *csock,
 	 */
 	if (csk->sk_user_data) {
 		write_unlock_bh(&csk->sk_callback_lock);
-		strp_stop(&psock->strp);
-		strp_done(&psock->strp);
 		kmem_cache_free(kcm_psockp, psock);
 		err = -EALREADY;
 		goto out;
Signature · 1 line
2.34.1
maintainer
#1 lore raw
Quoted 25 lines · On Sun, 21 Aug 2022 21:06:28 -0700 Cong Wang wrote:

From: Cong Wang <[email protected]>

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.

This also makes a lockdep warning reported by syzbot go away.

Reported-and-tested-by [email protected]
Reported-by [email protected]
Fixes e5571240236c ("kcm: Check if sk_user_data already set in kcm_attach")
Fixes dff8baa26117 ("kcm: Call strp_stop before strp_done in kcm_attach")
Cc Jakub Kicinski <[email protected]>
Cc Tom Herbert <[email protected]>
---
 net/kcm/kcmsock.c | 2 --
 1 file changed, 2 deletions(-)
net/kcm/kcmsock.c +0 -0
index 71899e5a5a11..661c40cdab3e 100644

net/kcm/kcmsock.c static int kcm_attach(struct socket *sock, struct socket *csock, · line 1430

Quoted 8 lines
net/kcm/kcmsock.c +0 -2
@@ -1425,8 +1425,6 @@ static int kcm_attach(struct socket *sock, struct socket *csock,
 	 */
 	if (csk->sk_user_data) {
 		write_unlock_bh(&csk->sk_callback_lock);
-		strp_stop(&psock->strp);
-		strp_done(&psock->strp);
 		kmem_cache_free(kcm_psockp, psock);
 		err = -EALREADY;
 		goto out;

Looks correct, but if strp_init() ever grows code which needs to be unwound in strp_done() we'd risk a leak. This seems to have been Tom's intent.

Could we perhaps reorder the sk_user_data check vs the strp_init() call? sock_map already calls strp_init() under the callback lock so we'd not be introducing any new lock ordering.