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 13:08:27 -0400	[thread overview]
Message-ID: <CAB9dFdsVxzi_Tx2yvStXLr2qvqd4ht4H1BRM8A5E1x-cBMv4mg@mail.gmail.com> (raw)
In-Reply-To: <CAEfhGixbKf7+j_4KUvNSQL96N+-9SsDSaH0CmfL=iwWFAYDeMg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 370 bytes --]

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.

[-- Attachment #2: reuseport_crash.c --]
[-- Type: text/x-csrc, Size: 911 bytes --]

#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>

#include <arpa/inet.h>

int
main(int argc, char **argv)
{
    struct sockaddr_in addr, addr2;
    int len, optval = 1;
    int s1, s2;

    addr.sin_addr.s_addr = htonl(INADDR_ANY);
    addr.sin_family = AF_INET;
    addr.sin_port = 0;

    s1 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
    s2 = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

    bind(s1, (struct sockaddr *)&addr, sizeof(addr));
    setsockopt(s1, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval));
    setsockopt(s2, SOL_SOCKET, SO_REUSEPORT, &optval, sizeof(optval));

    len = sizeof(addr);
    getsockname(s1, (struct sockaddr *)&addr, (socklen_t *)&len);
    addr2.sin_addr.s_addr = htonl(INADDR_ANY);
    addr2.sin_family = AF_INET;
    addr2.sin_port = addr.sin_port;
    bind(s2, (struct sockaddr *)&addr2, sizeof(addr));
    close(s2);
    close(s1);
    return 0;
}

  reply	other threads:[~2016-01-19 17:08 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 [this message]
2016-01-19 18:11       ` Craig Gallek
2016-01-19 18:51         ` Marc Dionne
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=CAB9dFdsVxzi_Tx2yvStXLr2qvqd4ht4H1BRM8A5E1x-cBMv4mg@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.