All of lore.kernel.org
 help / color / mirror / Atom feed
From: linux@armlinux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2] ARM: dma-mapping: fix potential uninitialized return
Date: Thu, 29 Nov 2018 10:14:29 +0000	[thread overview]
Message-ID: <20181129101428.GQ30658@n2100.armlinux.org.uk> (raw)
In-Reply-To: <401b58b2-fb17-dc83-f898-c10cafdc5413@arm.com>

On Thu, Nov 29, 2018 at 09:50:59AM +0000, Vladimir Murzin wrote:
> On 11/28/18 6:59 PM, Nathan Jones wrote:
> > If neither of the if() statements fire then the return value is
> > uninitialized. In the worst case it returns 0 which means the caller
> > will think the function succeeded.
> 
> "ret" is updated indirectly via:
> 
>         if (dma_mmap_from_dev_coherent(dev, vma, cpu_addr, size, &ret))
>                 return ret;

I'm afraid you are wrong - "ret" really is used uninitialised.

dma_mmap_from_dev_coherent() calls __dma_mmap_from_coherent(), and
there is a top-function-level if statement:

static int __dma_mmap_from_coherent(struct dma_coherent_mem *mem,
                struct vm_area_struct *vma, void *vaddr, size_t size, int *ret)
{
        if (mem && vaddr >= mem->virt_base && vaddr + size <=
                   (mem->virt_base + (mem->size << PAGE_SHIFT))) {
		... path that sets *ret ...
		return 1;
        }
        return 0;
}

If that if statement is true, then yes, ret will be initialised, and
dma_mmap_from_dev_coherent() will return 1.  We will take that
"return ret" statement in __arm_dma_mmap() and everything is fine.

If that if statement is false, then the function returns zero without
setting "ret" to anything, and we continue processing __arm_dma_mmap().
The next statements are:

        if (off < nr_pages && nr_vma_pages <= (nr_pages - off)) {
                ret = remap_pfn_range(vma, vma->vm_start,
                                      pfn + off,
                                      vma->vm_end - vma->vm_start,
                                      vma->vm_page_prot);
        }

        return ret;

So, if _this_ if statement is also false, then we get to "return ret"
but ret has not been initialised by anything.

Therefore, 'ret' does need initialisation, since as of your commit,
there is a path through the code where it is used uninitialised.

Hence, Nathan's patch is correct.

-- 
RMK's Patch system: http://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up

  parent reply	other threads:[~2018-11-29 10:14 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-28 17:39 [PATCH] ARM: dma-mapping: fix potential uninitialized return Nathan Jones
2018-11-28 17:47 ` Russell King - ARM Linux
2018-11-28 18:59 ` [PATCH v2] " Nathan Jones
2018-11-29  9:50   ` Vladimir Murzin
2018-11-29 10:11     ` Vladimir Murzin
2018-11-29 10:22       ` Russell King - ARM Linux
2018-11-29 16:26         ` Christoph Hellwig
2018-11-29 10:14     ` Russell King - ARM Linux [this message]
2018-11-29 14:58     ` Nathan Jones
2018-11-29 15:24       ` Russell King - ARM Linux
2018-11-30  9:00       ` Vladimir Murzin
2018-11-29 15:17   ` Robin Murphy
2018-11-30 13:07   ` [PATCH v3] " Nathan Jones
2018-12-04  9:09     ` Vladimir Murzin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181129101428.GQ30658@n2100.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.