Received: by 2002:a05:6520:4211:b029:f4:110d:56bc with SMTP id o17csp2108351lkv; Thu, 20 May 2021 03:36:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxvy7jMPwKycJ87zyX5F3RS7H2Muj9oA8fIMfTIfndsJ39fWFk0Lx/9eF4ojd2DxXdZ8pXL X-Received: by 2002:a92:dcc6:: with SMTP id b6mr3663788ilr.224.1621506986204; Thu, 20 May 2021 03:36:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621506986; cv=none; d=google.com; s=arc-20160816; b=LaTu6bZmPHW88SZFri8uRCS3bKm1dfme7XGZUduYuidTtYRUUoyCh3GEVaEqrKGEIl B3Z79w7idxdjZQU+dbnKb1GHHcgBUgnagHdTwULAQVVqn11CnShWOvwOiTPtUmGCEdWm zK6fqfwyxCXfwdpSnc8rD+PwtZ7K0IaRKzFuBRe4JC8m2RqR0u7aCMEFatGzPgBAmfu8 LhIVVRsyO1WObSNGSQE/4CwqOZ86EgZ3kbpyAnE0LAOTknnFF9hERv8u8fQMDIrQwacK RkkJkHhXE73SERizuoLn2LyvyqWBA7sqoHXi/9DCPfPYLEIZPfwSV4HJKC6WKTxfpuav bg/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TAF8Jt4QVZtOvIdIEObFWAHvbdWydBkhYR48ib542EI=; b=IbCovhVN61nubHNrtrINWJn0OqyEGnRPP8YGJPM+oLCUbxY3xVNijaGdrjIAGCdOeI GSsp/+rbMsHjQBY664YLNbqfVyv7m9RhTCh9wBRASnPJf0Qb9CaVWBNZquNo0UaGxNzR wNMp5BiP29uzTEUYxFSyJrocYguiGfD5SONoJ31jU/Jjr0crG0NrE6QEA5fw/5JMANg3 BaIq4os3kXGe3Wa2QiUBAzHRNH69M/miv1F6ymlnZlFmVEuj31swHsvlXIHN0sxtqJRj 2yBeLl/dhrtGMZH5aAo6nBEBqdCwlrvlEqobKD8DyEkrjlwyneiw7VOosSD1K10pH4Jj CRxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JRvCBYuR; 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=pass (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 u9si2194687jat.83.2021.05.20.03.35.40; Thu, 20 May 2021 03:36:26 -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=@linuxfoundation.org header.s=korg header.b=JRvCBYuR; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236705AbhETKdt (ORCPT + 99 others); Thu, 20 May 2021 06:33:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:51824 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235699AbhETKUg (ORCPT ); Thu, 20 May 2021 06:20:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4733E619C5; Thu, 20 May 2021 09:47:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621504058; bh=kI+rkmKsoWNvP+diRQEDMpeuHF2yYZ5MJaNw0LmznwA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JRvCBYuRtgFPgNH3MdZ7nfcMJGPKpKjCW5VAg4Xn9eUWEEN/IF/I6ISLwrf24G8YO /Ft47VqoTo6z+e8PzLHh+TpFJbc2lWOx2jQfvrrmeYVdzk69CDFl6EWPRQdI9zAfJK lPSi7MvPYk1ciOF0/d7oax/SSZO4wHVThoclEFqU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Himanshu Madhani , Quinn Tran , Saurav Kashyap , Nilesh Javali , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.14 056/323] scsi: qla2xxx: Fix use after free in bsg Date: Thu, 20 May 2021 11:19:08 +0200 Message-Id: <20210520092122.032513396@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Quinn Tran [ Upstream commit 2ce35c0821afc2acd5ee1c3f60d149f8b2520ce8 ] On bsg command completion, bsg_job_done() was called while qla driver continued to access the bsg_job buffer. bsg_job_done() would free up resources that ended up being reused by other task while the driver continued to access the buffers. As a result, driver was reading garbage data. localhost kernel: BUG: KASAN: use-after-free in sg_next+0x64/0x80 localhost kernel: Read of size 8 at addr ffff8883228a3330 by task swapper/26/0 localhost kernel: localhost kernel: CPU: 26 PID: 0 Comm: swapper/26 Kdump: loaded Tainted: G OE --------- - - 4.18.0-193.el8.x86_64+debug #1 localhost kernel: Hardware name: HP ProLiant DL360 Gen9/ProLiant DL360 Gen9, BIOS P89 08/12/2016 localhost kernel: Call Trace: localhost kernel: localhost kernel: dump_stack+0x9a/0xf0 localhost kernel: print_address_description.cold.3+0x9/0x23b localhost kernel: kasan_report.cold.4+0x65/0x95 localhost kernel: debug_dma_unmap_sg.part.12+0x10d/0x2d0 localhost kernel: qla2x00_bsg_sp_free+0xaf6/0x1010 [qla2xxx] Link: https://lore.kernel.org/r/20210329085229.4367-6-njavali@marvell.com Reviewed-by: Himanshu Madhani Signed-off-by: Quinn Tran Signed-off-by: Saurav Kashyap Signed-off-by: Nilesh Javali Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/scsi/qla2xxx/qla_bsg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/scsi/qla2xxx/qla_bsg.c b/drivers/scsi/qla2xxx/qla_bsg.c index c1ca21a88a09..06063a841726 100644 --- a/drivers/scsi/qla2xxx/qla_bsg.c +++ b/drivers/scsi/qla2xxx/qla_bsg.c @@ -19,10 +19,11 @@ qla2x00_bsg_job_done(void *ptr, int res) struct bsg_job *bsg_job = sp->u.bsg_job; struct fc_bsg_reply *bsg_reply = bsg_job->reply; + sp->free(sp); + bsg_reply->result = res; bsg_job_done(bsg_job, bsg_reply->result, bsg_reply->reply_payload_rcv_len); - sp->free(sp); } void -- 2.30.2