drivers/net/wimax/i2400m/fw.c fix possible double free
Subsystems (2)
PATCH 1/1 drivers/net/wimax/i2400m/fw.c fix possible double free
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
--- drivers/net/wimax/i2400m/fw.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
drivers/net/wimax/i2400m/fw.c +2 -1
@@ -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;
Signature · 1 line
1.6.3.3
David Miller
maintainerFrom: Darren Jenkins <[email protected]>
Date: Tue, 16 Mar 2010 22:46:28 +1100
Quoted 6 lines
i2400m_fw_check()can freei2400m->fw_hdrsifkrealloc()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 <[email protected]>
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.
Quoted 20 lines
--- drivers/net/wimax/i2400m/fw.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)drivers/net/wimax/i2400m/fw.c +2
-1@@ -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;Signature · 1 line
1.6.3.3
Quoted 13 lines · David Miller
From: Darren Jenkins <[email protected]>
Date: Tue, 16 Mar 2010 22:46:28 +1100Quoted 6 lines
i2400m_fw_check()can freei2400m->fw_hdrsifkrealloc()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 <[email protected]>Please don't fix it like this, the check is obscure and it's allowing other bugs to happen.
Quoted 6 lines
If
krealloc()fails, any refrence toi2400m->fw_hdrsis referencing freed memory.Therefore the
krealloc()failure handling in this driver should NULL outi2400m->fw_hdrsand that will fix the double kfree problem as well as trap any stray references.
I agree with David, the fix is quite obscure. The error path in i2400m_fw_check()'s call to i2400m_kzrealloc_2x() should be rather cleaning up in a better way.