Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2483084pxj; Mon, 10 May 2021 04:11:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxj4g3/ZncJcc6tXQW64It8uHeaa8eR0mw6HBNIlL3UkWH8Rgws+XbL9VLFos3OC49DAWsB X-Received: by 2002:a02:6d09:: with SMTP id m9mr21014610jac.131.1620645060974; Mon, 10 May 2021 04:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620645060; cv=none; d=google.com; s=arc-20160816; b=kuT3YvGB91/xVUqgDf4uweGEyOlRcGqhXwdqCO1ybrq/bf0WJuVI5ppu71Sv5lAD1L VO1E+OXG5EfLiL2du+equZT6s8Vq4B11wN5BVz3qhRNaIq1RWsBiyB8Bcz8vMrYH9aIN iN9WJWkreUQE+FrWELZV4Ct1VjMbw2z3djJOZnFBZqkjU6V28CGLuWwpGr6QydolI6Rp o9sspn6bzVgH3X5aUPmT9gIJqB6+MJuh6+TUDcokta2NjOjMNS9rrEtXj+1GdXjkA6gw tYaj5TTH7bD4gWoQ4eIrQlMqrOv4Gx5P/pFD82LO5zM7ozrC5udNMSUqBqBgSilYx//R sk0g== 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=VwMGlipAP+2e5kgClfc/plqmhXQTEu3RpI0r5kpArXE=; b=E85G99qqUA9V67vNLezN3wpLeIPVtMF1mYOOkGyp1w5K7kBzA4GlBhEQza/EtKuVfa BSZtD216avWTWH7j3+KxFhfAwiVEztmCq+qyPVuvswU6g6HZVkQbQkj70Uj0Q6VbTMkQ m1fB9k40M5NZU3g8l5BL36oGZd/6+vxWMnBnIRyLh+f5j16iqcZ3VVsfFY13FpDdxHTk 6bvWNjQi7oz9zjEoXBX5h7JbeLaVbQZCdxmfkC1QVX61d1i6AVqGwIHx8LzuDiYkQiXJ TGrKoerbKfZXvixYu6eJDMYUPtGcjgVgyAsB7bNEO8zqSAetCMDa1/SKUz4vWkz3KgRa KhpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=P4b2Glvz; 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 k7si15935815ilo.146.2021.05.10.04.10.48; Mon, 10 May 2021 04:11:00 -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=P4b2Glvz; 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 S236107AbhEJLHh (ORCPT + 99 others); Mon, 10 May 2021 07:07:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:58338 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232343AbhEJKqi (ORCPT ); Mon, 10 May 2021 06:46:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 11815619AD; Mon, 10 May 2021 10:37:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620643035; bh=P1406Jpr8eiCFe4E8OCTMSlIbNSDkAouqN75tcgzYgc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P4b2GlvzwcQ0VDNtSUsAWyBXKS4iR1Owp4NwjKQ/T0rgVP0jXwpvDV6WnNfZjXJdh wLqm9bDBxGViKHgXyTbIgxf7P2OwG7T6Src+17Z03mMS/SiudLSqioKu15egw6fWk0 MAvDtDCB+CSqXq/uYoOKeM1E2VvTWTIJ6ZHuZYOI= 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 5.10 150/299] scsi: qla2xxx: Fix use after free in bsg Date: Mon, 10 May 2021 12:19:07 +0200 Message-Id: <20210510102009.911368717@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210510102004.821838356@linuxfoundation.org> References: <20210510102004.821838356@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 23b604832a54..7fa085969a63 100644 --- a/drivers/scsi/qla2xxx/qla_bsg.c +++ b/drivers/scsi/qla2xxx/qla_bsg.c @@ -24,10 +24,11 @@ void qla2x00_bsg_job_done(srb_t *sp, 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 qla2x00_bsg_sp_free(srb_t *sp) -- 2.30.2