Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2026794pxa; Mon, 24 Aug 2020 03:01:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw6pcTaHPhjwY7n2lVtv4HXkRg6avrOwxb4OLm+siJSQS5lraiREgQVBDEhJfW7vUsNZnvB X-Received: by 2002:a50:935a:: with SMTP id n26mr4639991eda.107.1598263278052; Mon, 24 Aug 2020 03:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598263278; cv=none; d=google.com; s=arc-20160816; b=M2udVgO94zBl9wUYn5FRh+pfMYHrQzT3kep3Ugdhmzouj2mPDbnw44bMsdzsfaTc35 aNaXw8kIFCDqXVE07ODTSLYeVX1JqQKVFTvEv5oM0y8BYTp4Q3QpOMDtE2TZCX0gjzGr WKXuqBff6Y+4AAJvnbK3dJg6Rvse9WxEOjLS01vfdAMa431gzyz1JLnHu2IXLJWxb9js taxxFZZ1pkl0y1KJ03gS4T3jAlTPwJJxN1n9LFgfdBqDeybV/BlRhc/giTxvoS2gkCsw 2yrjpga5ibzTP4fgiqbFS1+cltN4wwRq0jPdRrDHA3zHZHrQ8HA6r7lEYNvaohMUncz4 YdHg== 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=NJM+HlVQg1HUvlxkNMWWU7ipVIp8IhC4i/tI8m/sd1M=; b=GU/KtOymoOrDysnKi2iKRaSOfluLaiB4KaCy1210f7iSfm9qpi66OcEUcMzZRgpD22 q4JDJV/DbmGouM/CseIKTn3EUMJIZhchcX0axEFyjWoU2lBGCQEnRRkTdfJVvXNRGt3s pDP20JSOrkm5xEtjWdlSMelmsg4PTc3I/pj9OwcDc/a1xn43iJxsTNTKVJSdw+j9ghNA DxAdCd+Fu/I0OOzEddVeh1QXILBvTjl/JKSfanPlzrD/Zk5eFjqMc17pY8d5mr07O0XZ 0m/H990GbV6Dp7f8irlLrH4xW+brgHrBxNuCfFq+G4w4uROz4Z2f51IzMYC7aGa7ilKi VwHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=mxRoPf28; 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 24si8428301edv.581.2020.08.24.03.00.55; Mon, 24 Aug 2020 03:01:18 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=mxRoPf28; 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 S1728745AbgHXJ6j (ORCPT + 99 others); Mon, 24 Aug 2020 05:58:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:42470 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727877AbgHXIeO (ORCPT ); Mon, 24 Aug 2020 04:34:14 -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 AE8412075B; Mon, 24 Aug 2020 08:34:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598258054; bh=23KwCts+PGV0rIB3suns0YvB6DPtsruM+gXIK6wRK+w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mxRoPf28dh3vaP+k0hFTLhZor2eacnBQYbY0li0j0op77Ud62wTtWg/tAgu4JkY+3 kIWUP3ES+8FT09GJSXXZOSTyojUQkcXvRBHL57YTHKFz4TExeVr6eSZNy5IryBlYvo LR1/ZfSvKadMBIj5yED5TQDL0e6GlNzQtDhd9FwE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Julian Wiedmann , Steffen Maier , "Martin K. Petersen" Subject: [PATCH 5.8 028/148] scsi: zfcp: Fix use-after-free in request timeout handlers Date: Mon, 24 Aug 2020 10:28:46 +0200 Message-Id: <20200824082415.303467813@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200824082413.900489417@linuxfoundation.org> References: <20200824082413.900489417@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: Steffen Maier commit 2d9a2c5f581be3991ba67fa9e7497c711220ea8e upstream. Before v4.15 commit 75492a51568b ("s390/scsi: Convert timers to use timer_setup()"), we intentionally only passed zfcp_adapter as context argument to zfcp_fsf_request_timeout_handler(). Since we only trigger adapter recovery, it was unnecessary to sync against races between timeout and (late) completion. Likewise, we only passed zfcp_erp_action as context argument to zfcp_erp_timeout_handler(). Since we only wakeup an ERP action, it was unnecessary to sync against races between timeout and (late) completion. Meanwhile the timeout handlers get timer_list as context argument and do a timer-specific container-of to zfcp_fsf_req which can have been freed. Fix it by making sure that any request timeout handlers, that might just have started before del_timer(), are completed by using del_timer_sync() instead. This ensures the request free happens afterwards. Space time diagram of potential use-after-free: Basic idea is to have 2 or more pending requests whose timeouts run out at almost the same time. req 1 timeout ERP thread req 2 timeout ---------------- ---------------- --------------------------------------- zfcp_fsf_request_timeout_handler fsf_req = from_timer(fsf_req, t, timer) adapter = fsf_req->adapter zfcp_qdio_siosl(adapter) zfcp_erp_adapter_reopen(adapter,...) zfcp_erp_strategy ... zfcp_fsf_req_dismiss_all list_for_each_entry_safe zfcp_fsf_req_complete 1 del_timer 1 zfcp_fsf_req_free 1 zfcp_fsf_req_complete 2 zfcp_fsf_request_timeout_handler del_timer 2 fsf_req = from_timer(fsf_req, t, timer) zfcp_fsf_req_free 2 adapter = fsf_req->adapter ^^^^^^^ already freed Link: https://lore.kernel.org/r/20200813152856.50088-1-maier@linux.ibm.com Fixes: 75492a51568b ("s390/scsi: Convert timers to use timer_setup()") Cc: #4.15+ Suggested-by: Julian Wiedmann Reviewed-by: Julian Wiedmann Signed-off-by: Steffen Maier Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/s390/scsi/zfcp_fsf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/s390/scsi/zfcp_fsf.c +++ b/drivers/s390/scsi/zfcp_fsf.c @@ -434,7 +434,7 @@ static void zfcp_fsf_req_complete(struct return; } - del_timer(&req->timer); + del_timer_sync(&req->timer); zfcp_fsf_protstatus_eval(req); zfcp_fsf_fsfstatus_eval(req); req->handler(req); @@ -867,7 +867,7 @@ static int zfcp_fsf_req_send(struct zfcp req->qdio_req.qdio_outb_usage = atomic_read(&qdio->req_q_free); req->issued = get_tod_clock(); if (zfcp_qdio_send(qdio, &req->qdio_req)) { - del_timer(&req->timer); + del_timer_sync(&req->timer); /* lookup request again, list might have changed */ zfcp_reqlist_find_rm(adapter->req_list, req_id); zfcp_erp_adapter_reopen(adapter, 0, "fsrs__1");