Received: by 10.213.65.68 with SMTP id h4csp305372imn; Fri, 23 Mar 2018 05:10:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELt4sVyTy9jWKEgxoWCkF3KTh7aSCuZxokBBykEvRv5Ecb3dxxokj6oUh/OaFhnJskhofXm4 X-Received: by 2002:a17:902:6b41:: with SMTP id g1-v6mr4136402plt.167.1521807044164; Fri, 23 Mar 2018 05:10:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521807044; cv=none; d=google.com; s=arc-20160816; b=UYc28shmruox1kATXiighVwLKG1fuBoNVjMhAW7qZIQuS8tdLvuo04BjzHxMmBD46R 8XeI1K9GEJgQGLfWMRTp/nXxr/laiXcdu+Sg9UeGc0LnMLFUjJ0bY1NT90oA43lv4WEE 5E4+swFryCtV4WWuDkhmLJ2KT78Kj3XELJDkbV1XKYGrJow5vTMPvqgZA+FGXOIGKEUG XVkzCEcrT2iItucG+ib+0Iglo80KR4ezksPxQjiq7frbrt8z/xl0qOfp6wiBUAEG4xbk 0qR+/harE9jR4Cds0Jq//DF73i+F/MGJYyGYwpKvq1HRz2CaWE9CIQqxDjr1j8IHyVaZ lC3g== 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=RMOCEXU5XuVN36bYQS60nPGVE9BSWc0gZ/LEJFPJQf4=; b=anfLgyxwqi86JZR4dB9q8puamTYEW4VMLiHTD1GOerkgAwTOTRqaBLxH10lT+d6ysA c7fkvL/zd0OITUJZNrnOFnFfJmRzrKbKFAb8GFcsFyhE4/fIf6FlkvDJEA7Ts2K4w6Oj PxB/sH29xI1tzMVdkF7oxDTfBrtayJ0SqvEHegkmaLln86uRcnmKwCoPbD0AFEMhNQTw nxeyGpJlfPwZ6OwsItz3kvRhfgg+xNhATzZ0SVtJHLwsQlaF/Edq6rxZTNeRHgSevgxR 8huAeecarQ3RbiLYESxcDzUxlXnQacH+VGSNnNRgMWl/XrXvoc7gxON3dTAjl3lvkUM5 gL1g== 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 q12-v6si7636693plk.559.2018.03.23.05.10.29; Fri, 23 Mar 2018 05:10:44 -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 S1753292AbeCWMJm (ORCPT + 99 others); Fri, 23 Mar 2018 08:09:42 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35620 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753049AbeCWJ6O (ORCPT ); Fri, 23 Mar 2018 05:58:14 -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 9A5F81253; Fri, 23 Mar 2018 09:58:13 +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.15 39/84] IB/ipoib: Avoid memory leak if the SA returns a different DGID Date: Fri, 23 Mar 2018 10:53:53 +0100 Message-Id: <20180323095417.869947753@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180323095411.913234798@linuxfoundation.org> References: <20180323095411.913234798@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.15-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 @@ -775,6 +775,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;