Received: by 10.213.65.68 with SMTP id h4csp239453imn; Fri, 23 Mar 2018 03:40:02 -0700 (PDT) X-Google-Smtp-Source: AG47ELutLupzURMD/rZuiv9HwXoHurmZbq1YXUiSjcqitZsT3HoxJ6ha7kTNcX3CRlLdBl8mafaF X-Received: by 10.99.111.140 with SMTP id k134mr20911430pgc.11.1521801602214; Fri, 23 Mar 2018 03:40:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521801602; cv=none; d=google.com; s=arc-20160816; b=RaJalWV7PrhJuYJaPF61p4fjayST80qJPH8mixdGMyi/h0PciaXvkvfAjA8GMI3ECr pLWQfFiKdUir4oM3yFonWZ76yzH5Nu7ljyqwIdY/iqH40Eh9MqekcsxiQSOlnkT/UMVk x/eflVtjqFYSfSrgpAWu4jrpOiiFhV1dojRTCjCvioYNLZwICF/vkjKnCcvDVLX12lrW QSjU/Qs+q2YhNMGdgq1n3kxgWfVPin095dn8WeC8B/+AieOJoD0O9jGbgOpdsub+lz9s HjKLpDOxARr0V1CCSXdYE6oGre5Z3bZ9fNGp3MImelOIcrKg2RLdpLJsr3QblsGhrEya /A7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=kgyQB6lDAME4hQk8bGzUI+4duTLp8UC/11pkI4f+Z3I=; b=NMVc8z2U/XWpwUwFnxdIBmMcJ0TL5bj12zWjIsXUSJnsncbvnOs8RSOUZMytIRXkNE n88e6TEHeSv4TYsu7eOYnpZu1DGRmlYGGA8fM3GxylkGpG0yq4iJCY3m7OK2/I/4v0Zt cXDyNQun99U30Bn1flKaQTilgoAjvmOLvlUc1TxJVt1pFSD0NZcu9ycRPE11HKdSAHdi auZfW1HgVpdF/KdainayvsYZsA1Dzb2+8lyguSyN5qxaF1hzQfcy++HcpJMZtfbvB8gO y1QhDIUxy/Ob9jiYpUTana3Hyj8eBXim7yxopOvCIz7vqxv6Vw8tUki0ZnI0UoZi3UOJ BV2w== 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 n1-v6si8494188pld.238.2018.03.23.03.39.47; Fri, 23 Mar 2018 03:40:02 -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 S933754AbeCWKRH (ORCPT + 99 others); Fri, 23 Mar 2018 06:17:07 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46984 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933726AbeCWKRD (ORCPT ); Fri, 23 Mar 2018 06:17:03 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 62193E4F; Fri, 23 Mar 2018 10:17:02 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Erez Shitrit , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH 4.4 83/97] IB/ipoib: Avoid memory leak if the SA returns a different DGID Date: Fri, 23 Mar 2018 10:55:10 +0100 Message-Id: <20180323094202.165259339@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094157.535925724@linuxfoundation.org> References: <20180323094157.535925724@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Erez Shitrit [ Upstream commit 439000892ee17a9c92f1e4297818790ef8bb4ced ] The ipoib path database is organized around DGIDs from the LLADDR, but the SA is free to return a different GID when asked for path. This causes a bug because the SA's modified DGID is copied into the database key, even though it is no longer the correct lookup key, causing a memory leak and other malfunctions. Ensure the database key does not change after the SA query completes. Demonstration of the bug is as follows ipoib wants to send to GID fe80:0000:0000:0000:0002:c903:00ef:5ee2, it creates new record in the DB with that gid as a key, and issues a new request to the SM. Now, the SM from some reason returns path-record with other SGID (for example, 2001:0000:0000:0000:0002:c903:00ef:5ee2 that contains the local subnet prefix) now ipoib will overwrite the current entry with the new one, and if new request to the original GID arrives ipoib will not find it in the DB (was overwritten) and will create new record that in its turn will also be overwritten by the response from the SM, and so on till the driver eats all the device memory. Signed-off-by: Erez Shitrit Signed-off-by: Leon Romanovsky Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/infiniband/ulp/ipoib/ipoib_main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) --- a/drivers/infiniband/ulp/ipoib/ipoib_main.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c @@ -724,6 +724,22 @@ static void path_rec_completion(int stat spin_lock_irqsave(&priv->lock, flags); if (!IS_ERR_OR_NULL(ah)) { + /* + * pathrec.dgid is used as the database key from the LLADDR, + * it must remain unchanged even if the SA returns a different + * GID to use in the AH. + */ + if (memcmp(pathrec->dgid.raw, path->pathrec.dgid.raw, + sizeof(union ib_gid))) { + ipoib_dbg( + priv, + "%s got PathRec for gid %pI6 while asked for %pI6\n", + dev->name, pathrec->dgid.raw, + path->pathrec.dgid.raw); + memcpy(pathrec->dgid.raw, path->pathrec.dgid.raw, + sizeof(union ib_gid)); + } + path->pathrec = *pathrec; old_ah = path->ah;