public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* Infiniband stack allows references to freed memory
@ 2012-02-01 20:22 David Miller
       [not found] ` <20120201.152213.433850213028883896.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
  0 siblings, 1 reply; 20+ messages in thread
From: David Miller @ 2012-02-01 20:22 UTC (permalink / raw)
  To: roland-DgEjT+Ai2ygdnm+yROfE0A
  Cc: sean.hefty-ral2JQCrhuEAvxtiuMwx3w,
	hal.rosenstock-Re5JQEeQqe8AvxtiuMwx3w,
	linux-rdma-u79uwXL29TY76Z2rM5mHXA


Any time an ipoib_neigh is changed, a sequence like the following is made:

			spin_lock_irqsave(&priv->lock, flags);
			/*
			 * It's safe to call ipoib_put_ah() inside
			 * priv->lock here, because we know that
			 * path->ah will always hold one more reference,
			 * so ipoib_put_ah() will never do more than
			 * decrement the ref count.
			 */
			if (neigh->ah)
				ipoib_put_ah(neigh->ah);
			list_del(&neigh->list);
			ipoib_neigh_free(dev, neigh);
			spin_unlock_irqrestore(&priv->lock, flags);
			ipoib_path_lookup(skb, n, dev);

This doesn't work, because you're leaving a stale pointer to the freed up
ipoib_neigh in the special neigh->ha pointer cookie.  Yes, it even fails
with all the locking done to protect _changes_ to *ipoib_neigh(n), and
with the code in ipoib_neigh_free() that NULLs out the pointer.

The core issue is that read side calls to *to_ipoib_neigh(n) are not
being synchronized at all, they are performed without any locking.  So
whether we hold the lock or not when making changes to *ipoib_neigh(n)
you still can have threads see references to freed up ipoib_neigh
objects.

	cpu 1			cpu 2
	n = *ipoib_neigh()
				*ipoib_neigh() = NULL
				kfree(n)
	n->foo == OOPS

To be honest I wouldn't mind if ipoib managed it's neighbour entries
differently.  The way it works now is getting in the way of some
changes I want to make.  Namely that I want to make it so that
dst_entry objects do not have an attached neighbour, instead
neighbours are always looked up on demand.

Such on-demand neigh lookups require having access to the ipv4/ipv6
header destination address of the packet, and in these ipoib paths we
don't have a real obvious way to get at that without lots of kludgy
tests.

Sticking datastructure pointers into the hardware address of the neigh
is not pretty either :-)

Perhaps the ipoib code can have a private path database it manages
entirely itself, which holds all the necessary information and is
looked up by some generic key which is available easily at transmit
time and does not involve generic neighbour entries.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

end of thread, other threads:[~2012-04-18  7:55 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-01 20:22 Infiniband stack allows references to freed memory David Miller
     [not found] ` <20120201.152213.433850213028883896.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2012-02-01 21:04   ` Roland Dreier
     [not found]     ` <CAG4TOxPrAhac1y-TzA=x47sm88JfQdkrpWW4Em_mBD=KbyRo+g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-02-01 21:13       ` David Miller
     [not found]         ` <20120201.161333.2203265702893105548.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2012-02-01 21:42           ` Roland Dreier
     [not found]             ` <CAG4TOxMHG04_REzB9faBcjgUS43845qG5CgDYCUfLDYC6sEjmw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-02-01 21:50               ` David Miller
     [not found]                 ` <20120201.165041.1820098802489365638.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2012-02-01 22:02                   ` David Miller
     [not found]                     ` <20120201.170210.981802234698152048.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2012-02-01 22:06                       ` Roland Dreier
     [not found]                         ` <CAG4TOxNNTOc0hwjOuEa-p2SBf5GBnEjVQyOERiTq5gkprLioYQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-02-01 22:17                           ` David Miller
     [not found]                             ` <20120201.171703.1299449838314569881.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2012-02-01 23:28                               ` Roland Dreier
     [not found]                                 ` <CAG4TOxN75jXze4iy_nCBO1vwqvXnwKcqbAFAEFR=n-PdiG4moA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-02-02  1:21                                   ` David Miller
     [not found]                                     ` <20120201.202128.703330634975191244.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2012-02-02  2:19                                       ` Roland Dreier
2012-04-17  8:02                                       ` Or Gerlitz
     [not found]                                         ` <4F8D23A0.7000109-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2012-04-18  3:04                                           ` David Miller
     [not found]                                             ` <20120417.230418.1898458010494189728.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2012-04-18  5:58                                               ` Or Gerlitz
     [not found]                                                 ` <4F8E57F8.9050703-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2012-04-18  6:15                                                   ` David Miller
     [not found]                                                     ` <20120418.021558.255251358104374047.davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org>
2012-04-18  7:55                                                       ` Or Gerlitz
2012-02-01 22:26               ` Jason Gunthorpe
     [not found]                 ` <20120201222638.GA24483-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2012-02-01 23:32                   ` Roland Dreier
     [not found]                     ` <CAG4TOxMbDxYYyLRFJqvpDQk99f5cA7M=AA37W9R=yL5tBeshdQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-02-02  1:02                       ` Jason Gunthorpe
     [not found]                         ` <20120202010253.GB25606-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2012-02-02  1:42                           ` Roland Dreier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox