lkml.org 
[lkml]   [2010]   [Mar]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] drivers/net/wimax/i2400m/fw.c fix possible double free
From
From: Darren Jenkins <darrenrjenkins@gmail.com>
Date: Tue, 16 Mar 2010 22:46:28 +1100

> i2400m_fw_check() can free i2400m->fw_hdrs if krealloc() fails causing a double free
> Add a check so we don't free the memory a second time.
>
> coverity CID: 13455
>
> Signed-off-by: Darren Jenkins <darrenrjenkins@gmail.com>

Please don't fix it like this, the check is obscure and it's
allowing other bugs to happen.

If krealloc() fails, any refrence to i2400m->fw_hdrs is
referencing freed memory.

Therefore the krealloc() failure handling in this driver should NULL
out i2400m->fw_hdrs and that will fix the double kfree problem as well
as trap any stray references.

> ---
> drivers/net/wimax/i2400m/fw.c | 3 ++-
> 1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/drivers/net/wimax/i2400m/fw.c b/drivers/net/wimax/i2400m/fw.c
> index 25c24f0..a97c413 100644
> --- a/drivers/net/wimax/i2400m/fw.c
> +++ b/drivers/net/wimax/i2400m/fw.c
> @@ -1490,7 +1490,8 @@ int i2400m_fw_bootstrap(struct i2400m *i2400m, const struct firmware *fw,
> if (ret < 0)
> dev_err(dev, "%s: cannot use: %d, skipping\n",
> i2400m->fw_name, ret);
> - kfree(i2400m->fw_hdrs);
> + if (ret != -ENOMEM)
> + kfree(i2400m->fw_hdrs);
> i2400m->fw_hdrs = NULL;
> d_fnend(5, dev, "(i2400m %p) = %d\n", i2400m, ret);
> return ret;
> --
> 1.6.3.3


\
 
 \ /
  Last update: 2010-03-16 22:17    [W:1.068 / U:0.576 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site