Received: by 10.223.176.5 with SMTP id f5csp980651wra; Fri, 2 Feb 2018 09:11:52 -0800 (PST) X-Google-Smtp-Source: AH8x2262e2ygb7RfX5WThrs/STjY0TdVdJd/zWNNnzOU3PPf33hlhvz7I3df0Q0nfl4bNA6GLnTD X-Received: by 2002:a17:902:7008:: with SMTP id y8-v6mr4863902plk.358.1517591512157; Fri, 02 Feb 2018 09:11:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517591512; cv=none; d=google.com; s=arc-20160816; b=zohGuX///mjBiPo/8St2Ozz4VYa/80xpSHHDWlAtJNZlW5ouopzjLl7MkK+b442JEJ i9ukqBG0ZaYbCW77AqjTB6V49kD9/HY9GAkjkdJN6qri+RsYwHl6YZZpo3koamtu+SA3 9VisUlzvtMjPIsBTabiTacgXVZTZaokmIignhGnAZHWVJsotTZxB4gLvmEcwQTtAOyo6 DnjjJ87mr2PSbDBWqlhOWPoyjx8RIwPxzsK4h5L2e1FLBa6b1lIB99mR3kwOobm2R5sO u6e6lCQZeORk+fZw/KlHJw0YMSrymp5UoZ1hrlBf4HSZT/birP6MsxBDb/uEIL5HZZY4 H63g== 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=l9BXXbl92NZAB8azifWfuj9hQ6RThW4ISjeNIDPUhkw=; b=XP9n9c0a0LUwAdylzQCRRhXho48OeI1LYKjX+OxftAjOIvQieQYXCz/X2m0oDA0uFP x5vn41NhErVGdwgWJD5CSPQz9hYJ1OJ8OVgVmz0A7DrWSfD2Qwh7XwBNrqXjn/D+PPO2 wVcT9DbNGPTmB84o/jKM748HsKc407veWlsJNcoFxRzE1p1Q0U9ZYB9QWN5bOJvnLywn TFiIcVs6mj/WoB2s7JtngMAQHMj/jOeIn5OxQa9vVcAhjDqSloKYwFKs9mvl+m+1pkVW j073TGAm3uyO1SXcYovjhj7s05K0r00KuSJiEXkAU6Cep6cDEjfygMRJAdSEHSbwiAHx +vWA== 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 o15si1708188pgc.48.2018.02.02.09.11.37; Fri, 02 Feb 2018 09:11:52 -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 S1753364AbeBBRLJ (ORCPT + 99 others); Fri, 2 Feb 2018 12:11:09 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:36662 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753028AbeBBRF6 (ORCPT ); Fri, 2 Feb 2018 12:05:58 -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 0B300E3B; Fri, 2 Feb 2018 17:05:56 +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.9 71/86] staging: lustre: separate a connection destroy from free struct kib_conn Date: Fri, 2 Feb 2018 17:58:31 +0100 Message-Id: <20180202140829.222638408@linuxfoundation.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180202140822.679101338@linuxfoundation.org> References: <20180202140822.679101338@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.9-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 @@ -824,14 +824,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; @@ -894,8 +895,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 @@ -1018,7 +1018,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 @@ -3323,11 +3323,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)