Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp23220pxb; Fri, 15 Jan 2021 04:58:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJypy/OT3RLcb3vyrUfYycJ/0QXbYFJD+xUvtzNPSqKS9jH35gr7GiI75P6TZXwOKYsJqjTO X-Received: by 2002:a17:906:90d6:: with SMTP id v22mr8677607ejw.88.1610715513300; Fri, 15 Jan 2021 04:58:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610715513; cv=none; d=google.com; s=arc-20160816; b=VjELf1he5qpfNTHmBcdU9OXTrw0IzKveRCbw34ZMhB4dXTKreYbYMNC9C/bNJGjT4n rFlRTpmBNJ611QspOYJ/Awe7TAa/t7xH1Ueq7StHYlHqmPzmB2S/UVtGygZEXreO+KYT aPpAz3PmJ3TjKbiAayWYedGLOvvaWvKMQvb56vHKVq1/VOyNK9zCbPsP931cWaU8GtrW SXWHwQA9wnb5ImG1v+eeUujQm/0GIosEwbRkV4xvq/BYjhoj5U+nc2RHQVzHyv14WIbE EMRJq2VlRR/Ivm/R14dxOmuFs0dcriUOzaj7PaxuK8Z5bngTZ5+ItMa/0MHoZ8jvDKZi V/1w== 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=a4ZDQypw9peb8Ed7ohOjajON41O7LsU1vr5Ky4CEXYI=; b=yz3nk436XsNXxh8eHb+Nf4xm1X+9zeEd9P7lks6F1brHrCZFL5K0VTfqgiW1/yzaWA x+cJIelCTOMUVgvWpukNnPoSdiTRai2W9AnX1nW8dEV/V6SOeur5yWCI1e+nA63yojq5 uswXauHMoaznI4iFWMX9c2GFWAvSFjKF3ArfiOA2sZ9CxKppSP5rvES1pCPjDk3+eD4R wsdFglYonAzfbnd4SFvqhy0gaEfdqZlB+d9CnnbynveCcbZpjUue7jb6pTuL9kxFW9xc h15TttbtjcdjfNnRzuOTRLwxbe4F5MYI9zBEP3Nq3OAt/t4gb2DFJptUaJgnTzHn5L4/ 1H+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=eBevTQo5; 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 v3si3509627eje.650.2021.01.15.04.58.09; Fri, 15 Jan 2021 04:58:33 -0800 (PST) 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=eBevTQo5; 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 S1732867AbhAOMfI (ORCPT + 99 others); Fri, 15 Jan 2021 07:35:08 -0500 Received: from mail.kernel.org ([198.145.29.99]:41400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387533AbhAOMev (ORCPT ); Fri, 15 Jan 2021 07:34:51 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 19A7B23359; Fri, 15 Jan 2021 12:34:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1610714076; bh=UzfAEKJY8rc8SY6lA7OSso4IDYsVqTBY144XalJuV+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eBevTQo5efaq2jNxAf2R9CVIjhtddCPjFHRyPvUUI1x0fYmjDs19q/9icU18uy5kw OuLcGeWwMZjtPAX/DsCYbPZqJH/OLzd1W/c7phAYxahSZ1bS3SlZRPDhpsI17leCxN mBD26JacSEoyqfDNCmcEF+zKm1SEThK6y2r1lDKE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Gustavo Pimentel , Vinod Koul Subject: [PATCH 5.4 35/62] dmaengine: dw-edma: Fix use after free in dw_edma_alloc_chunk() Date: Fri, 15 Jan 2021 13:27:57 +0100 Message-Id: <20210115122000.092494711@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210115121958.391610178@linuxfoundation.org> References: <20210115121958.391610178@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: Dan Carpenter commit 595a334148449bd1d27cf5d6fcb3b0d718cb1b9f upstream. If the dw_edma_alloc_burst() function fails then we free "chunk" but it's still on the "desc->chunk->list" list so it will lead to a use after free. Also the "->chunks_alloc" count is incremented when it shouldn't be. In current kernels small allocations are guaranteed to succeed and dw_edma_alloc_burst() can't fail so this will not actually affect runtime. Fixes: e63d79d1ffcd ("dmaengine: Add Synopsys eDMA IP core driver") Signed-off-by: Dan Carpenter Acked-by: Gustavo Pimentel Link: https://lore.kernel.org/r/X9dTBFrUPEvvW7qc@mwanda Signed-off-by: Vinod Koul Signed-off-by: Greg Kroah-Hartman --- drivers/dma/dw-edma/dw-edma-core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/dma/dw-edma/dw-edma-core.c +++ b/drivers/dma/dw-edma/dw-edma-core.c @@ -85,12 +85,12 @@ static struct dw_edma_chunk *dw_edma_all if (desc->chunk) { /* Create and add new element into the linked list */ - desc->chunks_alloc++; - list_add_tail(&chunk->list, &desc->chunk->list); if (!dw_edma_alloc_burst(chunk)) { kfree(chunk); return NULL; } + desc->chunks_alloc++; + list_add_tail(&chunk->list, &desc->chunk->list); } else { /* List head */ chunk->burst = NULL;