nfc: llcp: avoid double release/put on LLCP_CLOSED in nfc_llcp_recv_disc()
Subsystems (4)
PATCH 1/1 nfc: llcp: avoid double release/put on LLCP_CLOSED in nfc_llcp_recv_disc()
nfc_llcp_sock_get() takes a reference on the LLCP socket via sock_hold().
In nfc_llcp_recv_disc(), when the socket is already in LLCP_CLOSED state, the code used to perform release_sock() and nfc_llcp_sock_put() in the CLOSED branch but then continued execution and later performed the same cleanup again on the common exit path. This results in refcount imbalance (double put) and unbalanced lock release.
Remove the redundant CLOSED-branch cleanup so that release_sock() and nfc_llcp_sock_put() are performed exactly once via the common exit path, while keeping the existing DM_DISC reply behavior.
--- net/nfc/llcp_core.c | 5 ----- 1 file changed, 5 deletions(-)
net/nfc/llcp_core.c +0 -5
@@ -1177,11 +1177,6 @@ static void nfc_llcp_recv_disc(struct nfc_llcp_local *local,nfc_llcp_socket_purge (llcp_sock); -if (sk->sk_state ==LLCP_CLOSED ) { -release_sock (sk); -nfc_llcp_sock_put (llcp_sock); - } -if (sk->sk_state ==LLCP_CONNECTED ) {nfc_put_device (local->dev); sk->sk_state =LLCP_CLOSED ;
Signature · 1 line
2.34.1
Quoted 7 lines · Qianchang Zhao
nfc_llcp_sock_get()takes a reference on the LLCP socket viasock_hold().In
nfc_llcp_recv_disc(), when the socket is already inLLCP_CLOSEDstate, the code used to performrelease_sock()andnfc_llcp_sock_put()in the CLOSED branch but then continued execution and later performed the same cleanup again on the common exit path. This results in refcount imbalance (double put) and unbalanced lock release.
You did not answer to my questions, so I repeat the same question I already asked you. Don't ignore reviewer's feedback.
Quoted 7 lines
Remove the redundant CLOSED-branch cleanup so that
release_sock()andnfc_llcp_sock_put()are performed exactly once via the common exit path, while keeping the existingDM_DISCreply behavior.Reported-by Qianchang Zhao <[email protected]>Reported-by Zhitong Liu <[email protected]>
Drop both. You are the author, there are no reported-by credits for authors.
Missing Fixes tag.
Quoted 11 lines
Signed-off-by Qianchang Zhao <[email protected]>--- net/nfc/llcp_core.c | 5 ----- 1 file changed, 5 deletions(-)net/nfc/llcp_core.c +0
-0
net/nfc/llcp_core.c static void nfc_llcp_recv_disc(struct nfc_llcp_local *local, · line 1182
Quoted 6 lines
net/nfc/llcp_core.c +0
-3@@ -1177,11 +1177,6 @@ static void nfc_llcp_recv_disc(struct nfc_llcp_local *local,nfc_llcp_socket_purge (llcp_sock); -if (sk->sk_state ==LLCP_CLOSED ) { -release_sock (sk); -nfc_llcp_sock_put (llcp_sock);
So why now sending to closed socket is right?
net/nfc/llcp_core.c static void nfc_llcp_recv_disc(struct nfc_llcp_local *local, · line 1182
Quoted 5 lines
net/nfc/llcp_core.c +0
-2- } -if (sk->sk_state ==LLCP_CONNECTED ) {nfc_put_device (local->dev); sk->sk_state =LLCP_CLOSED ;
Best regards,
Krzysztof