diff mbox series

[net] kcm: get rid of unnecessary cleanup

Message ID 20220822040628.177649-1-xiyou.wangcong@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net] kcm: get rid of unnecessary cleanup | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 85 this patch: 85
netdev/cc_maintainers fail 3 blamed authors not CCed: edumazet@google.com tom@quantonium.net davem@davemloft.net; 7 maintainers not CCed: ast@kernel.org sgarzare@redhat.com davem@davemloft.net edumazet@google.com f.fainelli@gmail.com pabeni@redhat.com tom@quantonium.net
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 85 this patch: 85
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Cong Wang Aug. 22, 2022, 4:06 a.m. UTC
From: Cong Wang <cong.wang@bytedance.com>

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: syzbot+9fc084a4348493ef65d2@syzkaller.appspotmail.com
Reported-by: syzbot+e696806ef96cdd2d87cd@syzkaller.appspotmail.com
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 <kuba@kernel.org>
Cc: Tom Herbert <tom@herbertland.com>
Signed-off-by: Cong Wang <cong.wang@bytedance.com>
---
 net/kcm/kcmsock.c | 2 --
 1 file changed, 2 deletions(-)

Comments

Jakub Kicinski Aug. 23, 2022, 11:39 p.m. UTC | #1
On Sun, 21 Aug 2022 21:06:28 -0700 Cong Wang wrote:
> From: Cong Wang <cong.wang@bytedance.com>
> 
> 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: syzbot+9fc084a4348493ef65d2@syzkaller.appspotmail.com
> Reported-by: syzbot+e696806ef96cdd2d87cd@syzkaller.appspotmail.com
> 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 <kuba@kernel.org>
> Cc: Tom Herbert <tom@herbertland.com>
> Signed-off-by: Cong Wang <cong.wang@bytedance.com>
> ---
>  net/kcm/kcmsock.c | 2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c
> index 71899e5a5a11..661c40cdab3e 100644
> --- a/net/kcm/kcmsock.c
> +++ b/net/kcm/kcmsock.c
> @@ -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.
diff mbox series

Patch

diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c
index 71899e5a5a11..661c40cdab3e 100644
--- a/net/kcm/kcmsock.c
+++ b/net/kcm/kcmsock.c
@@ -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;