Received: by 10.213.65.68 with SMTP id h4csp258037imn; Fri, 23 Mar 2018 04:06:24 -0700 (PDT) X-Google-Smtp-Source: AG47ELsuBvmkk9X20XazZIgC0IyIX+AbEpsgzqKfmiv7FvaMy7ajMUm1RUpQJ8MzTzpNoF0qXhsG X-Received: by 10.98.182.4 with SMTP id j4mr632107pff.207.1521803184797; Fri, 23 Mar 2018 04:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521803184; cv=none; d=google.com; s=arc-20160816; b=A/gkPEcW45o3eoUSG19jQ9okZ4PhwHL+SrfiYbJdPwhudXHbf0TDAMFYfs6Bz2RVyo BvKWH2mOJZEVIBmL/vNWM5gLbhtYGoJ/MnFM6uOTDB078vdKFOXdC8sp2bP5cPFsEcIJ /Ffp+trrmv1ctKXvfZQcqX9vRbuiHGr8Uvva72rlyoYteUnW9rp1we+I5SWh4rkUOug5 4SBcs/ibTnWzUtmDDOZtJ7rz7RHOxSzRUOxZLXuqBWSGvKZd49ILdDQijQgrMbTALl9N qEbdoWtLKMECc502mZCU8t0kaFGkQpSVraGupcm6VPvfaXXB59e3j+T09eMQJ5KQfqWX b7vA== 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=GF0SbPhDn7CxE5eUu4ZRHRkJWqAHE3jtlWgT77P4aE8=; b=ReVWGWe2lf6j0Hl5r9l43fQjJ0A+aU0kNFSEvnZPotQ2Op0oQH9RglOo5Aqshxqn5M 6LIiJ4uM901TPl3M8aKG5yQvylTiHUwha5/IUgdzfT1cbat8A5K9F8azX/37z7B11WUA h2I2Y95l3NMxxUdO54dlWo1WfymFvuTkdD8BFjhpaXVwT91RO4D6iVE0JscLWPZibfGO Nl3zrj/VLT7QPwAxMCDWt6DlENl2z4FsIU39Cq8/iOsrpeuPpMRmv7MLTYzLmeqZO4T1 3mTytzp5+FOBNpqoyCcx0F+91A2e2pMBkmxg+DaznBOL4MezGZKTZ6eGJoA1CGWBHwBK i1+A== 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 e20si6433415pfi.359.2018.03.23.04.06.10; Fri, 23 Mar 2018 04:06:24 -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 S1755779AbeCWLFC (ORCPT + 99 others); Fri, 23 Mar 2018 07:05:02 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:44346 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933181AbeCWKMZ (ORCPT ); Fri, 23 Mar 2018 06:12:25 -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 C5815115A; Fri, 23 Mar 2018 10:12:24 +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.9 152/177] IB/ipoib: Avoid memory leak if the SA returns a different DGID Date: Fri, 23 Mar 2018 10:54:40 +0100 Message-Id: <20180323094211.896399808@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323094205.090519271@linuxfoundation.org> References: <20180323094205.090519271@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.9-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 @@ -799,6 +799,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;