Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp788176ybj; Thu, 7 May 2020 07:40:07 -0700 (PDT) X-Google-Smtp-Source: APiQypL0JXiVFKFsw+oCyI99Hy8rt2zJmbFjmgLBGtu0+0ZEeBMShkqa6tHsAwqg3dp3fEESjbrU X-Received: by 2002:a50:d6d0:: with SMTP id l16mr12631611edj.317.1588862406872; Thu, 07 May 2020 07:40:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588862406; cv=none; d=google.com; s=arc-20160816; b=j8RybFCiALgrNyrSEQ67Ro1+4zz0eD3OYshU3CUFPletXclAkJMIWTBKJSj+Bxb6jZ WxVgolqIJ81FTsr+po6YxjBidRiajK1iQjy3RpVYbj3IojJ0AO3Db4DHnI4z60cK/IHj E/NwA+6h6zc9Ph7Q2J45uc50HPdyzC4qRkjQTrB0R0onh2Qzp2h638CGMiuDo4W3T2vN kzOZN4yvgC2kem3XUqfs6nv3STnQSz0z3xgzNMz0Y3rOdderes9YxcyxWzuxXsIYEOEH u35iEwx07jP5KkzPqa4qyaDIDW15zLTsMND83b4AnTHbzf7pSjwpKA0OoBhZCwiVBUIK JDtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=a0WQ+KXVy6g+QSyl9rFzRisQyJ3KzPO7vJe6qqOXwiA=; b=Wwotypik2tBWt3Pxj97b9y0/IHsHVCYaUsc4IvoaGPg1K4k09xQt2p/x6spK9Mf9jh B4fkXEvKWEEa/I6L7zXwpG3UqCVj5PJU8ETXZBWxlFbsLkzhTD2eoo439CmTwzzpYUjT L21EIgVLayPsi5MjiiZx4CXIovFxjozj8P3RbginefTg8Ub0DJMGUkxzWKaT0QvHS85P kttWhtNj6pKdz9aVKr6bSSMzQptOAzSSkCOIGY6hYbvcyIfG55jbdVWEBx0sE6qIrp2h t15R5EE7alnoxNtgbaoaZ1C0vzbKtPDkyyqTUlJ5aUwWc6NCnZBERZBkrRfPIou91JkA 8COA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e0s4o+5E; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qh10si3429364ejb.49.2020.05.07.07.39.42; Thu, 07 May 2020 07:40:06 -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=@kernel.org header.s=default header.b=e0s4o+5E; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726807AbgEGO1f (ORCPT + 99 others); Thu, 7 May 2020 10:27:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:53284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726742AbgEGO1e (ORCPT ); Thu, 7 May 2020 10:27:34 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 798162083B; Thu, 7 May 2020 14:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588861653; bh=nldiJ+MHYYN+kjgAX5mo6jUIk7pC/Xc/j4g2G7Uco6Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e0s4o+5EI+KKTv1EgVraZSnAfNcypP9onwpJf01GmePNVCzCRa9kHDOdp2JmKvYAR QtzvVzwnfVW3XUo6M556Gizb5EI8oMj9cvYjDBNL59gnAAmOwQK3XM/R7wVj+WZJUZ eA8cU4ZevAU/7OzP0/EfaWKkx4XzjRT8pJYN7l+g= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sebastian von Ohr , Radhey Shyam Pandey , Vinod Koul , Sasha Levin , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.6 05/50] dmaengine: xilinx_dma: Add missing check for empty list Date: Thu, 7 May 2020 10:26:41 -0400 Message-Id: <20200507142726.25751-5-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200507142726.25751-1-sashal@kernel.org> References: <20200507142726.25751-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sebastian von Ohr [ Upstream commit b269426011bcfd97b7c3101abfe1a99147b6f40b ] The DMA transfer might finish just after checking the state with dma_cookie_status, but before the lock is acquired. Not checking for an empty list in xilinx_dma_tx_status may result in reading random data or data corruption when desc is written to. This can be reliably triggered by using dma_sync_wait to wait for DMA completion. Signed-off-by: Sebastian von Ohr Tested-by: Radhey Shyam Pandey Link: https://lore.kernel.org/r/20200303130518.333-1-vonohr@smaract.com Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/xilinx/xilinx_dma.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/dma/xilinx/xilinx_dma.c b/drivers/dma/xilinx/xilinx_dma.c index a9c5d5cc9f2bd..5d5f1d0ce16cb 100644 --- a/drivers/dma/xilinx/xilinx_dma.c +++ b/drivers/dma/xilinx/xilinx_dma.c @@ -1229,16 +1229,16 @@ static enum dma_status xilinx_dma_tx_status(struct dma_chan *dchan, return ret; spin_lock_irqsave(&chan->lock, flags); - - desc = list_last_entry(&chan->active_list, - struct xilinx_dma_tx_descriptor, node); - /* - * VDMA and simple mode do not support residue reporting, so the - * residue field will always be 0. - */ - if (chan->has_sg && chan->xdev->dma_config->dmatype != XDMA_TYPE_VDMA) - residue = xilinx_dma_get_residue(chan, desc); - + if (!list_empty(&chan->active_list)) { + desc = list_last_entry(&chan->active_list, + struct xilinx_dma_tx_descriptor, node); + /* + * VDMA and simple mode do not support residue reporting, so the + * residue field will always be 0. + */ + if (chan->has_sg && chan->xdev->dma_config->dmatype != XDMA_TYPE_VDMA) + residue = xilinx_dma_get_residue(chan, desc); + } spin_unlock_irqrestore(&chan->lock, flags); dma_set_residue(txstate, residue); -- 2.20.1