* [PATCH] Staging: rtl8192e: Fix segfault upon alloc failure
@ 2014-11-05 16:11 Daniel Dressler
2014-11-05 22:56 ` Greg Kroah-Hartman
0 siblings, 1 reply; 2+ messages in thread
From: Daniel Dressler @ 2014-11-05 16:11 UTC (permalink / raw)
To: danieru.dressler
Cc: Greg Kroah-Hartman, Matthew Casey, Ben Hutchings,
open list:STAGING SUBSYSTEM, open list
Kernel space allocations can fail. This patch
fixes a crash condition upon allocation failure.
Should this condition occur init_firmware() will
goto its error handler and declare download failure.
Of interesting note is that prior to this patch
fw_download_code() could never fail yet our caller
checked the return value.
Reported-by: RUC_Soft_Sec <rucsoftsec@gmail.com>
Signed-off-by: Daniel Dressler <danieru.dressler@gmail.com>
---
drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
index 2e28744..e4257fe 100644
--- a/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
+++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
@@ -61,6 +61,9 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
}
skb = dev_alloc_skb(frag_length + 4);
+ if (!skb)
+ return false;
+
memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev));
tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE);
tcb_desc->queue_index = TXCMD_QUEUE;
--
2.1.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] Staging: rtl8192e: Fix segfault upon alloc failure
2014-11-05 16:11 [PATCH] Staging: rtl8192e: Fix segfault upon alloc failure Daniel Dressler
@ 2014-11-05 22:56 ` Greg Kroah-Hartman
0 siblings, 0 replies; 2+ messages in thread
From: Greg Kroah-Hartman @ 2014-11-05 22:56 UTC (permalink / raw)
To: Daniel Dressler
Cc: Matthew Casey, Ben Hutchings, open list:STAGING SUBSYSTEM, open list
On Thu, Nov 06, 2014 at 01:11:17AM +0900, Daniel Dressler wrote:
> Kernel space allocations can fail. This patch
> fixes a crash condition upon allocation failure.
>
> Should this condition occur init_firmware() will
> goto its error handler and declare download failure.
>
> Of interesting note is that prior to this patch
> fw_download_code() could never fail yet our caller
> checked the return value.
>
> Reported-by: RUC_Soft_Sec <rucsoftsec@gmail.com>
> Signed-off-by: Daniel Dressler <danieru.dressler@gmail.com>
> ---
> drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c b/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
> index 2e28744..e4257fe 100644
> --- a/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
> +++ b/drivers/staging/rtl8192e/rtl8192e/r8192E_firmware.c
> @@ -61,6 +61,9 @@ static bool fw_download_code(struct net_device *dev, u8 *code_virtual_address,
> }
>
> skb = dev_alloc_skb(frag_length + 4);
> + if (!skb)
> + return false;
Lots of people try to fix this "warning" in this manner. But you have
to do more work here than just a simple "return false;", you need to
unwind all of the work you have done up to this point, which is a
non-trivial task...
I'd recommend looking at how other drivers of this manufacturer handle
this type of operation to get a better idea of how to rewrite this
function.
good luck,
greg k-h
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-11-05 22:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-05 16:11 [PATCH] Staging: rtl8192e: Fix segfault upon alloc failure Daniel Dressler
2014-11-05 22:56 ` Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).