Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3052452ybi; Tue, 2 Jul 2019 01:11:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwMDjv6Nmo/stxDgI0qQEHS0bSs0LHkz1ElBczMmnhGF7CwfdtDqOWXX97G013EdpBGOJ4s X-Received: by 2002:a63:c60b:: with SMTP id w11mr28376998pgg.356.1562055098283; Tue, 02 Jul 2019 01:11:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562055098; cv=none; d=google.com; s=arc-20160816; b=X7nanbsZ2l8PYA/8jtnKhI7nG4o2rwt7HOmN3y43RPAa4dOWlS2J1iDwv7Q3yPp3b/ j++4SLvu+sk8PJdoNMmq8/dBzzTprUeOONepQmLQ5c4gRZ9z0zKBQ9RwF22CqYU0Egfx VtMC4b9TX3CAJFkVLjkzwXaT5M4eKeuovN1DHZRdkmquUNK/+bajvd7hhUR0DUZqrRQ7 awazOYkwxE+2aOklMX3UhS3qKFBBkTtqvx5X9GQXqdLo1zT5ENrZWq3+WLMnQWs00NyD tcJJ9E9fxkadI71Nw/r8ncry+F/BMDZEGteycDUN0eKKrQWV+Ap2fQe18uHY3p76gDaa B0dw== 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=OzKcv2qdawWmQvPwFNXXjVK3uKiUbLKG0J0bnl++jQTkuwRgBGwD6HuVGNfzCotyxB stb9FpwZYvxJ5pbNjEupBPa0NiUexAx6pElXQLXalcB8c8V1x1LyFLSYSCSMO2rTZbyl BYti4j5c5pOrW89tlVw4P3/0UEJTFiLSA3UmJ/UmxZ2jfBLZCk7K0FCmcSDIXSWIYVt9 9ZEYvlpVvf86hywwuEX23szAgOvShD/w3CvK5mfV+9ZBGgeJxDy7c5/l1+XF2RWEH80o rJLzuNXFyEt2DzPJ55weMb1bJv0UnElxrie2kOS9S76SKRWdfpUjfJ+gB6gchtSZRm92 6qYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="lg/UaI7o"; 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 f3si12238885pgs.135.2019.07.02.01.11.23; Tue, 02 Jul 2019 01:11:38 -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="lg/UaI7o"; 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 S1728385AbfGBIKR (ORCPT + 99 others); Tue, 2 Jul 2019 04:10:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:58556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727844AbfGBIKQ (ORCPT ); Tue, 2 Jul 2019 04:10:16 -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 C45952064A; Tue, 2 Jul 2019 08:10:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562055015; bh=JZqU6SbEu1G9od63bFj+X/LVOZySTd08frXzcfvf4FI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lg/UaI7oXrqm7D7XuaVfnF2lGYzWmqPV3eIs3q0nq4EFgJPzqKtcNk+bDjBM5ebKr w5yMzA6gCObSv3rHwlGfHumf5RaeHStiuJi97kYHuvl9wUA9J8VJGtiPqNwyy21+5Z KpMIaAV0wb9lYrKmk+gZJz18B7+dE/jlEzVNZwzQ= 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.14 21/43] scsi: vmw_pscsi: Fix use-after-free in pvscsi_queue_lck() Date: Tue, 2 Jul 2019 10:02:01 +0200 Message-Id: <20190702080124.907127322@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190702080123.904399496@linuxfoundation.org> References: <20190702080123.904399496@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; }