Re: [PATCH 4.9 038/109] dmaengine: stm32-dma: Fix null pointer dereference in stm32_dma_tx_status
From: Pierre Yves MORDRET
Date: Thu Dec 07 2017 - 08:27:09 EST
Acked-by: Pierre-Yves MORDRET <pierre-yves.mordret@xxxxxx>
~PYM~
On 12/07/2017 02:18 PM, Ludovic BARRE wrote:
> with Pierre Yves mail it's better ;-)
>
> On 12/07/2017 02:04 PM, Ludovic BARRE wrote:
>> add Pierre-yves Mordret
>>
>> acked-by: Ludovic BARRE <ludovic.barre@xxxxxx>
>>
>> On 12/07/2017 01:56 PM, Greg Kroah-Hartman wrote:
>>> 4.9-stable review patch. If anyone has any objections, please let me
>>> know.
>>>
>>> ------------------
>>>
>>> From: M'boumba Cedric Madianga <cedric.madianga@xxxxxxxxx>
>>>
>>>
>>> [ Upstream commit 57b5a32135c813f2ab669039fb4ec16b30cb3305 ]
>>>
>>> chan->desc is always set to NULL when a DMA transfer is complete.
>>> As a DMA transfer could be complete during the call of
>>> stm32_dma_tx_status,
>>> we need to be sure that chan->desc is not NULL before using this variable
>>> to avoid a null pointer deference issue.
>>>
>>> Signed-off-by: M'boumba Cedric Madianga <cedric.madianga@xxxxxxxxx>
>>> Reviewed-by: Ludovic BARRE <ludovic.barre@xxxxxx>
>>> Signed-off-by: Vinod Koul <vinod.koul@xxxxxxxxx>
>>> Signed-off-by: Sasha Levin <alexander.levin@xxxxxxxxxxx>
>>> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
>>> ---
>>> Â drivers/dma/stm32-dma.c |ÂÂ 10 +++-------
>>> Â 1 file changed, 3 insertions(+), 7 deletions(-)
>>>
>>> --- a/drivers/dma/stm32-dma.c
>>> +++ b/drivers/dma/stm32-dma.c
>>> @@ -884,7 +884,7 @@ static enum dma_status stm32_dma_tx_stat
>>> ÂÂÂÂÂ struct virt_dma_desc *vdesc;
>>> ÂÂÂÂÂ enum dma_status status;
>>> ÂÂÂÂÂ unsigned long flags;
>>> -ÂÂÂ u32 residue;
>>> +ÂÂÂ u32 residue = 0;
>>> ÂÂÂÂÂ status = dma_cookie_status(c, cookie, state);
>>> ÂÂÂÂÂ if ((status == DMA_COMPLETE) || (!state))
>>> @@ -892,16 +892,12 @@ static enum dma_status stm32_dma_tx_stat
>>> ÂÂÂÂÂ spin_lock_irqsave(&chan->vchan.lock, flags);
>>> ÂÂÂÂÂ vdesc = vchan_find_desc(&chan->vchan, cookie);
>>> -ÂÂÂ if (cookie == chan->desc->vdesc.tx.cookie) {
>>> +ÂÂÂ if (chan->desc && cookie == chan->desc->vdesc.tx.cookie)
>>> ÂÂÂÂÂÂÂÂÂ residue = stm32_dma_desc_residue(chan, chan->desc,
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ chan->next_sg);
>>> -ÂÂÂ } else if (vdesc) {
>>> +ÂÂÂ else if (vdesc)
>>> ÂÂÂÂÂÂÂÂÂ residue = stm32_dma_desc_residue(chan,
>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ to_stm32_dma_desc(vdesc), 0);
>>> -ÂÂÂ } else {
>>> -ÂÂÂÂÂÂÂ residue = 0;
>>> -ÂÂÂ }
>>> -
>>> ÂÂÂÂÂ dma_set_residue(state, residue);
>>> ÂÂÂÂÂ spin_unlock_irqrestore(&chan->vchan.lock, flags);
>>>
>>>