netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [BUG] Crash with NULL pointer dereference in bond_handle_frame in -rt (possibly mainline)
@ 2013-03-28 17:16 Steven Rostedt
  2013-03-28 17:29 ` Eric Dumazet
  0 siblings, 1 reply; 18+ messages in thread
From: Steven Rostedt @ 2013-03-28 17:16 UTC (permalink / raw)
  To: Jiri Pirko, Andy Gospodarek, David S. Miller
  Cc: LKML, netdev, Nicolas de Pesloüan, Thomas Gleixner,
	Guy Streeter, Paul E. McKenney

Hi,

I'm currently debugging a crash in an old 3.0-rt kernel that one of our
customers is seeing. The bug happens with a stress test that loads and
unloads the bonding module in a loop (I don't know all the details as
I'm not the one that is directly interacting with the customer). But the
bug looks to be something that may still be present and possibly present
in mainline too. It will just be much harder to trigger it in mainline.

In -rt, interrupts are threads, and can schedule in and out just like
any other thread. Note, mainline now supports interrupt threads so this
may be easily reproducible in mainline as well. I don't have the ability
to tell the customer to try mainline or other kernels, so my hands are
somewhat tied to what I can do.

But according to a core dump, I tracked down that the eth irq thread
crashed in bond_handle_frame() here:

	slave = bond_slave_get_rcu(skb->dev);
	bond = slave->bond; <--- BUG


the slave returned was NULL and accessing slave->bond caused a NULL
pointer dereference.

Looking at the code that unregisters the handler:

void netdev_rx_handler_unregister(struct net_device *dev)
{

        ASSERT_RTNL();
        RCU_INIT_POINTER(dev->rx_handler, NULL);
        RCU_INIT_POINTER(dev->rx_handler_data, NULL);
}

Which is basically:
	dev->rx_handler = NULL;
	dev->rx_handler_data = NULL;

And looking at __netif_receive_skb() we have:

        rx_handler = rcu_dereference(skb->dev->rx_handler);
        if (rx_handler) {
                if (pt_prev) {
                        ret = deliver_skb(skb, pt_prev, orig_dev);
                        pt_prev = NULL;
                }
                switch (rx_handler(&skb)) {

My question to all of you is, what stops this interrupt from happening
while the bonding module is unloading?  What happens if the interrupt
triggers and we have this:


	CPU0			CPU1
	----			----
  rx_handler = skb->dev->rx_handler

			netdev_rx_handler_unregister() {
			   dev->rx_handler = NULL;
			   dev->rx_handler_data = NULL;

  rx_handler()
   bond_handle_frame() {
    slave = skb->dev->rx_handler;
    bond = slave->bond; <-- NULL pointer dereference!!!


What protection am I missing in the bond release handler that would
prevent the above from happening?

Thanks!

-- Steve

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2013-03-30  9:19 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-28 17:16 [BUG] Crash with NULL pointer dereference in bond_handle_frame in -rt (possibly mainline) Steven Rostedt
2013-03-28 17:29 ` Eric Dumazet
2013-03-28 17:44   ` Steven Rostedt
2013-03-29  9:48   ` Jiri Pirko
2013-03-29 13:01     ` [PATCH] net: add a synchronize_net() in netdev_rx_handler_unregister() Eric Dumazet
2013-03-29 13:17       ` Steven Rostedt
2013-03-29 13:38         ` Eric Dumazet
2013-03-29 15:11       ` Ivan Vecera
2013-03-29 15:38         ` Eric Dumazet
2013-03-29 16:12           ` Jiri Pirko
2013-03-29 16:46             ` Eric Dumazet
2013-03-29 19:20       ` Paul E. McKenney
2013-03-29 19:26         ` Eric Dumazet
2013-03-29 19:39         ` David Miller
2013-03-29 15:46     ` [BUG] Crash with NULL pointer dereference in bond_handle_frame in -rt (possibly mainline) Stephen Hemminger
2013-03-29 18:36     ` Steven Rostedt
2013-03-29 19:55       ` Steven Rostedt
2013-03-30  9:19       ` Jiri Pirko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).