All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Dionne <marc.c.dionne@gmail.com>
To: Craig Gallek <kraig@google.com>
Cc: netdev <netdev@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Eric Dumazet <edumazet@google.com>
Subject: Re: Crash with SO_REUSEPORT and ef456144da8ef507c8cf504284b6042e9201a05c
Date: Tue, 19 Jan 2016 14:51:53 -0400	[thread overview]
Message-ID: <CAB9dFdsGxwcuGqWnFShm3qb2nsC2Pk2AT=Zb6TFM+jR41Kuqjg@mail.gmail.com> (raw)
In-Reply-To: <CAEfhGiy=-AgMad_tquyXws7Vf3j9HWwhCnaZqWeq58_XSzcgoA@mail.gmail.com>

On Tue, Jan 19, 2016 at 2:11 PM, Craig Gallek <kraig@google.com> wrote:
> On Tue, Jan 19, 2016 at 12:08 PM, Marc Dionne <marc.c.dionne@gmail.com> wrote:
>> On Tue, Jan 19, 2016 at 12:31 PM, Craig Gallek <kraig@google.com> wrote:
>>>
>>> I need to think about how to handle setsockopt-after-bind condition a
>>> bit more, but the NULL pointer dereference is obviously wrong.  Do you
>>> have a way to easily reproduce this?  I've only managed to get it to
>>> happen once so far...
>>
>> The attached code reliably triggers the crash for me.
>
> I think the patch below will address this issue (sorry in advance if
> gmail screws up the whitespace...).  I'll send it for formal review
> once I finish testing it.
>
> Craig
>
> diff --git a/net/core/sock_reuseport.c b/net/core/sock_reuseport.c
> index 1df98c557440..004cb2c974ac 100644
> --- a/net/core/sock_reuseport.c
> +++ b/net/core/sock_reuseport.c
> @@ -97,6 +97,11 @@ int reuseport_add_sock(struct sock *sk, const
> struct sock *sk2)
>  {
>   struct sock_reuseport *reuse;
>
> +  if (!rcu_access_pointer(sk2->sk_reuseport_cb)) {
> +   int err = reuseport_alloc(sk2);
> +   if (err) return err;
> +  }
> +
>   spin_lock_bh(&reuseport_lock);
>   reuse = rcu_dereference_protected(sk2->sk_reuseport_cb,
>    lockdep_is_held(&reuseport_lock)),

That works fine, thanks..

Just wondering though, is there a bit of a race there?  Seems like it
might be safer to have a version of reuseport_alloc that doesn't take
the lock and use it here, moving the block after the lock is taken.

Marc

  reply	other threads:[~2016-01-19 18:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-19 15:57 Crash with SO_REUSEPORT and ef456144da8ef507c8cf504284b6042e9201a05c Marc Dionne
2016-01-19 16:04 ` Marc Dionne
2016-01-19 16:31   ` Craig Gallek
2016-01-19 17:08     ` Marc Dionne
2016-01-19 18:11       ` Craig Gallek
2016-01-19 18:51         ` Marc Dionne [this message]
2016-01-19 16:14 ` Eric Dumazet
2016-01-19 19:08 Craig Gallek
2016-01-19 19:32 ` Marc Dionne

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='CAB9dFdsGxwcuGqWnFShm3qb2nsC2Pk2AT=Zb6TFM+jR41Kuqjg@mail.gmail.com' \
    --to=marc.c.dionne@gmail.com \
    --cc=edumazet@google.com \
    --cc=kraig@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.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.