Linux-mtd Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Brian Norris <computersforpeace@gmail.com>
To: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: linux-mtd@lists.infradead.org, dwmw2@infradead.org
Subject: Re: [PATCH] mtd: physmap_of: fix potential NULL dereference
Date: Fri, 12 Dec 2014 19:11:51 -0800	[thread overview]
Message-ID: <20141213031151.GP21347@ld-irv-0074> (raw)
In-Reply-To: <1417351863-3812-1-git-send-email-ard.biesheuvel@linaro.org>

On Sun, Nov 30, 2014 at 01:51:03PM +0100, Ard Biesheuvel wrote:
> On device remove, when testing the cmtd field of an of_flash
> struct to decide whether it is a concatenated device or not,
> we get a false positive on cmtd == NULL, and dereference it
> subsequently. This may occur if of_flash_remove() is called
> from the cleanup path of of_flash_probe().

Did you catch this on real hardware, or just by inspection? Just
wondering if this should be marked for -stable.

> Instead, test for NULL first, and only then perform the test
> for a concatenated device.
> 
> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> ---
>  drivers/mtd/maps/physmap_of.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
> index c1d21cb501ca..e48930424091 100644
> --- a/drivers/mtd/maps/physmap_of.c
> +++ b/drivers/mtd/maps/physmap_of.c
> @@ -47,14 +47,12 @@ static int of_flash_remove(struct platform_device *dev)
>  		return 0;
>  	dev_set_drvdata(&dev->dev, NULL);
>  
> -	if (info->cmtd != info->list[0].mtd) {
> +	if (info->cmtd) {
>  		mtd_device_unregister(info->cmtd);
> -		mtd_concat_destroy(info->cmtd);
> +		if (info->cmtd != info->list[0].mtd)
> +			mtd_concat_destroy(info->cmtd);
>  	}
>  
> -	if (info->cmtd)
> -		mtd_device_unregister(info->cmtd);
> -
>  	for (i = 0; i < info->list_size; i++) {
>  		if (info->list[i].mtd)
>  			map_destroy(info->list[i].mtd);

Brian

  parent reply	other threads:[~2014-12-13  3:12 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-30 12:51 [PATCH] mtd: physmap_of: fix potential NULL dereference Ard Biesheuvel
2014-12-12 16:21 ` Ard Biesheuvel
2014-12-13  3:11 ` Brian Norris [this message]
2014-12-13  6:44   ` Ard Biesheuvel
2014-12-13  3:28 ` Brian Norris

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=20141213031151.GP21347@ld-irv-0074 \
    --to=computersforpeace@gmail.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=dwmw2@infradead.org \
    --cc=linux-mtd@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox