Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1820951imm; Mon, 3 Sep 2018 10:17:13 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbZpPuK80zJETwwj35W6EmOqamdx3ON+z7hBM/2RiSMIGw2RLcZG9i+jhSfknAA9obRGMMi X-Received: by 2002:a63:bd41:: with SMTP id d1-v6mr27620548pgp.309.1535995033706; Mon, 03 Sep 2018 10:17:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995033; cv=none; d=google.com; s=arc-20160816; b=FRpJQml+6M00Q/eyeJ7MEKOYaoT8lMwTg7C3VprccgjBMMw/fYaTNutewvn7neTIg3 aPLNjD/MXpt2TF4kpR1XDF+C5GdIne2FiwvlivH78jsG2JTCGBtdvGX2C5tqAauSzijX 2TqItGtEfa3NWZjpGoLrs1eWjuwBFKqv4E9JxNgFhkyQoaHFegpxPa/XoChx/i3SYRT4 Es6qoPhE6OdwFhAaXeuNe3aIH70xp3gLCdcV4ambOQfoKNpuGjhd7UwNmhj4/bQKe69F Owm6BvTL3hT/lrUFreXFbDp5G77YP1dGJ9tK63JzmydKEJinNXBgIH4vYgn11dxH/tdV JLMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=xn/h2+qO41QfbtJU1rHDkynXRMvlWuTp7lZQvIV/bfk=; b=dk1hJIweL5G7jtO12npBLTuK1Rx2DX3bHsLFE+q8F2wYpVWu5l2OJY7mL7101GNDfe 4hO4oDfwiRW03yF8lYLSUPPmXjVLZpfw8UABHTzDwycZGem+giyw7RnaMlx4bNAyoPbc Nqd315vk6kUAOKNCBKWmLd/faOVILRhzQxZcEb8YmxqsAJ3lZfyFQ3DKEA/Nz+3nOh4r uHjZGbh4h9uYuO0DorhptR5Q1JMA35N4jJkUnw7TZP4tjVGle5H0p1c9s6dRxnoeTuQA T2PZvS5aZWlOjssZRxPgcuSuZPsXLNe68114u/jTuYTG8MObpAbfdKBahGsSHt13OdQ5 ycYQ== 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 o5-v6si17957418pgo.250.2018.09.03.10.16.58; Mon, 03 Sep 2018 10:17:13 -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 S1729653AbeICVgf (ORCPT + 99 others); Mon, 3 Sep 2018 17:36:35 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:42402 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727793AbeICVge (ORCPT ); Mon, 3 Sep 2018 17:36:34 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 526BBD02; Mon, 3 Sep 2018 17:15:30 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Varun Prakash , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.14 011/165] scsi: libiscsi: fix possible NULL pointer dereference in case of TMF Date: Mon, 3 Sep 2018 18:54:57 +0200 Message-Id: <20180903165655.576457825@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Varun Prakash [ Upstream commit a17037e7d59075053b522048742a08ac9500bde8 ] In iscsi_check_tmf_restrictions() task->hdr is dereferenced to print the opcode, it is possible that task->hdr is NULL. There are two cases based on opcode argument: 1. ISCSI_OP_SCSI_CMD - In this case alloc_pdu() is called after iscsi_check_tmf_restrictions() iscsi_prep_scsi_cmd_pdu() -> iscsi_check_tmf_restrictions() -> alloc_pdu(). Transport drivers allocate memory for iSCSI hdr in alloc_pdu() and assign it to task->hdr. In case of TMF task->hdr will be NULL resulting in NULL pointer dereference. 2. ISCSI_OP_SCSI_DATA_OUT - In this case transport driver can free the memory for iSCSI hdr after transmitting the pdu so task->hdr can be NULL or invalid. This patch fixes this issue by removing task->hdr->opcode from the printk statement. Signed-off-by: Varun Prakash Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/scsi/libiscsi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) --- a/drivers/scsi/libiscsi.c +++ b/drivers/scsi/libiscsi.c @@ -284,11 +284,11 @@ static int iscsi_check_tmf_restrictions( */ if (opcode != ISCSI_OP_SCSI_DATA_OUT) { iscsi_conn_printk(KERN_INFO, conn, - "task [op %x/%x itt " + "task [op %x itt " "0x%x/0x%x] " "rejected.\n", - task->hdr->opcode, opcode, - task->itt, task->hdr_itt); + opcode, task->itt, + task->hdr_itt); return -EACCES; } /* @@ -297,10 +297,10 @@ static int iscsi_check_tmf_restrictions( */ if (conn->session->fast_abort) { iscsi_conn_printk(KERN_INFO, conn, - "task [op %x/%x itt " + "task [op %x itt " "0x%x/0x%x] fast abort.\n", - task->hdr->opcode, opcode, - task->itt, task->hdr_itt); + opcode, task->itt, + task->hdr_itt); return -EACCES; } break;