Received: by 10.213.65.68 with SMTP id h4csp229887imn; Fri, 23 Mar 2018 03:25:59 -0700 (PDT) X-Google-Smtp-Source: AG47ELswvNsar7YK5Qm2fYlTYaK7rnPZNf58Csvfm26p2FSRtKMGXKMM3YdNy83b+Z+LgTR9fiSJ X-Received: by 10.98.147.27 with SMTP id b27mr23656142pfe.145.1521800759889; Fri, 23 Mar 2018 03:25:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521800759; cv=none; d=google.com; s=arc-20160816; b=fs8935Zr3iy98iehnW+Sqhs3sfofHOw96wr+fgzmKH1/uC8N/c7LI77qlG3KbOBAu8 6P4jmAhxPrb0m2S8vIIinLhr4WLHcobVwuempNhlWXtBlVy7L23wW5WtoQ/eIAFGAzw3 HDBKgBpyIY/xB98l7a5iAkp59jjwtH3e6Wa6ig5aw0fae5ev0c14ge2OWnfEp352cvug ONxqnl5GvvSVZ8jSKOs5Ut8JmAu2dCrJDDe1hgenu2vd/QTaoj20kQjYY4XIi+hhcRUN krK8Uj9SS4AX3p0kuGEmRxZgfXNzVEtopBj7or8l/+c1kCqcKrxeuK9WTC/36JW3qSQm Y7dg== 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=u38D1Q1/OaZCSbWSFtTuLI1BVKhqK9/10mc4VuVuB6E=; b=Sdwlz5xSsXsOhvfGGyWu4c2RbkaaTx0H4ddnHZAiZxfABublc/3VCsCNM3L+MdQweA CAN8yNtmNLUUa7Ttacjgt/pNnm4M4V+z16RODNYwqpWcTsfle0aS/rpHzDN+Eg1z2n73 wwO/g1icRnvYHhOkO7sBG5LscuJj7wHPvrMMLQjoefQHRWs68oUQEv9pPDH1Z5CZV1J+ yjlSUNZ/Yev5ZtJcoMIsprIA6lcga8pd5jhutP/PUt0wmKAclN0lZvH0o+x8iLFjZoW4 6GADgdrgcc3SDmsMZPfctpoe8YsMYp5yeTKcbXdhB1BtpUDrEitmrZrQ4r9GrUlur3Oj nPMw== 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 h68si3802846pfc.86.2018.03.23.03.25.44; Fri, 23 Mar 2018 03:25:59 -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 S1753351AbeCWKXt (ORCPT + 99 others); Fri, 23 Mar 2018 06:23:49 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:48314 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934088AbeCWKUB (ORCPT ); Fri, 23 Mar 2018 06:20:01 -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 CA6B2FCA; Fri, 23 Mar 2018 10:20:00 +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 3.18 41/47] IB/ipoib: Avoid memory leak if the SA returns a different DGID Date: Fri, 23 Mar 2018 10:55:32 +0100 Message-Id: <20180323094249.870367274@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094248.117679641@linuxfoundation.org> References: <20180323094248.117679641@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 3.18-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 @@ -488,6 +488,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;