Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2504658imm; Mon, 24 Sep 2018 05:35:39 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbmIXGFKaXN45+4Sp700yQ52kmIwsRYJELOBPr+Pc2nk2udzt8OojR6/+fxutpXbEpZDnd6 X-Received: by 2002:a62:1a16:: with SMTP id a22-v6mr520245pfa.237.1537792539754; Mon, 24 Sep 2018 05:35:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537792539; cv=none; d=google.com; s=arc-20160816; b=BKcK1a+pKSe6VUOuIaUhp/pfwaemIdDBKM/6/OioNOc4ijEdMzgYh9pxWQiurGUaNw IpGE9AhnImX1TMjDYL8oEi/IC1qgvxRM12b04TL9d+KZaHpQbeI0RCHeGjWIujWKzwUB 4Dn8ZGcWj2jR26FiHpgJiAegCUg3g8kfw1wkMcNYZ7k+3y2wip17oCRCbIwHcgnUz9dX TqQRi34FNtZTEsFiB7kVbjrGCMeTxvAMOvKMuDqEFHXooX3K06cqwtknZ3zV6VPEr9cj GO2+oItwa8xmRYjQwo4ikCLEEE2VX0z0y6b/vzAQdIgemzyj7GkLUh9/GFhk3AK/0wf/ NSvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=SBY23RWbooESU5bW0aXeovUZWdOG5IeyAO0rS8p04kM=; b=mrJAeEvKIAysGSchxPkO1pOR9hVpHWRctYp+R7GOO3JGKdQ8Bq2sZFE2LVdk1pHQed i73Mwz4aCOCe5PDupu4AbOUk04ojQE2YR8g4ZUMr/K/FC5nORjOd5AN08LqyC9aS2fRq yWTAmqalvUEXpljmiFKXNLwLhkIDJAJyNDF9km7kEdv+F/mc2bgXk4kCaXv2Y+uXWKoZ BxVLcUdC5qIAHFYhMnI9Zcahq1eDwqK1hphZ3B2kWv+i6lofbVNPr+9cUib/298FKqhh ig8eJfXA8ehXuzWWYwyHc0N5BZxxTeEns4xQ9ZigvzEY/AobhVP0t5LWDHau+tgQrbY5 YDLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n12-v6si7970951pgl.136.2018.09.24.05.35.24; Mon, 24 Sep 2018 05:35:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388284AbeIXSfN (ORCPT + 99 others); Mon, 24 Sep 2018 14:35:13 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:58344 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733238AbeIXSfM (ORCPT ); Mon, 24 Sep 2018 14:35:12 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5C2061098; Mon, 24 Sep 2018 12:33:16 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Aaron Knister , Ira Weiny , Jason Gunthorpe Subject: [PATCH 4.18 102/235] IB/ipoib: Avoid a race condition between start_xmit and cm_rep_handler Date: Mon, 24 Sep 2018 13:51:28 +0200 Message-Id: <20180924113115.672237596@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180924113103.999624566@linuxfoundation.org> References: <20180924113103.999624566@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Aaron Knister commit 816e846c2eb9129a3e0afa5f920c8bbc71efecaa upstream. Inside of start_xmit() the call to check if the connection is up and the queueing of the packets for later transmission is not atomic which leaves a window where cm_rep_handler can run, set the connection up, dequeue pending packets and leave the subsequently queued packets by start_xmit() sitting on neigh->queue until they're dropped when the connection is torn down. This only applies to connected mode. These dropped packets can really upset TCP, for example, and cause multi-minute delays in transmission for open connections. Here's the code in start_xmit where we check to see if the connection is up: if (ipoib_cm_get(neigh)) { if (ipoib_cm_up(neigh)) { ipoib_cm_send(dev, skb, ipoib_cm_get(neigh)); goto unref; } } The race occurs if cm_rep_handler execution occurs after the above connection check (specifically if it gets to the point where it acquires priv->lock to dequeue pending skb's) but before the below code snippet in start_xmit where packets are queued. if (skb_queue_len(&neigh->queue) < IPOIB_MAX_PATH_REC_QUEUE) { push_pseudo_header(skb, phdr->hwaddr); spin_lock_irqsave(&priv->lock, flags); __skb_queue_tail(&neigh->queue, skb); spin_unlock_irqrestore(&priv->lock, flags); } else { ++dev->stats.tx_dropped; dev_kfree_skb_any(skb); } The patch acquires the netif tx lock in cm_rep_handler for the section where it sets the connection up and dequeues and retransmits deferred skb's. Fixes: 839fcaba355a ("IPoIB: Connected mode experimental support") Cc: stable@vger.kernel.org Signed-off-by: Aaron Knister Tested-by: Ira Weiny Reviewed-by: Ira Weiny Signed-off-by: Jason Gunthorpe Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/ulp/ipoib/ipoib_cm.c | 2 ++ 1 file changed, 2 insertions(+) --- a/drivers/infiniband/ulp/ipoib/ipoib_cm.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_cm.c @@ -1028,12 +1028,14 @@ static int ipoib_cm_rep_handler(struct i skb_queue_head_init(&skqueue); + netif_tx_lock_bh(p->dev); spin_lock_irq(&priv->lock); set_bit(IPOIB_FLAG_OPER_UP, &p->flags); if (p->neigh) while ((skb = __skb_dequeue(&p->neigh->queue))) __skb_queue_tail(&skqueue, skb); spin_unlock_irq(&priv->lock); + netif_tx_unlock_bh(p->dev); while ((skb = __skb_dequeue(&skqueue))) { skb->dev = p->dev;