From: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com>
To: Dan Carpenter <dan.carpenter@oracle.com>,
Samuel Ortiz <sameo@linux.intel.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>,
"John W. Linville" <linville@tuxdriver.com>,
netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH net] nfc: avoid potential race condition
Date: Thu, 23 Sep 2021 09:26:51 +0200 [thread overview]
Message-ID: <3760c70c-299c-89bf-5a4a-22e8d564ef92@canonical.com> (raw)
In-Reply-To: <20210923065051.GA25122@kili>
On 23/09/2021 08:50, Dan Carpenter wrote:
> This from static analysis inspired by CVE-2021-26708 where there was a
> race condition because it didn't lock_sock(sk) before saving
> "vsk->transport". Here it is saving "llcp_sock->local" but the concept
> is the same that it needs to take the lock first.
I think the difference between this llcp_sock code and above transport,
is lack of writer to llcp_sock->local with whom you could race.
Commits c0cfa2d8a788fcf4 and 6a2c0962105ae8ce causing the
multi-transport race show nicely assigns to vsk->transport when module
is unloaded.
Here however there is no writer to llcp_sock->local, except bind and
connect and their error paths. The readers which you modify here, have
to happen after bind/connect. You cannot have getsockopt() or release()
before bind/connect, can you? Unless you mean here the bind error path,
where someone calls getsockopt() in the middle of bind()? Is it even
possible?
The code except this looks reasonable and since writer protects
llcp_sock->local(), the reader I guess should do it as well... just
wondering whether this is a real issue.
Best regards,
Krzysztof
>
> Fixes: 00e856db49bb ("NFC: llcp: Fall back to local values when getting socket options")
> Fixes: d646960f7986 ("NFC: Initial LLCP support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> net/nfc/llcp_sock.c | 15 +++++++++------
> 1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/net/nfc/llcp_sock.c b/net/nfc/llcp_sock.c
> index 6cfd30fc0798..74f4209c7144 100644
> --- a/net/nfc/llcp_sock.c
> +++ b/net/nfc/llcp_sock.c
> @@ -314,14 +314,16 @@ static int nfc_llcp_getsockopt(struct socket *sock, int level, int optname,
> if (get_user(len, optlen))
> return -EFAULT;
>
> - local = llcp_sock->local;
> - if (!local)
> - return -ENODEV;
> -
> len = min_t(u32, len, sizeof(u32));
>
> lock_sock(sk);
>
> + local = llcp_sock->local;
> + if (!local) {
> + release_sock(sk);
> + return -ENODEV;
> + }
> +
> switch (optname) {
> case NFC_LLCP_RW:
> rw = llcp_sock->rw > LLCP_MAX_RW ? local->rw : llcp_sock->rw;
> @@ -598,14 +600,15 @@ static int llcp_sock_release(struct socket *sock)
>
> pr_debug("%p\n", sk);
>
> + lock_sock(sk);
> +
> local = llcp_sock->local;
> if (local == NULL) {
> + release_sock(sk);
> err = -ENODEV;
> goto out;
> }
>
> - lock_sock(sk);
> -
> /* Send a DISC */
> if (sk->sk_state == LLCP_CONNECTED)
> nfc_llcp_send_disconnect(llcp_sock);
>
next prev parent reply other threads:[~2021-09-23 7:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-23 6:50 [PATCH net] nfc: avoid potential race condition Dan Carpenter
2021-09-23 7:26 ` Krzysztof Kozlowski [this message]
2021-09-23 12:22 ` Dan Carpenter
2021-09-24 8:21 ` Krzysztof Kozlowski
2021-09-24 20:14 ` Jakub Kicinski
2021-09-27 7:44 ` Krzysztof Kozlowski
2021-09-27 14:26 ` Jakub Kicinski
2021-09-27 14:58 ` Krzysztof Kozlowski
2021-09-27 15:13 ` Dan Carpenter
2021-09-27 15:27 ` Krzysztof Kozlowski
2021-09-27 15:38 ` Dan Carpenter
2021-09-27 14:49 ` Dan Carpenter
2021-09-27 12:14 ` Dan Carpenter
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=3760c70c-299c-89bf-5a4a-22e8d564ef92@canonical.com \
--to=krzysztof.kozlowski@canonical.com \
--cc=dan.carpenter@oracle.com \
--cc=davem@davemloft.net \
--cc=kernel-janitors@vger.kernel.org \
--cc=kuba@kernel.org \
--cc=linville@tuxdriver.com \
--cc=netdev@vger.kernel.org \
--cc=sameo@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