All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Bob Pearson <rpearsonhpe@gmail.com>
Cc: leon@kernel.org, zyjzyj2000@gmail.com, jhack@hpe.com,
	linux-rdma@vger.kernel.org
Subject: Re: [PATCH for-next 9/9] RDMA/rxe: Protect pending send packets
Date: Wed, 2 Aug 2023 11:57:55 -0300	[thread overview]
Message-ID: <ZMpu86c4HCoFwIUA@nvidia.com> (raw)
In-Reply-To: <dad6082d-24f8-ccc7-0714-e89141159eac@gmail.com>

On Wed, Aug 02, 2023 at 09:39:55AM -0500, Bob Pearson wrote:
> On 8/1/23 17:56, Jason Gunthorpe wrote:
> > On Mon, Jul 31, 2023 at 01:44:47PM -0500, Bob Pearson wrote:
> >> On 7/31/23 13:32, Jason Gunthorpe wrote:
> >>> On Mon, Jul 31, 2023 at 01:26:23PM -0500, Bob Pearson wrote:
> >>>> On 7/31/23 13:17, Jason Gunthorpe wrote:
> >>>>> On Fri, Jul 21, 2023 at 03:50:22PM -0500, Bob Pearson wrote:
> >>>>>> Network interruptions may cause long delays in the processing of
> >>>>>> send packets during which time the rxe driver may be unloaded.
> >>>>>> This will cause seg faults when the packet is ultimately freed as
> >>>>>> it calls the destructor function in the rxe driver. This has been
> >>>>>> observed in cable pull fail over fail back testing.
> >>>>>
> >>>>> No, module reference counts are only for code that is touching
> >>>>> function pointers.
> >>>>
> >>>> this is exactly the case here. it is the skb destructor function that
> >>>> is carried by the skb.
> >>>
> >>> It can't possibly call it correctly without also having the rxe
> >>> ib_device reference too though??
> >>
> >> Nope. This was causing seg faults in testing when there was a long network
> >> hang and the admin tried to reload the rxe driver. The skb code doesn't care
> >> about the ib device at all.
> > 
> > I don't get it, there aren't globals in rxe, so WTF is it doing if it
> > isn't somehow tracing back to memory that is under the ib_device
> > lifetime?
> > 
> > Jason
> 
> When the rxe driver builds a send packet it puts the address of its destructor
> subroutine in the skb before calling ip_local_out and sending it. The address of
> driver software is now hanging around. If you don't delay the module exit routine
> until all the skb's are freed you can cause seg faults. The only way to cause this to
> happen is to call rmmod on the driver too early but people have done this occasionally
> and report it as a bug.

You are missing the point, the destructor currently does this:

static void rxe_skb_tx_dtor(struct sk_buff *skb)
{
	struct sock *sk = skb->sk;
	struct rxe_qp *qp = sk->sk_user_data;

So you've already UAF'd because rxe_qp is freed memory well before you
get to unloading the module.

This series changed it to do this:
 
 static void rxe_skb_tx_dtor(struct sk_buff *skb)
 {
	struct rxe_dev *rxe;
	unsigned int index;
	struct rxe_qp *qp;
	int skb_out;

	/* takes a ref on ib device if success */
	rxe = get_rxe_from_skb(skb);
	if (!rxe)
		goto out;

 
static struct rxe_dev *get_rxe_from_skb(struct sk_buff *skb)
{
	struct rxe_dev *rxe;
	struct net_device *ndev = skb->dev;

	rxe = rxe_get_dev_from_net(ndev);
	if (!rxe && is_vlan_dev(ndev))
		rxe = rxe_get_dev_from_net(vlan_dev_real_dev(ndev));


Which seems totally nutz, you are now relying on the global hash table
in ib_core to resolve the ib device.

Again, why can't this code do something sane like refcount the qp or
ib_device so the destruction doesn't progress until all the SKBs are
flushed out?

Jason

      reply	other threads:[~2023-08-02 14:58 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-21 20:50 [PATCH for-next 0/9] RDMA/rxe: Misc fixes and cleanups Bob Pearson
2023-07-21 20:50 ` [PATCH for-next 1/9] RDMA/rxe: Fix handling sleepable in rxe_pool.c Bob Pearson
2023-07-31 18:08   ` Jason Gunthorpe
2023-07-21 20:50 ` [PATCH for-next 2/9] RDMA/rxe: Fix xarray locking " Bob Pearson
2023-07-21 20:50 ` [PATCH for-next 3/9] RDMA/rxe: Fix freeing busy objects Bob Pearson
2023-07-31 18:11   ` Jason Gunthorpe
2023-07-31 18:16     ` Bob Pearson
2023-07-31 18:22       ` Jason Gunthorpe
2023-07-21 20:50 ` [PATCH for-next 4/9] RDMA/rxe: Fix delayed send packet handling Bob Pearson
2023-07-23 13:03   ` Zhu Yanjun
2023-07-23 17:24     ` Bob Pearson
2023-07-24 17:59     ` Leon Romanovsky
2023-07-24 18:26       ` Bob Pearson
2023-07-31 18:12   ` Jason Gunthorpe
2023-07-31 18:20     ` Bob Pearson
2023-07-31 18:23       ` Jason Gunthorpe
2023-07-31 18:33         ` Bob Pearson
2023-08-04 14:17           ` Jason Gunthorpe
2023-07-21 20:50 ` [PATCH for-next 5/9] RDMA/rxe: Optimize rxe_init_packet in rxe_net.c Bob Pearson
2023-07-21 20:50 ` [PATCH for-next 6/9] RDMA/rxe: Delete unused field elem->list Bob Pearson
2023-07-21 20:50 ` [PATCH for-next 7/9] RDMA/rxe: Add elem->valid field Bob Pearson
2023-07-31 18:15   ` Jason Gunthorpe
2023-07-21 20:50 ` [PATCH for-next 8/9] RDMA/rxe: Report leaked objects Bob Pearson
2023-07-31 18:15   ` Jason Gunthorpe
2023-07-31 18:23     ` Bob Pearson
2023-07-31 18:31       ` Jason Gunthorpe
2023-07-31 18:42         ` Bob Pearson
2023-07-31 18:43           ` Jason Gunthorpe
2023-07-31 18:51             ` Bob Pearson
2023-08-04 14:16               ` Jason Gunthorpe
2023-07-21 20:50 ` [PATCH for-next 9/9] RDMA/rxe: Protect pending send packets Bob Pearson
2023-07-31 18:17   ` Jason Gunthorpe
2023-07-31 18:26     ` Bob Pearson
2023-07-31 18:32       ` Jason Gunthorpe
2023-07-31 18:44         ` Bob Pearson
2023-08-01 22:56           ` Jason Gunthorpe
2023-08-02 14:39             ` Bob Pearson
2023-08-02 14:57               ` Jason Gunthorpe [this message]

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=ZMpu86c4HCoFwIUA@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=jhack@hpe.com \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=rpearsonhpe@gmail.com \
    --cc=zyjzyj2000@gmail.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 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.