dmaengine: fsl-edma: fix potential NULL pointer dereference in fsl_edma_tx_status()

Message ID 20221026101841.35305-1-acherniakov@astralinux.ru
State New
Headers
Series dmaengine: fsl-edma: fix potential NULL pointer dereference in fsl_edma_tx_status() |

Commit Message

Andrew Chernyakov Oct. 26, 2022, 10:18 a.m. UTC
  fsl_edma_desc_residue() dereferences fsl_chan->edesc, but it is checked
for NULL only in one of two places where fsl_edma_desc_residue() is
called from fsl_edma_tx_status().

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Andrew Chernyakov <acherniakov@astralinux.ru>
---
 drivers/dma/fsl-edma-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

Vinod Koul Nov. 4, 2022, 2:37 p.m. UTC | #1
On 26-10-22, 13:18, Andrew Chernyakov wrote:
> fsl_edma_desc_residue() dereferences fsl_chan->edesc, but it is checked
> for NULL only in one of two places where fsl_edma_desc_residue() is
> called from fsl_edma_tx_status().

Patch subject should be the change it introduces, pls revise

> 
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
> 
> Signed-off-by: Andrew Chernyakov <acherniakov@astralinux.ru>
> ---
>  drivers/dma/fsl-edma-common.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/dma/fsl-edma-common.c b/drivers/dma/fsl-edma-common.c
> index a06a1575a2a5..fb712d85d556 100644
> --- a/drivers/dma/fsl-edma-common.c
> +++ b/drivers/dma/fsl-edma-common.c
> @@ -330,7 +330,7 @@ enum dma_status fsl_edma_tx_status(struct dma_chan *chan,
>  	if (fsl_chan->edesc && cookie == fsl_chan->edesc->vdesc.tx.cookie)
>  		txstate->residue =
>  			fsl_edma_desc_residue(fsl_chan, vdesc, true);
> -	else if (vdesc)
> +	else if (fsl_chan->edesc && vdesc)
>  		txstate->residue =
>  			fsl_edma_desc_residue(fsl_chan, vdesc, false);
>  	else
> -- 
> 2.35.1
  

Patch

diff --git a/drivers/dma/fsl-edma-common.c b/drivers/dma/fsl-edma-common.c
index a06a1575a2a5..fb712d85d556 100644
--- a/drivers/dma/fsl-edma-common.c
+++ b/drivers/dma/fsl-edma-common.c
@@ -330,7 +330,7 @@  enum dma_status fsl_edma_tx_status(struct dma_chan *chan,
 	if (fsl_chan->edesc && cookie == fsl_chan->edesc->vdesc.tx.cookie)
 		txstate->residue =
 			fsl_edma_desc_residue(fsl_chan, vdesc, true);
-	else if (vdesc)
+	else if (fsl_chan->edesc && vdesc)
 		txstate->residue =
 			fsl_edma_desc_residue(fsl_chan, vdesc, false);
 	else