All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Martin Fuzzey <mfuzzey@parkeon.com>, linux-iio@vger.kernel.org
Subject: Re: [PATCH] iio: core: Fix double free.
Date: Sun, 27 Jul 2014 17:42:27 +0100	[thread overview]
Message-ID: <53D52BF3.6020903@kernel.org> (raw)
In-Reply-To: <20140721132215.11583.81979.stgit@localhost>

On 21/07/14 14:22, Martin Fuzzey wrote:
> When an error occured during event registration memory was freed twice
> resulting in kernel memory corruption and a crash in unrelated code.
>
> The problem was caused by
> 	iio_device_unregister_eventset()
> 	iio_device_unregister_sysfs()
>
> being called twice, once on the error path and then
> again via iio_dev_release().
>
> Fix this by making these two functions idempotent so they
> may be called multiple times.
>
> The problem was observed before applying
> 	78b33216 iio:core: Handle error when mask type is not separate
>
> Signed-off-by: Martin Fuzzey <mfuzzey@parkeon.com>
Good catch.

Applied to the fixes-togreg branch of iio.git and marked
for stable.

Given the timing this might end up waiting until after the upcoming merge
windows closes. It's been there a long time with you being the first to notice
so I'm not that fussed about rushing it out and annoying Linus!

Jonathan
> ---
>   drivers/iio/industrialio-core.c  |    5 +++--
>   drivers/iio/industrialio-event.c |    1 +
>   2 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index 4b1f375..fa06197 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -828,8 +828,7 @@ static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
>    * @attr_list: List of IIO device attributes
>    *
>    * This function frees the memory allocated for each of the IIO device
> - * attributes in the list. Note: if you want to reuse the list after calling
> - * this function you have to reinitialize it using INIT_LIST_HEAD().
> + * attributes in the list.
>    */
>   void iio_free_chan_devattr_list(struct list_head *attr_list)
>   {
> @@ -837,6 +836,7 @@ void iio_free_chan_devattr_list(struct list_head *attr_list)
>
>   	list_for_each_entry_safe(p, n, attr_list, l) {
>   		kfree(p->dev_attr.attr.name);
> +		list_del(&p->l);
>   		kfree(p);
>   	}
>   }
> @@ -917,6 +917,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
>
>   	iio_free_chan_devattr_list(&indio_dev->channel_attr_list);
>   	kfree(indio_dev->chan_attr_group.attrs);
> +	indio_dev->chan_attr_group.attrs = NULL;
>   }
>
>   static void iio_dev_release(struct device *device)
> diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
> index bfbf4d4..ad7a35f 100644
> --- a/drivers/iio/industrialio-event.c
> +++ b/drivers/iio/industrialio-event.c
> @@ -492,6 +492,7 @@ int iio_device_register_eventset(struct iio_dev *indio_dev)
>   error_free_setup_event_lines:
>   	iio_free_chan_devattr_list(&indio_dev->event_interface->dev_attr_list);
>   	kfree(indio_dev->event_interface);
> +	indio_dev->event_interface = NULL;
>   	return ret;
>   }
>
>


      reply	other threads:[~2014-07-27 16:40 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-21 13:22 [PATCH] iio: core: Fix double free Martin Fuzzey
2014-07-27 16:42 ` Jonathan Cameron [this message]

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=53D52BF3.6020903@kernel.org \
    --to=jic23@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=mfuzzey@parkeon.com \
    /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.