Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3054695ybi; Tue, 2 Jul 2019 01:14:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqwK4lDk0tH7fXR4fqKNuZ2qcqeXwGEuuqvhHwveIgF98Am1jIvRXiQseoy8YiCPVGxpS4kg X-Received: by 2002:a65:4b8b:: with SMTP id t11mr20919297pgq.130.1562055271892; Tue, 02 Jul 2019 01:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562055271; cv=none; d=google.com; s=arc-20160816; b=rwc/ffGUxIXG9Sjmu965U3BJtJJQhJEj8MhD8o0+JopGyM5vGq8I5CHXqpSfldCy1M H3WV3cED1ZvifIVWOptFcWQ/FIXc0mXg25tiRcwAtEYep3YTBugd7jX9Lqxyw0ZQPQcC 1lgT7msP1HaeVrnfoJNzX5ngrglmem91OOXutlq0NmCO0XL4vQaJwWXu8e+UzjljW+iq TT5H8Jz4aMBB7HK09V5VHc3Yx4zL+pCO2gT5Si6xDZu/8zN1Podc13yDoB9mj8GtSrWi fS89rDRu08re6DXKhi6+ej+c7kmNyoDTsktWci36/LUnWninfozIB9a28qJn/U3/Ex+z HP6Q== 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=6pKKhGqjRj914EY1KUGFNPAnavaQYJQlAHhMrQjmTi8=; b=nhm+sqsZSyEp2+WnkJTpJ30BNMb9SWN1Rx9aRGgHUHTK+E4cNMLg/crfizEkMSaP1s Md5TY2QnzWlurh4f/5srhAQgN0Ew2i4W51AxliZfZR7TiqNVwD0ggMbAXxptDAgCzFSV B0jHPG+bAr3BqPhfeOLMbzKKdNq+wgGS6jw8/XeNFi0PSrGl0KvOk+soi1K0M5b3QaXZ rCYtB9mOv8fQBxMnw8Pj7iOTB58VB/IHvdRHI6ksnRVm7pPtR3GUXTH2wCX7hhBNftDO QcWQBP1S75V4jxHZw0CStKK6+6reOOE9qDXrWk3RJ62wgNJ3yeHX2yuZqrr/IXe2XpwE w4LQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=OLyOaz1c; 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 a88si1719689pje.6.2019.07.02.01.14.16; Tue, 02 Jul 2019 01:14:31 -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=OLyOaz1c; 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 S1727470AbfGBIGq (ORCPT + 99 others); Tue, 2 Jul 2019 04:06:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:53580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727312AbfGBIGo (ORCPT ); Tue, 2 Jul 2019 04:06:44 -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 D1AA021841; Tue, 2 Jul 2019 08:06:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562054803; bh=JZqU6SbEu1G9od63bFj+X/LVOZySTd08frXzcfvf4FI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OLyOaz1cD6EwDAXKwK4WTnNRu59O2W6sMVnRsBfAyNb1xdsBHuEKR7kepUrO0VsH0 xwO4uby8YthkB+qhI3CK2dEci8tzxjk2Qkn0hgf2m7thcbtb1yijrRz8K4f7JjoBCZ +vllvZ9YZ9LhR4x4vmfP+4ypyO9nmcgSf5EK/yZU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , "Ewan D. Milne" , "Martin K. Petersen" Subject: [PATCH 4.19 40/72] scsi: vmw_pscsi: Fix use-after-free in pvscsi_queue_lck() Date: Tue, 2 Jul 2019 10:01:41 +0200 Message-Id: <20190702080126.741089345@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190702080124.564652899@linuxfoundation.org> References: <20190702080124.564652899@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: Jan Kara commit 240b4cc8fd5db138b675297d4226ec46594d9b3b upstream. Once we unlock adapter->hw_lock in pvscsi_queue_lck() nothing prevents just queued scsi_cmnd from completing and freeing the request. Thus cmd->cmnd[0] dereference can dereference already freed request leading to kernel crashes or other issues (which one of our customers observed). Store cmd->cmnd[0] in a local variable before unlocking adapter->hw_lock to fix the issue. CC: Signed-off-by: Jan Kara Reviewed-by: Ewan D. Milne Signed-off-by: Martin K. Petersen Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/vmw_pvscsi.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) --- a/drivers/scsi/vmw_pvscsi.c +++ b/drivers/scsi/vmw_pvscsi.c @@ -763,6 +763,7 @@ static int pvscsi_queue_lck(struct scsi_ struct pvscsi_adapter *adapter = shost_priv(host); struct pvscsi_ctx *ctx; unsigned long flags; + unsigned char op; spin_lock_irqsave(&adapter->hw_lock, flags); @@ -775,13 +776,14 @@ static int pvscsi_queue_lck(struct scsi_ } cmd->scsi_done = done; + op = cmd->cmnd[0]; dev_dbg(&cmd->device->sdev_gendev, - "queued cmd %p, ctx %p, op=%x\n", cmd, ctx, cmd->cmnd[0]); + "queued cmd %p, ctx %p, op=%x\n", cmd, ctx, op); spin_unlock_irqrestore(&adapter->hw_lock, flags); - pvscsi_kick_io(adapter, cmd->cmnd[0]); + pvscsi_kick_io(adapter, op); return 0; }