* [PATCH net-next] cxgb4: Check for kvzalloc allocation failure @ 2018-05-22 7:07 YueHaibing 2018-05-24 15:07 ` David Miller 0 siblings, 1 reply; 4+ messages in thread From: YueHaibing @ 2018-05-22 7:07 UTC (permalink / raw) To: ganeshgr, davem; +Cc: linux-kernel, netdev, YueHaibing t4_prep_fw doesn't check for card_fw pointer before store the read data, which could lead to a NULL pointer dereference if kvzalloc failed. Signed-off-by: YueHaibing <yuehaibing@huawei.com> --- drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c index 130d1ee..019cffe 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c @@ -4135,6 +4135,10 @@ static int adap_init0(struct adapter *adap) * card */ card_fw = kvzalloc(sizeof(*card_fw), GFP_KERNEL); + if (!card_fw) { + ret = -ENOMEM; + goto bye; + } /* Get FW from from /lib/firmware/ */ ret = request_firmware(&fw, fw_info->fw_mod_name, -- 2.7.0 ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] cxgb4: Check for kvzalloc allocation failure 2018-05-22 7:07 [PATCH net-next] cxgb4: Check for kvzalloc allocation failure YueHaibing @ 2018-05-24 15:07 ` David Miller 2018-05-25 1:39 ` YueHaibing 0 siblings, 1 reply; 4+ messages in thread From: David Miller @ 2018-05-24 15:07 UTC (permalink / raw) To: yuehaibing; +Cc: ganeshgr, linux-kernel, netdev From: YueHaibing <yuehaibing@huawei.com> Date: Tue, 22 May 2018 15:07:18 +0800 > diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c > index 130d1ee..019cffe 100644 > --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c > +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c > @@ -4135,6 +4135,10 @@ static int adap_init0(struct adapter *adap) > * card > */ > card_fw = kvzalloc(sizeof(*card_fw), GFP_KERNEL); > + if (!card_fw) { > + ret = -ENOMEM; > + goto bye; > + } > On error, this leaks fw_info. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] cxgb4: Check for kvzalloc allocation failure 2018-05-24 15:07 ` David Miller @ 2018-05-25 1:39 ` YueHaibing 2018-05-25 1:52 ` David Miller 0 siblings, 1 reply; 4+ messages in thread From: YueHaibing @ 2018-05-25 1:39 UTC (permalink / raw) To: David Miller; +Cc: ganeshgr, linux-kernel, netdev On 2018/5/24 23:07, David Miller wrote: > From: YueHaibing <yuehaibing@huawei.com> > Date: Tue, 22 May 2018 15:07:18 +0800 > >> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c >> index 130d1ee..019cffe 100644 >> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c >> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c >> @@ -4135,6 +4135,10 @@ static int adap_init0(struct adapter *adap) >> * card >> */ >> card_fw = kvzalloc(sizeof(*card_fw), GFP_KERNEL); >> + if (!card_fw) { >> + ret = -ENOMEM; >> + goto bye; >> + } >> > > On error, this leaks fw_info. Hi David, I checked fw_info is an element of fw_info_array,there all members of struct fw_info no need free. It likes this : static struct fw_info fw_info_array[] = { { .chip = CHELSIO_T4, .fs_name = FW4_CFNAME, .fw_mod_name = FW4_FNAME, .fw_hdr = { .chip = FW_HDR_CHIP_T4, .fw_ver = __cpu_to_be32(FW_VERSION(T4)), .intfver_nic = FW_INTFVER(T4, NIC), .intfver_vnic = FW_INTFVER(T4, VNIC), .intfver_ri = FW_INTFVER(T4, RI), .intfver_iscsi = FW_INTFVER(T4, ISCSI), .intfver_fcoe = FW_INTFVER(T4, FCOE), }, }, { ........ Am I missing something? > > . > ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next] cxgb4: Check for kvzalloc allocation failure 2018-05-25 1:39 ` YueHaibing @ 2018-05-25 1:52 ` David Miller 0 siblings, 0 replies; 4+ messages in thread From: David Miller @ 2018-05-25 1:52 UTC (permalink / raw) To: yuehaibing; +Cc: ganeshgr, linux-kernel, netdev From: YueHaibing <yuehaibing@huawei.com> Date: Fri, 25 May 2018 09:39:20 +0800 > On 2018/5/24 23:07, David Miller wrote: >> From: YueHaibing <yuehaibing@huawei.com> >> Date: Tue, 22 May 2018 15:07:18 +0800 >> >>> diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c >>> index 130d1ee..019cffe 100644 >>> --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c >>> +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c >>> @@ -4135,6 +4135,10 @@ static int adap_init0(struct adapter *adap) >>> * card >>> */ >>> card_fw = kvzalloc(sizeof(*card_fw), GFP_KERNEL); >>> + if (!card_fw) { >>> + ret = -ENOMEM; >>> + goto bye; >>> + } >>> >> >> On error, this leaks fw_info. > > Hi David, > > I checked fw_info is an element of fw_info_array,there all members of struct fw_info no need free. Aha, I misread the code, sorry. Applied, thanks. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-05-25 1:52 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-05-22 7:07 [PATCH net-next] cxgb4: Check for kvzalloc allocation failure YueHaibing 2018-05-24 15:07 ` David Miller 2018-05-25 1:39 ` YueHaibing 2018-05-25 1:52 ` David Miller
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®