diff mbox series

isdn: mISDN: Fix potential NULL pointer dereference of kzalloc

Message ID 20190302212044.13638-1-pakki001@umn.edu
State Accepted
Delegated to: David Miller
Headers show
Series isdn: mISDN: Fix potential NULL pointer dereference of kzalloc | expand

Commit Message

Aditya Pakki March 2, 2019, 9:20 p.m. UTC
Allocating memory via kzalloc for phi may fail and causes a
NULL pointer dereference. This patch avoids such a scenario.

Signed-off-by: Aditya Pakki <pakki001@umn.edu>
---
 drivers/isdn/hardware/mISDN/hfcsusb.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Gustavo A. R. Silva March 2, 2019, 9:26 p.m. UTC | #1
On 3/2/19 3:20 PM, Aditya Pakki wrote:
> Allocating memory via kzalloc for phi may fail and causes a
> NULL pointer dereference. This patch avoids such a scenario.
> 

Was this detected by Coccinelle?

If so, please mention it in the commit log.

Thanks
--
Gustavo

> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
> ---
>  drivers/isdn/hardware/mISDN/hfcsusb.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/isdn/hardware/mISDN/hfcsusb.c b/drivers/isdn/hardware/mISDN/hfcsusb.c
> index 124ff530da82..26e3182bbca8 100644
> --- a/drivers/isdn/hardware/mISDN/hfcsusb.c
> +++ b/drivers/isdn/hardware/mISDN/hfcsusb.c
> @@ -263,6 +263,9 @@ hfcsusb_ph_info(struct hfcsusb *hw)
>  	int i;
>  
>  	phi = kzalloc(struct_size(phi, bch, dch->dev.nrbchan), GFP_ATOMIC);
> +	if (!phi)
> +		return;
> +
>  	phi->dch.ch.protocol = hw->protocol;
>  	phi->dch.ch.Flags = dch->Flags;
>  	phi->dch.state = dch->state;
>
Kangjie Lu March 2, 2019, 9:39 p.m. UTC | #2
On 3/2/19 3:26 PM, Gustavo A. R. Silva wrote:
>
> On 3/2/19 3:20 PM, Aditya Pakki wrote:
>> Allocating memory via kzalloc for phi may fail and causes a
>> NULL pointer dereference. This patch avoids such a scenario.
>>
> Was this detected by Coccinelle?


It was detected by an LLVM-based static analyzer we recently developed.


>
> If so, please mention it in the commit log.
>
> Thanks
> --
> Gustavo
>
>> Signed-off-by: Aditya Pakki <pakki001@umn.edu>
>> ---
>>   drivers/isdn/hardware/mISDN/hfcsusb.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/drivers/isdn/hardware/mISDN/hfcsusb.c b/drivers/isdn/hardware/mISDN/hfcsusb.c
>> index 124ff530da82..26e3182bbca8 100644
>> --- a/drivers/isdn/hardware/mISDN/hfcsusb.c
>> +++ b/drivers/isdn/hardware/mISDN/hfcsusb.c
>> @@ -263,6 +263,9 @@ hfcsusb_ph_info(struct hfcsusb *hw)
>>   	int i;
>>   
>>   	phi = kzalloc(struct_size(phi, bch, dch->dev.nrbchan), GFP_ATOMIC);
>> +	if (!phi)
>> +		return;
>> +
>>   	phi->dch.ch.protocol = hw->protocol;
>>   	phi->dch.ch.Flags = dch->Flags;
>>   	phi->dch.state = dch->state;
>>
David Miller March 4, 2019, 6:55 p.m. UTC | #3
From: Aditya Pakki <pakki001@umn.edu>
Date: Sat,  2 Mar 2019 15:20:43 -0600

> Allocating memory via kzalloc for phi may fail and causes a
> NULL pointer dereference. This patch avoids such a scenario.
> 
> Signed-off-by: Aditya Pakki <pakki001@umn.edu>

Applied.
diff mbox series

Patch

diff --git a/drivers/isdn/hardware/mISDN/hfcsusb.c b/drivers/isdn/hardware/mISDN/hfcsusb.c
index 124ff530da82..26e3182bbca8 100644
--- a/drivers/isdn/hardware/mISDN/hfcsusb.c
+++ b/drivers/isdn/hardware/mISDN/hfcsusb.c
@@ -263,6 +263,9 @@  hfcsusb_ph_info(struct hfcsusb *hw)
 	int i;
 
 	phi = kzalloc(struct_size(phi, bch, dch->dev.nrbchan), GFP_ATOMIC);
+	if (!phi)
+		return;
+
 	phi->dch.ch.protocol = hw->protocol;
 	phi->dch.ch.Flags = dch->Flags;
 	phi->dch.state = dch->state;