Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2809518pxu; Mon, 14 Dec 2020 11:22:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6szLCrCQ/1I119prW5rXaDWloQ87BHlIr6pppR98DufQ0ZFiqtQRCUnpzbogpl4Kc7RoY X-Received: by 2002:a17:906:3553:: with SMTP id s19mr23151271eja.95.1607973762812; Mon, 14 Dec 2020 11:22:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607973762; cv=none; d=google.com; s=arc-20160816; b=i5AkdVhqwXlT5Q8WAdK6P4Fz/lmmklZiXxOsZPRzuE4DbR+BCZzGGYXDK/RgMu+5f7 zSbgJ0y8Tjlta0AVK/0ZqkYveOfTUCE5a7TL+GVuz/bsLHpHXEsMQCV3jacjJzmseGel FNW+H8v2WNQCkuoW1c5c4is3G9FxjmICOd9a8hZroIaowDV07qK6oH8uxuoobl1SJv5e Gd9+D6PfwFM62+GUJD3Vx6YhUIKv5CaF1qXu17eqcFWpDy6XGkI7UqRJWz3l2K8441E6 X63V5rofTcsrrQmnRpnJH9vXvKhjPcQcHc/H9/VSaaR0XsbeFM1gVd6GJ3ocM1sNOZP8 EuJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=jUu/b3JhCdjomdLBGCwahiOQ6m0DrpxfmevpaM4cYMY=; b=NXnHD0uXONb61Yrr2Kx78D8H5gwCJ1nz4ZZKJ+E4v6uxTpy3T92Q/cmhzaMXEcCOnt LSwarWUrHGIFgmwMO3OwG9+rmJr8h2yk8WJ6rqN7VJbS7nQ3xxGXDcJvy07BVj2ZY3W0 DarybNFSUhB+TDbtVq/TR49fO0Eh/GH6+1h53BPh6Lg3G559FkiCubtYagdRGo77chMf UoLKypI3kc2z6wdJraEXEr5T63+EE2U6U7TeLVI3VCgny80eWrnTDWUQJ8v9oh0CyRt3 Rbl8tI1hGwqWjZfZXxOxhNxXHhXOFEL7zd+nwRAl2RAJ+x0d7QPtu8kW1HswYTDfMR5c dNUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j7si12059334ejm.496.2020.12.14.11.22.18; Mon, 14 Dec 2020 11:22:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502698AbgLNTJK (ORCPT + 99 others); Mon, 14 Dec 2020 14:09:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:47320 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2408584AbgLNRhL (ORCPT ); Mon, 14 Dec 2020 12:37:11 -0500 From: Greg Kroah-Hartman Authentication-Results: mail.kernel.org; dkim=permerror (bad message/signature format) To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sukadev Bhattiprolu , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.9 019/105] ibmvnic: track pending login Date: Mon, 14 Dec 2020 18:27:53 +0100 Message-Id: <20201214172556.196755366@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201214172555.280929671@linuxfoundation.org> References: <20201214172555.280929671@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sukadev Bhattiprolu [ Upstream commit 76cdc5c5d99ce4856ad0ac38facc33b52fa64f77 ] If after ibmvnic sends a LOGIN it gets a FAILOVER, it is possible that the worker thread will start reset process and free the login response buffer before it gets a (now stale) LOGIN_RSP. The ibmvnic tasklet will then try to access the login response buffer and crash. Have ibmvnic track pending logins and discard any stale login responses. Fixes: 032c5e82847a ("Driver for IBM System i/p VNIC protocol") Signed-off-by: Sukadev Bhattiprolu Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/ibm/ibmvnic.c | 17 +++++++++++++++++ drivers/net/ethernet/ibm/ibmvnic.h | 1 + 2 files changed, 18 insertions(+) diff --git a/drivers/net/ethernet/ibm/ibmvnic.c b/drivers/net/ethernet/ibm/ibmvnic.c index 006670f318bf1..9aa63b8b44368 100644 --- a/drivers/net/ethernet/ibm/ibmvnic.c +++ b/drivers/net/ethernet/ibm/ibmvnic.c @@ -3843,6 +3843,8 @@ static int send_login(struct ibmvnic_adapter *adapter) crq.login.cmd = LOGIN; crq.login.ioba = cpu_to_be32(buffer_token); crq.login.len = cpu_to_be32(buffer_size); + + adapter->login_pending = true; ibmvnic_send_crq(adapter, &crq); return 0; @@ -4374,6 +4376,15 @@ static int handle_login_rsp(union ibmvnic_crq *login_rsp_crq, struct ibmvnic_login_buffer *login = adapter->login_buf; int i; + /* CHECK: Test/set of login_pending does not need to be atomic + * because only ibmvnic_tasklet tests/clears this. + */ + if (!adapter->login_pending) { + netdev_warn(netdev, "Ignoring unexpected login response\n"); + return 0; + } + adapter->login_pending = false; + dma_unmap_single(dev, adapter->login_buf_token, adapter->login_buf_sz, DMA_TO_DEVICE); dma_unmap_single(dev, adapter->login_rsp_buf_token, @@ -4721,6 +4732,11 @@ static void ibmvnic_handle_crq(union ibmvnic_crq *crq, case IBMVNIC_CRQ_INIT: dev_info(dev, "Partner initialized\n"); adapter->from_passive_init = true; + /* Discard any stale login responses from prev reset. + * CHECK: should we clear even on INIT_COMPLETE? + */ + adapter->login_pending = false; + if (!completion_done(&adapter->init_done)) { complete(&adapter->init_done); adapter->init_done_rc = -EIO; @@ -5188,6 +5204,7 @@ static int ibmvnic_probe(struct vio_dev *dev, const struct vio_device_id *id) dev_set_drvdata(&dev->dev, netdev); adapter->vdev = dev; adapter->netdev = netdev; + adapter->login_pending = false; ether_addr_copy(adapter->mac_addr, mac_addr_p); ether_addr_copy(netdev->dev_addr, adapter->mac_addr); diff --git a/drivers/net/ethernet/ibm/ibmvnic.h b/drivers/net/ethernet/ibm/ibmvnic.h index 31d604fc7bde7..77f43cbdb6dc4 100644 --- a/drivers/net/ethernet/ibm/ibmvnic.h +++ b/drivers/net/ethernet/ibm/ibmvnic.h @@ -1084,6 +1084,7 @@ struct ibmvnic_adapter { struct delayed_work ibmvnic_delayed_reset; unsigned long resetting; bool napi_enabled, from_passive_init; + bool login_pending; bool failover_pending; bool force_reset_recovery; -- 2.27.0