All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cong Wang <xiyou.wangcong@gmail.com>
To: "Gong, Sishuai" <sishuai@purdue.edu>
Cc: "jchapman@katalix.com" <jchapman@katalix.com>,
	"tparkin@katalix.com" <tparkin@katalix.com>,
	"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: A concurrency bug between l2tp_tunnel_register() and l2tp_xmit_core()
Date: Wed, 14 Apr 2021 13:07:01 -0700	[thread overview]
Message-ID: <CAM_iQpWs+T+ps3N7XD2s3YWrqAbQ0zqO_pmFpiFOG5y84Nku0Q@mail.gmail.com> (raw)
In-Reply-To: <400E2FE1-A1E7-43EE-9ABA-41C65601C6EB@purdue.edu>

On Tue, Apr 13, 2021 at 3:10 PM Gong, Sishuai <sishuai@purdue.edu> wrote:
>
> Hi,
>
> We found a concurrency bug in linux 5.12-rc3 and we are able to reproduce it under x86. This bug happens when two l2tp functions l2tp_tunnel_register() and l2tp_xmit_core() are running in parallel. In general, l2tp_tunnel_register() registered a tunnel that hasn’t been fully initialized and then l2tp_xmit_core() tries to access an uninitialized attribute. The interleaving is shown below..
>
> ------------------------------------------
> Execution interleaving
>
> Thread 1                                                                                                Thread 2
>
> l2tp_tunnel_register()
>         spin_lock_bh(&pn->l2tp_tunnel_list_lock);
>                 …
>                 list_add_rcu(&tunnel->list, &pn->l2tp_tunnel_list);
>                 // tunnel becomes visible
>         spin_unlock_bh(&pn->l2tp_tunnel_list_lock);
>                                                                                                         pppol2tp_connect()
>                                                                                                                 …
>                                                                                                                 tunnel = l2tp_tunnel_get(sock_net(sk), info.tunnel_id);
>                                                                                                                 // Successfully get the new tunnel
>                                                                                                         …
>                                                                                                         l2tp_xmit_core()
>                                                                                                                 struct sock *sk = tunnel->sock;
>                                                                                                                 // uninitialized, sk=0
>                                                                                                                 …
>                                                                                                                 bh_lock_sock(sk);
>                                                                                                                 // Null-pointer exception happens
>         …
>         tunnel->sock = sk;
>
> ------------------------------------------
> Impact & fix
>
> This bug causes a kernel NULL pointer deference error, as attached below. Currently, we think a potential fix is to initialize tunnel->sock before adding the tunnel into l2tp_tunnel_list.

I think this is the right fix. Please submit a patch formally.

Thanks.

      parent reply	other threads:[~2021-04-14 20:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-13 17:30 A concurrency bug between l2tp_tunnel_register() and l2tp_xmit_core() Gong, Sishuai
2021-04-14 19:37 ` Tom Parkin
2021-04-14 19:53   ` Gong, Sishuai
2021-04-14 20:07 ` Cong Wang [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=CAM_iQpWs+T+ps3N7XD2s3YWrqAbQ0zqO_pmFpiFOG5y84Nku0Q@mail.gmail.com \
    --to=xiyou.wangcong@gmail.com \
    --cc=jchapman@katalix.com \
    --cc=netdev@vger.kernel.org \
    --cc=sishuai@purdue.edu \
    --cc=tparkin@katalix.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 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.