Received: by 10.223.185.116 with SMTP id b49csp5962375wrg; Wed, 7 Mar 2018 22:44:51 -0800 (PST) X-Google-Smtp-Source: AG47ELt9w0dnUW8RmCBcjwIfx04UncRm3AYb43BUmzV5uFknbW1JmBPW0LAqOjlgqVmge05Mmhz9 X-Received: by 10.98.21.200 with SMTP id 191mr25067994pfv.166.1520491491583; Wed, 07 Mar 2018 22:44:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520491491; cv=none; d=google.com; s=arc-20160816; b=ii8oatVXSYqTX5yhMcBJzmvia7nW86Es/rzPSA27yspWsQassZ8Y6kOZbzT1IDo/M2 LLTXXfiLa5Gm2LWDDUh6lo1iQgD/x+rYt7NLeSozSa0sQYdO3y6Oy7JXIlYGWQcQX36D bIGawPMgEUmfX0PAP4iuM/j9CVdtPg8kB3or3v+3KQH496irzjuJ0JLcs9jG1HuWFc0s L3NWZvaLjM43GdMwhlZBwQxOKjaOtKWBWhQr0gCH8gqLsK5NZo8WqhSffwheouJrkp4n xwhkG03OUgm9FYHyYteqs7ZmzUbCphJhJZV/YK3YJm2pNPpBpVSXI/WqHtfVJYQmiZIv TzXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=ZDsPA8MFOqQMPTtrH+tyb6h1t34qhwuthoeUxMNNbcQ=; b=q57zmgI569c7UkYGyrunt44HEaQYvgCwA7IV9zEjuUz3HJ3NuFUk8cQTH4EYp473ja XudaFZM4ZT8f44m1SX1cKRv6VJVM3HFZ4Qzx0/HOMhKrQ7aPwIipWI3z62JGaRlKSO76 EDKU/pE2o8xzdVZrGAEYdUmMmUmF6Ot887eJPm25J1TGhu1SZxmmkrMaQAGF5SQV21Ql 6NGSGfLNxn9OpKSstF9OeAlMoyPfNwQ1jRg33OjdPTo9fbpT55FoRaoSJPjwRaVNEMYm M+uQ6Ug6LjtAp221gJRes2YD7FJlcRN+fMsD0jj0+1BDzJ7FQRtZADzvQoM411uGDjF9 l6HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=c95ui//S; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9si12708254pgc.628.2018.03.07.22.44.36; Wed, 07 Mar 2018 22:44:51 -0800 (PST) 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; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=c95ui//S; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935396AbeCHGng (ORCPT + 99 others); Thu, 8 Mar 2018 01:43:36 -0500 Received: from mail-sn1nam01on0102.outbound.protection.outlook.com ([104.47.32.102]:61147 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965225AbeCHE66 (ORCPT ); Wed, 7 Mar 2018 23:58:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ZDsPA8MFOqQMPTtrH+tyb6h1t34qhwuthoeUxMNNbcQ=; b=c95ui//SBLTMWeF44r2TpVwIOXPnKXYjJI/7g7GCn+dE9rbzhyUdMp6x2jysyo3ETBROAoILkHd8+4z5GkYxyPseNM2QG9sgEmW5w/4JkggNaotiH+KQUjVak3fPJoDXy6pY538sPuJRca3ICFWapJdOoHUf5pTIAsohSwbvK7s= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1015.namprd21.prod.outlook.com (52.132.133.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.588.3; Thu, 8 Mar 2018 04:58:55 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8063:c68a:b210:7446]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8063:c68a:b210:7446%2]) with mapi id 15.20.0588.008; Thu, 8 Mar 2018 04:58:55 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Erez Shitrit , Leon Romanovsky , Jason Gunthorpe , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 36/67] IB/ipoib: Avoid memory leak if the SA returns a different DGID Thread-Topic: [PATCH AUTOSEL for 4.14 36/67] IB/ipoib: Avoid memory leak if the SA returns a different DGID Thread-Index: AQHTtpoACoC/5KiOg0e+RWWe8okAZw== Date: Thu, 8 Mar 2018 04:57:47 +0000 Message-ID: <20180308045641.7814-36-alexander.levin@microsoft.com> References: <20180308045641.7814-1-alexander.levin@microsoft.com> In-Reply-To: <20180308045641.7814-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1015;7:VeL7jM7Yx/EGraKoTzxXVqdIvcRyDnxKmwO3yyF9s+Gi/lCDl3GMXUOrj8S/FUJy9DM8mMtTIieEbep9cEwlTEG7LNTIOrch9izxlJW5cc3APVuprjedksOwZdQp0tdkoZ3LXOJL8zXjLSEbnofxIQ0qK8ad5+sWLuZCeRr1iodQmRrlH2qgPGf0+svnS+hehdYbR08IXZ/oCgNyS+LxKEH2/qo8/2ZwVPHEuYEJ72aKOjlePadgnsNXQ1Hk23ca;20:iLGCJiY4wZep/QKWZRrKWg1yWhZT0NoVKw1lxJ0y3R0EgDCz06xkoz/jEkPTg6GrCqlar5X0M84uT4lWiqDhDRER2Qy17DhO47Ak2M3g6QVwXQks/ggzfGNtPVh3uCIO7LlMgIlnrgb0josGEtjDTsWQJ3RzXWrsYOKd4qjU1f8= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: b5488110-0aa0-4421-c322-08d584b14b8c x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1015; x-ms-traffictypediagnostic: DM5PR2101MB1015: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231220)(944501244)(52105095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041288)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB1015;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1015; x-forefront-prvs: 060503E79B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(396003)(366004)(39860400002)(39380400002)(346002)(189003)(199004)(6116002)(53936002)(1076002)(107886003)(3846002)(3660700001)(10090500001)(6666003)(2950100002)(2906002)(6512007)(99286004)(8936002)(6486002)(76176011)(6506007)(68736007)(59450400001)(316002)(110136005)(81156014)(81166006)(8676002)(54906003)(3280700002)(2900100001)(6436002)(97736004)(72206003)(25786009)(10290500003)(86612001)(4326008)(305945005)(7736002)(66066001)(22452003)(478600001)(5660300001)(86362001)(14454004)(106356001)(36756003)(102836004)(5250100002)(105586002)(26005)(2501003)(186003)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1015;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: JQ8X9Uzp39jiD5oIu1P7dWeRRGvmVfaDsgqen09ErqXqYKuMJowwsRJ9JpJFbFU7+/Rj+FKGBAE0UFTonFVt4HoQfbIumJf2ujitGTviS4+31lovSDZn8Mg+W8g1/RMDm+K5yoqVkXf1BNC39xnVxYKjBr8x8pTwzNwkKlAyURPHupqwHCfWpX+6vb6tEltQdZhFykFh2zpSe0uBkkBHZSlwFXBg4/48vqnQSBvLgtgOMrGdBdyKgGiFUzVgOvlWe4hS49Qw4LcVLj2Ll/gp94YWhXNfYT3kMoiQ5QLlnPdsd3vPdXHHfD3QEeD9IDzYrnkSZsk87V9NHkfTvv0WoQ== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: b5488110-0aa0-4421-c322-08d584b14b8c X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2018 04:57:47.3198 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1015 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/infiniband/ulp/ipoib/ipoib_main.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/infiniband/ulp/ipoib/ipoib_main.c b/drivers/infiniband= /ulp/ipoib/ipoib_main.c index dcc77014018d..a47a7944d650 100644 --- a/drivers/infiniband/ulp/ipoib/ipoib_main.c +++ b/drivers/infiniband/ulp/ipoib/ipoib_main.c @@ -776,6 +776,22 @@ static void path_rec_completion(int status, spin_lock_irqsave(&priv->lock, flags); =20 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 =3D *pathrec; =20 old_ah =3D path->ah; --=20 2.14.1