From: David Miller <davem@davemloft.net>
To: dborkman@redhat.com
Cc: netdev@vger.kernel.org, noureddine@aristanetworks.com,
greearb@candelatech.com, eric.dumazet@gmail.com
Subject: Re: [PATCH v3] packet: fix use after free race in send path when dev is released
Date: Thu, 21 Nov 2013 13:18:04 -0500 (EST) [thread overview]
Message-ID: <20131121.131804.553779665697649670.davem@davemloft.net> (raw)
In-Reply-To: <1385049058-1946-1-git-send-email-dborkman@redhat.com>
From: Daniel Borkmann <dborkman@redhat.com>
Date: Thu, 21 Nov 2013 16:50:58 +0100
> Salam reported a use after free bug in PF_PACKET that occurs when
> we're sending out frames on a socket bound device and suddenly the
> net device is being unregistered. It appears that commit 827d9780
> introduced a possible race condition between {t,}packet_snd() and
> packet_notifier(). In the case of a bound socket, packet_notifier()
> can drop the last reference to the net_device and {t,}packet_snd()
> might end up suddenly sending a packet over a freed net_device.
>
> To avoid reverting 827d9780 and thus introducing a performance
> regression compared to the current state of things, we decided to
> hold a cached RCU protected pointer to the net device and maintain
> it on write side via bind spin_lock protected register_prot_hook()
> and __unregister_prot_hook() calls.
>
> In {t,}packet_snd() path, we access this pointer under rcu_read_lock
> through packet_cached_dev_get() that holds reference to the device
> to prevent it from being freed through packet_notifier() while
> we're in send path. This is okay to do as dev_put()/dev_hold() are
> per-cpu counters, so this should not be a performance issue. Also,
> the code simplifies a bit as we don't need need_rls_dev anymore.
>
> Fixes: 827d978037d7 ("af-packet: Use existing netdev reference for bound sockets.")
> Reported-by: Salam Noureddine <noureddine@aristanetworks.com>
> Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
> Signed-off-by: Salam Noureddine <noureddine@aristanetworks.com>
Applied and queued up for -stable, thanks.
next prev parent reply other threads:[~2013-11-21 18:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-21 15:50 [PATCH v3] packet: fix use after free race in send path when dev is released Daniel Borkmann
2013-11-21 18:18 ` David Miller [this message]
2013-11-21 22:40 ` Ben Greear
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=20131121.131804.553779665697649670.davem@davemloft.net \
--to=davem@davemloft.net \
--cc=dborkman@redhat.com \
--cc=eric.dumazet@gmail.com \
--cc=greearb@candelatech.com \
--cc=netdev@vger.kernel.org \
--cc=noureddine@aristanetworks.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