From: Simon Horman <simon.horman@corigine.com>
To: Lin Ma <linma@zju.edu.cn>
Cc: krzysztof.kozlowski@linaro.org, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
netdev@vger.kernel.org, sameo@linux.intel.com,
thierry.escande@linux.intel.com
Subject: Re: [PATCH v4] net: nfc: Fix use-after-free caused by nfc_llcp_find_local
Date: Sun, 25 Jun 2023 09:06:48 +0200 [thread overview]
Message-ID: <ZJfniMAoum2x6ul4@corigine.com> (raw)
In-Reply-To: <20230625005439.8728-1-linma@zju.edu.cn>
+ Blamed authors; corected davem's email address
On Sun, Jun 25, 2023 at 08:54:39AM +0800, Lin Ma wrote:
...
> @@ -696,20 +696,22 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
> if (dev->dep_link_up == false) {
> ret = -ENOLINK;
> device_unlock(&dev->dev);
> - goto put_dev;
> + goto sock_llcp_put_local;
> }
> device_unlock(&dev->dev);
>
> if (local->rf_mode == NFC_RF_INITIATOR &&
> addr->target_idx != local->target_idx) {
> ret = -ENOLINK;
> - goto put_dev;
> + goto sock_llcp_put_local;
> }
>
> llcp_sock->dev = dev;
> - llcp_sock->local = nfc_llcp_local_get(local);
> + llcp_sock->local = local;
> llcp_sock->ssap = nfc_llcp_get_local_ssap(local);
> if (llcp_sock->ssap == LLCP_SAP_MAX) {
> + llcp_sock->local = NULL;
> + llcp_sock->dev = NULL;
> ret = -ENOMEM;
> goto sock_llcp_put_local;
> }
Hi Lin Ma,
thanks for your patch.
I agree with the get/put handling in this patch.
But I have a question regarding the changes to llcp_sock_connect().
Setting of llcp_sock->local and llcp_sock->dev has been moved
from the sock_llcp_put_local label, below,
to the error handling for nfc_llcp_get_local_ssap, above.
For the case where nfc_llcp_get_local_ssap returns an error this seems
fine. However, there are two other cases that this effects. Relevant
code, which appears between the hunk above and the one below is:
--- start ---
llcp_sock->service_name = kmemdup(addr->service_name,
llcp_sock->service_name_len,
GFP_KERNEL);
if (!llcp_sock->service_name) {
ret = -ENOMEM;
goto sock_llcp_release;
}
nfc_llcp_sock_link(&local->connecting_sockets, sk);
ret = nfc_llcp_send_connect(llcp_sock);
if (ret)
goto sock_unlink;
sk->sk_state = LLCP_CONNECTING;
ret = sock_wait_state(sk, LLCP_CONNECTED,
sock_sndtimeo(sk, flags & O_NONBLOCK));
if (ret && ret != -EINPROGRESS)
goto sock_unlink;
--- end ---
It seems to me that in the error handling above,
where the gotos will feed into sock_llcp_put_local,
llcp_sock->local and llcp_sock->dev will not be reset to NULL
in these cases anymore.
Is that ok?
> @@ -758,9 +760,7 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
> nfc_llcp_put_ssap(local, llcp_sock->ssap);
>
> sock_llcp_put_local:
> - nfc_llcp_local_put(llcp_sock->local);
> - llcp_sock->local = NULL;
> - llcp_sock->dev = NULL;
> + nfc_llcp_local_put(local);
>
> put_dev:
> nfc_put_device(dev);
...
prev parent reply other threads:[~2023-06-25 7:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-25 0:54 [PATCH v4] net: nfc: Fix use-after-free caused by nfc_llcp_find_local Lin Ma
2023-06-25 7:06 ` Simon Horman [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZJfniMAoum2x6ul4@corigine.com \
--to=simon.horman@corigine.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=kuba@kernel.org \
--cc=linma@zju.edu.cn \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=sameo@linux.intel.com \
--cc=thierry.escande@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).