Received: by 10.223.176.5 with SMTP id f5csp992745wra; Fri, 2 Feb 2018 09:22:30 -0800 (PST) X-Google-Smtp-Source: AH8x226pINSNBFFRg9/HUPlV1rOmbEOPEphz9OTVbAOSY6+GvtvAdtyA327JJDOWw8rPWWYZmgCK X-Received: by 10.101.101.26 with SMTP id x26mr8515677pgv.149.1517592149950; Fri, 02 Feb 2018 09:22:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517592149; cv=none; d=google.com; s=arc-20160816; b=uqG9xtZDN11T+QyoqxcVVqupGCEoxsOv5ik2/y1CCemn0RSic+bFGhj3WbwY/Vcf67 JmusxiVm/8JTV71yNCppLnXK13xVsUFbnwMxpJGlkIpT1MJBwnKx8FTr6LpWnqxMxzPV Y4jGJyrJp/q6Ref7hkCxkwyNBQcLx5DGAMy5rgacvnSaAuXhc030X5k1X0Tp8RaxFFZm WYueWfepBXCNavwyc1cslbvGqSR+vIALSniNt4Fm0G9pXBCtuGee3yx0MVZnzKidjffe HPMp/4YZOTYMurqHLW/pPeC1qFU8nmvy6LS3dlN9brov88WdK7ceRpMmWUTYiKHNf5fx /pxg== 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=KYg5x2P/Em/pIXGHQ/z0i/M6A2Au/UV5nB+U/87S1xc=; b=sgUKUmmSbj6/UAZT3GV+tM2rt11GqnjdUN8JFz4qrBKZTb+rSaSTTXJ+OvvfdKbVOH 8v1ljhAAPXoISX9Z2DMMSVBEH0LYfl0YYz4OpPv5R8lX8q9BSBrSQNV4T554V8JWIdix +2MCvDyVqjWuziFNxZXHuZbm5zAbdn8eBos+NwQ9cNWQoGypLcotUJHj18yYMsNQ0fhV 1JQT/rAz+9N2lGHBvec2A30S9tDiF1HKltBdXTiz9nU5nu/hpVwnCKNlTjFlItYtrYAU WogERjWSLmHu4NGqHOAP/FcWgUmSlN/xiz4EaSamQNLHPAgNLAkUWfE6EFwSu389AhE6 FgeA== 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 p9-v6si277077pls.317.2018.02.02.09.22.14; Fri, 02 Feb 2018 09:22:29 -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; 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 S1752890AbeBBRVG (ORCPT + 99 others); Fri, 2 Feb 2018 12:21:06 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:39210 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752803AbeBBRNE (ORCPT ); Fri, 2 Feb 2018 12:13:04 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id EB194F21; Fri, 2 Feb 2018 17:13:03 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Eremin , Andreas Dilger Subject: [PATCH 4.14 129/156] staging: lustre: separate a connection destroy from free struct kib_conn Date: Fri, 2 Feb 2018 17:58:30 +0100 Message-Id: <20180202140846.210308851@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140840.242829545@linuxfoundation.org> References: <20180202140840.242829545@linuxfoundation.org> User-Agent: quilt/0.65 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.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Dmitry Eremin commit 9b046013e5837f8a58453d1e9f8e01d03adb7fe7 upstream. The logic of the original commit 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") was assumed conditional free of struct kib_conn if the second argument free_conn in function kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) is true. But this hunk of code was dropped from original commit. As result the logic works wrong and current code use struct kib_conn after free. > drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c > 3317 kiblnd_destroy_conn(conn, !peer); > ^^^^ Freed always (but should be conditionally) > 3318 > 3319 spin_lock_irqsave(lock, flags); > 3320 if (!peer) > 3321 continue; > 3322 > 3323 conn->ibc_peer = peer; > ^^^^^^^^^^^^^^ Use after free > 3324 if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE) > 3325 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ Use after free > 3326 &kiblnd_data.kib_reconn_list); > 3327 else > 3328 list_add_tail(&conn->ibc_list, > ^^^^^^^^^^^^^^ Use after free > 3329 &kiblnd_data.kib_reconn_wait); To avoid confusion this fix moved the freeing a struct kib_conn outside of the function kiblnd_destroy_conn() and free as it was intended in original commit. Fixes: 4d99b2581eff ("staging: lustre: avoid intensive reconnecting for ko2iblnd") Signed-off-by: Dmitry Eremin Reviewed-by: Andreas Dilger Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c | 7 +++---- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h | 2 +- drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c | 6 ++++-- 3 files changed, 8 insertions(+), 7 deletions(-) --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c @@ -825,14 +825,15 @@ struct kib_conn *kiblnd_create_conn(stru return conn; failed_2: - kiblnd_destroy_conn(conn, true); + kiblnd_destroy_conn(conn); + LIBCFS_FREE(conn, sizeof(*conn)); failed_1: LIBCFS_FREE(init_qp_attr, sizeof(*init_qp_attr)); failed_0: return NULL; } -void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn) +void kiblnd_destroy_conn(struct kib_conn *conn) { struct rdma_cm_id *cmid = conn->ibc_cmid; struct kib_peer *peer = conn->ibc_peer; @@ -895,8 +896,6 @@ void kiblnd_destroy_conn(struct kib_conn rdma_destroy_id(cmid); atomic_dec(&net->ibn_nconns); } - - LIBCFS_FREE(conn, sizeof(*conn)); } int kiblnd_close_peer_conns_locked(struct kib_peer *peer, int why) --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.h @@ -1015,7 +1015,7 @@ int kiblnd_close_peer_conns_locked(stru struct kib_conn *kiblnd_create_conn(struct kib_peer *peer, struct rdma_cm_id *cmid, int state, int version); -void kiblnd_destroy_conn(struct kib_conn *conn, bool free_conn); +void kiblnd_destroy_conn(struct kib_conn *conn); void kiblnd_close_conn(struct kib_conn *conn, int error); void kiblnd_close_conn_locked(struct kib_conn *conn, int error); --- a/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c +++ b/drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c @@ -3313,11 +3313,13 @@ kiblnd_connd(void *arg) spin_unlock_irqrestore(lock, flags); dropped_lock = 1; - kiblnd_destroy_conn(conn, !peer); + kiblnd_destroy_conn(conn); spin_lock_irqsave(lock, flags); - if (!peer) + if (!peer) { + kfree(conn); continue; + } conn->ibc_peer = peer; if (peer->ibp_reconnected < KIB_RECONN_HIGH_RACE)