Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp1194203ybn; Wed, 2 Oct 2019 12:14:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJTcdWSUaQWPNjXlMwz+KsY06f1bwOzzyfU/eYkeauaV14OdUNWcz6IjsxxzuFx739p3NG X-Received: by 2002:a17:906:1394:: with SMTP id f20mr4640642ejc.274.1570043679756; Wed, 02 Oct 2019 12:14:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570043679; cv=none; d=google.com; s=arc-20160816; b=ZKXkCHFySCkuIxd0AvpmXK4ZAQGOc97xRpQCNYxOSig7mV/UKC7wpC1HmxbLiJ0ekR uTVz42+xt5m2XM9KQrOMGHWJi2r0//0pBnrrCKQtoMj1nRahKX7FPEIkzZlgjuFqP5JR kyQ+pbDx8G2kg0P7zccFQi/re5WYdXaFWsMttUavD/O4tY68/nSqR9hpwrJj131RB2XK MGfMNYEf2SSrUB4XK2JykUiXm2AGsmx7CjxGpICExHyvnQOGoS0Mx+aXRB/4fS3ldKiw +XMrytCB852V3J0Qht27v8/PqaT55oAUcQlP04NgzEJrzQCwN8Eoqar6hTDG9UM6q33a efyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=TJo035aXDJulPEIOQYw5p3kJcjVeJoJmu6C5zKyfDtw=; b=xOWspmkJRCdm8PmesAHsvXTMdOhp/KrgI9vll+1oHy4tqhGma5vit70Fv5MG3ZGaLQ bDT8j0hDf9NTHn1zJncfZ7p6OX0b2p9r6vlO70qz5tP3DCx7Q1sRPF3gyEduN14c3tWL 9oqUh4NkbYOQFPONtTxI3OgGUBp9atg2+h+BgOO8RpdE1sWwhrLQM1deF2byMrCMe0c7 C2q0GeSBRas+n3izyHjzv6crvvjcMxwoIHomDCZNs9CuM/u2NFmwvO7MokBlScVDVKXe iHbTbslVxTWIdBsYOypf51lI7FGsAZO3tW5xakEIOvNPUo/QblWLJptQto76Cq9sPkCj gW7Q== ARC-Authentication-Results: i=1; mx.google.com; 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 rh23si20164ejb.75.2019.10.02.12.14.15; Wed, 02 Oct 2019 12:14:39 -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; 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 S1729926AbfJBTKx (ORCPT + 99 others); Wed, 2 Oct 2019 15:10:53 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35772 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729296AbfJBTIQ (ORCPT ); Wed, 2 Oct 2019 15:08:16 -0400 Received: from [192.168.4.242] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iFjyv-00036L-1e; Wed, 02 Oct 2019 20:08:13 +0100 Received: from ben by deadeye with local (Exim 4.92.1) (envelope-from ) id 1iFjyp-0003fj-Rj; Wed, 02 Oct 2019 20:08:07 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Jan Kara" , "Ewan D. Milne" , "Martin K. Petersen" Date: Wed, 02 Oct 2019 20:06:51 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 73/87] scsi: vmw_pscsi: Fix use-after-free in pvscsi_queue_lck() In-Reply-To: X-SA-Exim-Connect-IP: 192.168.4.242 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.75-rc1 review patch. If anyone has any objections, please let me know. ------------------ 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. Signed-off-by: Jan Kara Reviewed-by: Ewan D. Milne Signed-off-by: Martin K. Petersen Signed-off-by: Ben Hutchings --- 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 @@ -754,6 +754,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); @@ -766,13 +767,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; }