Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp10402743ybi; Wed, 24 Jul 2019 22:34:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzN4T2wwbu+mXLlGg9ukYYs5DE95KU5W4nrezcJgfODXvB2uhDcqrZ8MYbpYyWd6UibEdjr X-Received: by 2002:aa7:8711:: with SMTP id b17mr15097886pfo.234.1564032861346; Wed, 24 Jul 2019 22:34:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564032861; cv=none; d=google.com; s=arc-20160816; b=Vg/zGspiOhZs+CId39SmhTX12q3iR+TvHL6SWct5UHieHRSvqmaKPWUeXJP4GIjR8S w7MnT9zZzKOi53lVdI9I3icpH9HrLdq98XJYRenIUd/pFAkVo6qM2d+/9VdtUlnHLjJx Z/BRKabuIkCAbT9RF087FkbWfjzMiJMcF4nJD0+vz1VQg3ZVB2q1M5fIkuuPADmAXnjK SqeGm+AXNs83QaGMv9dqpV4PH52y8TL0Z3/9D2FIZA4cDHR3N1iiMmeO5j0fF0k4BJsx eO/VHSmcobA0+H0dELieXy5xbW6eoB3aPReHCMiGhfCMBkDPxcGo70poVmsEs5KQ4xAC zC4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=j1fOLNWFjxNNEoeX0CmGMTUgLU+ZUrOrFhCFwrSzYGU=; b=YqG4t1GNbnyLW+YgaiSmH7AFOMo8+6zN07KHH/guN844KCV6W2eSi5hj+/E9PMoqV2 Siqt4oSE+5IYS9PnUojMTKsdYlvdHfNcgqxykDsNga7o2dvNx0kMgzthHgcexaqp9kRf OPuQ5cirEdPPJW5nx6XvlUqY98EydjcgqY17ydIOu93gqDQgCFz82e2qsONUx9W5xiR0 8O2iDrYnmO+ja2O6qUAnn1A6To47tBTsa/ProFE7FLAFpS9buZOxXYv57Yb3SML1UIrx hc9+ZuUWrADpe0DdqxRej2uXdDeG/0DmIYUifOFbXZRcB4qbPA7MD8KTYnv+N9On5t1t efxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1GHI14Uh; 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 l186si17940846pgd.455.2019.07.24.22.33.31; Wed, 24 Jul 2019 22:34:21 -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; dkim=pass header.i=@kernel.org header.s=default header.b=1GHI14Uh; 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 S2404365AbfGXTyb (ORCPT + 99 others); Wed, 24 Jul 2019 15:54:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:37446 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404350AbfGXTy3 (ORCPT ); Wed, 24 Jul 2019 15:54:29 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 009582147A; Wed, 24 Jul 2019 19:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1563998068; bh=lednPcTVqVhtLN1g1Rjm601tmhqmTC7Osfas59sjvOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1GHI14UhJxtnfyN8YzyRyfz+x0zMT4cGndgohzlCYehuofDG1ZyN54zKCDHDEPLlg dCRHS5TdaUkCbN9+1Nv6qToF7mtbTbyo9NCXhUEjLsoO1Qqv37/G4/GmFukP1y43ID mLpzisyRoux/HEfVjQpnbABB69Y7cZanonKjpAJk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Benjamin Block , Steffen Maier , Jens Remus , "Martin K. Petersen" Subject: [PATCH 5.1 235/371] scsi: zfcp: fix request object use-after-free in send path causing wrong traces Date: Wed, 24 Jul 2019 21:19:47 +0200 Message-Id: <20190724191742.246326310@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190724191724.382593077@linuxfoundation.org> References: <20190724191724.382593077@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Block commit 106d45f350c7cac876844dc685845cba4ffdb70b upstream. When tracing instances where we open and close WKA ports, we also pass the request-ID of the respective FSF command. But after successfully sending the FSF command we must not use the request-object anymore, as this might result in an use-after-free (see "zfcp: fix request object use-after-free in send path causing seqno errors" ). To fix this add a new variable that caches the request-ID before sending the request. This won't change during the hand-off to the FCP channel, and so it's safe to trace this cached request-ID later, instead of using the request object. Signed-off-by: Benjamin Block Fixes: d27a7cb91960 ("zfcp: trace on request for open and close of WKA port") Cc: #2.6.38+ Reviewed-by: Steffen Maier Reviewed-by: Jens Remus Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/s390/scsi/zfcp_fsf.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/drivers/s390/scsi/zfcp_fsf.c +++ b/drivers/s390/scsi/zfcp_fsf.c @@ -1627,6 +1627,7 @@ int zfcp_fsf_open_wka_port(struct zfcp_f { struct zfcp_qdio *qdio = wka_port->adapter->qdio; struct zfcp_fsf_req *req; + unsigned long req_id = 0; int retval = -EIO; spin_lock_irq(&qdio->req_q_lock); @@ -1649,6 +1650,8 @@ int zfcp_fsf_open_wka_port(struct zfcp_f hton24(req->qtcb->bottom.support.d_id, wka_port->d_id); req->data = wka_port; + req_id = req->req_id; + zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); retval = zfcp_fsf_req_send(req); if (retval) @@ -1657,7 +1660,7 @@ int zfcp_fsf_open_wka_port(struct zfcp_f out: spin_unlock_irq(&qdio->req_q_lock); if (!retval) - zfcp_dbf_rec_run_wka("fsowp_1", wka_port, req->req_id); + zfcp_dbf_rec_run_wka("fsowp_1", wka_port, req_id); return retval; } @@ -1683,6 +1686,7 @@ int zfcp_fsf_close_wka_port(struct zfcp_ { struct zfcp_qdio *qdio = wka_port->adapter->qdio; struct zfcp_fsf_req *req; + unsigned long req_id = 0; int retval = -EIO; spin_lock_irq(&qdio->req_q_lock); @@ -1705,6 +1709,8 @@ int zfcp_fsf_close_wka_port(struct zfcp_ req->data = wka_port; req->qtcb->header.port_handle = wka_port->handle; + req_id = req->req_id; + zfcp_fsf_start_timer(req, ZFCP_FSF_REQUEST_TIMEOUT); retval = zfcp_fsf_req_send(req); if (retval) @@ -1713,7 +1719,7 @@ int zfcp_fsf_close_wka_port(struct zfcp_ out: spin_unlock_irq(&qdio->req_q_lock); if (!retval) - zfcp_dbf_rec_run_wka("fscwp_1", wka_port, req->req_id); + zfcp_dbf_rec_run_wka("fscwp_1", wka_port, req_id); return retval; }