From: Jakub Kicinski <kuba@kernel.org>
To: Duoming Zhou <duoming@zju.edu.cn>
Cc: linux-hams@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, ralf@linux-mips.org,
davem@davemloft.net, edumazet@google.com, pabeni@redhat.com
Subject: Re: [PATCH v4] net: rose: fix null-ptr-deref caused by rose_kill_by_neigh
Date: Fri, 1 Jul 2022 19:41:55 -0700 [thread overview]
Message-ID: <20220701194155.5bd61e58@kernel.org> (raw)
In-Reply-To: <20220629104941.26351-1-duoming@zju.edu.cn>
On Wed, 29 Jun 2022 18:49:41 +0800 Duoming Zhou wrote:
> When the link layer connection is broken, the rose->neighbour is
> set to null. But rose->neighbour could be used by rose_connection()
> and rose_release() later, because there is no synchronization among
> them. As a result, the null-ptr-deref bugs will happen.
>
> One of the null-ptr-deref bugs is shown below:
>
> (thread 1) | (thread 2)
> | rose_connect
> rose_kill_by_neigh | lock_sock(sk)
> spin_lock_bh(&rose_list_lock) | if (!rose->neighbour)
> rose->neighbour = NULL;//(1) |
> | rose->neighbour->use++;//(2)
> if (rose->neighbour == neigh) {
Why is it okay to perform this comparison without the socket lock,
if we need a socket lock to clear it? Looks like rose_kill_by_neigh()
is not guaranteed to clear all the uses of a neighbor.
> + sock_hold(s);
> + spin_unlock_bh(&rose_list_lock);
> + lock_sock(s);
> rose_disconnect(s, ENETUNREACH, ROSE_OUT_OF_ORDER, 0);
> rose->neighbour->use--;
What protects the use counter?
> rose->neighbour = NULL;
> + release_sock(s);
> + spin_lock_bh(&rose_list_lock);
Don't take the lock here just dump one line further back.
> + sock_put(s);
> + goto again;
> }
> }
> spin_unlock_bh(&rose_list_lock);
> diff --git a/net/rose/rose_route.c b/net/rose/rose_route.c
> index fee6409c2bb..b116828b422 100644
> --- a/net/rose/rose_route.c
> +++ b/net/rose/rose_route.c
> @@ -827,7 +827,9 @@ void rose_link_failed(ax25_cb *ax25, int reason)
> ax25_cb_put(ax25);
>
> rose_del_route_by_neigh(rose_neigh);
> + spin_unlock_bh(&rose_neigh_list_lock);
> rose_kill_by_neigh(rose_neigh);
> + return;
> }
> spin_unlock_bh(&rose_neigh_list_lock);
> }
next prev parent reply other threads:[~2022-07-02 2:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-29 10:49 [PATCH v4] net: rose: fix null-ptr-deref caused by rose_kill_by_neigh Duoming Zhou
2022-07-02 2:41 ` Jakub Kicinski [this message]
2022-07-02 7:23 ` duoming
2022-07-02 19:01 ` Jakub Kicinski
2022-07-03 0:43 ` duoming
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=20220701194155.5bd61e58@kernel.org \
--to=kuba@kernel.org \
--cc=davem@davemloft.net \
--cc=duoming@zju.edu.cn \
--cc=edumazet@google.com \
--cc=linux-hams@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=ralf@linux-mips.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.