* [PATCH iwl-net v1] idpf: fix potential memory leak on kcalloc() failure
@ 2025-04-04 10:54 Michal Swiatkowski
2025-04-07 10:43 ` Simon Horman
2025-04-25 16:49 ` [Intel-wired-lan] " Salin, Samuel
0 siblings, 2 replies; 7+ messages in thread
From: Michal Swiatkowski @ 2025-04-04 10:54 UTC (permalink / raw)
To: intel-wired-lan
Cc: netdev, Michal Swiatkowski, Pavan Kumar Linga,
Aleksandr Loktionov
In case of failing on rss_data->rss_key allocation the function is
freeing vport without freeing earlier allocated q_vector_idxs. Fix it.
Move from freeing in error branch to goto scheme.
Fixes: 95af467d9a4e ("idpf: configure resources for RX queues")
Reviewed-by: Pavan Kumar Linga <pavan.kumar.linga@intel.com>
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
Suggested-by: Pavan Kumar Linga <pavan.kumar.linga@intel.com>
Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
---
drivers/net/ethernet/intel/idpf/idpf_lib.c | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/intel/idpf/idpf_lib.c b/drivers/net/ethernet/intel/idpf/idpf_lib.c
index aa755dedb41d..329ba53e86fd 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_lib.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_lib.c
@@ -1132,11 +1132,9 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,
num_max_q = max(max_q->max_txq, max_q->max_rxq);
vport->q_vector_idxs = kcalloc(num_max_q, sizeof(u16), GFP_KERNEL);
- if (!vport->q_vector_idxs) {
- kfree(vport);
+ if (!vport->q_vector_idxs)
+ goto free_vport;
- return NULL;
- }
idpf_vport_init(vport, max_q);
/* This alloc is done separate from the LUT because it's not strictly
@@ -1146,11 +1144,9 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,
*/
rss_data = &adapter->vport_config[idx]->user_config.rss_data;
rss_data->rss_key = kzalloc(rss_data->rss_key_size, GFP_KERNEL);
- if (!rss_data->rss_key) {
- kfree(vport);
+ if (!rss_data->rss_key)
+ goto free_vector_idxs;
- return NULL;
- }
/* Initialize default rss key */
netdev_rss_key_fill((void *)rss_data->rss_key, rss_data->rss_key_size);
@@ -1163,6 +1159,13 @@ static struct idpf_vport *idpf_vport_alloc(struct idpf_adapter *adapter,
adapter->next_vport = idpf_get_free_slot(adapter);
return vport;
+
+free_vector_idxs:
+ kfree(vport->q_vector_idxs);
+free_vport:
+ kfree(vport);
+
+ return NULL;
}
/**
--
2.42.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH iwl-net v1] idpf: fix potential memory leak on kcalloc() failure
2025-04-04 10:54 [PATCH iwl-net v1] idpf: fix potential memory leak on kcalloc() failure Michal Swiatkowski
@ 2025-04-07 10:43 ` Simon Horman
2025-04-10 22:04 ` [Intel-wired-lan] " Tony Nguyen
2025-04-11 5:09 ` Michal Swiatkowski
2025-04-25 16:49 ` [Intel-wired-lan] " Salin, Samuel
1 sibling, 2 replies; 7+ messages in thread
From: Simon Horman @ 2025-04-07 10:43 UTC (permalink / raw)
To: Michal Swiatkowski
Cc: intel-wired-lan, netdev, Pavan Kumar Linga, Aleksandr Loktionov
On Fri, Apr 04, 2025 at 12:54:21PM +0200, Michal Swiatkowski wrote:
> In case of failing on rss_data->rss_key allocation the function is
> freeing vport without freeing earlier allocated q_vector_idxs. Fix it.
>
> Move from freeing in error branch to goto scheme.
>
> Fixes: 95af467d9a4e ("idpf: configure resources for RX queues")
Hi Michal,
WRT leaking q_vector_indxs, that allocation is not present at
the commit cited above, so I think the correct Fixes tag for
that problem is the following, where that allocation was added:
Fixes: d4d558718266 ("idpf: initialize interrupts and enable vport")
I do note that adapter->vport_config[idx] may be allocated but
not freed on error in idpf_vport_alloc(). But I assume that this
is not a leak as it will eventually be cleaned up by idpf_remove().
So the Fixes tag not withstanding this looks good to me.
Reviewed-by: Simon Horman <horms@kernel.org>
> Reviewed-by: Pavan Kumar Linga <pavan.kumar.linga@intel.com>
> Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
> Suggested-by: Pavan Kumar Linga <pavan.kumar.linga@intel.com>
> Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
...
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Intel-wired-lan] [PATCH iwl-net v1] idpf: fix potential memory leak on kcalloc() failure
2025-04-07 10:43 ` Simon Horman
@ 2025-04-10 22:04 ` Tony Nguyen
2025-04-11 5:09 ` Michal Swiatkowski
2025-04-11 5:09 ` Michal Swiatkowski
1 sibling, 1 reply; 7+ messages in thread
From: Tony Nguyen @ 2025-04-10 22:04 UTC (permalink / raw)
To: Simon Horman, Michal Swiatkowski
Cc: intel-wired-lan, netdev, Pavan Kumar Linga, Aleksandr Loktionov
On 4/7/2025 3:43 AM, Simon Horman wrote:
> On Fri, Apr 04, 2025 at 12:54:21PM +0200, Michal Swiatkowski wrote:
>> In case of failing on rss_data->rss_key allocation the function is
>> freeing vport without freeing earlier allocated q_vector_idxs. Fix it.
>>
>> Move from freeing in error branch to goto scheme.
>>
>> Fixes: 95af467d9a4e ("idpf: configure resources for RX queues")
>
> Hi Michal,
>
> WRT leaking q_vector_indxs, that allocation is not present at
> the commit cited above, so I think the correct Fixes tag for
> that problem is the following, where that allocation was added:
>
> Fixes: d4d558718266 ("idpf: initialize interrupts and enable vport")
Patch applied. I do agree with Simon's assessment so plan to use this fixes.
Thanks,
Tony
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH iwl-net v1] idpf: fix potential memory leak on kcalloc() failure
2025-04-07 10:43 ` Simon Horman
2025-04-10 22:04 ` [Intel-wired-lan] " Tony Nguyen
@ 2025-04-11 5:09 ` Michal Swiatkowski
2025-04-11 15:51 ` Simon Horman
1 sibling, 1 reply; 7+ messages in thread
From: Michal Swiatkowski @ 2025-04-11 5:09 UTC (permalink / raw)
To: Simon Horman
Cc: Michal Swiatkowski, intel-wired-lan, netdev, Pavan Kumar Linga,
Aleksandr Loktionov
On Mon, Apr 07, 2025 at 11:43:50AM +0100, Simon Horman wrote:
> On Fri, Apr 04, 2025 at 12:54:21PM +0200, Michal Swiatkowski wrote:
> > In case of failing on rss_data->rss_key allocation the function is
> > freeing vport without freeing earlier allocated q_vector_idxs. Fix it.
> >
> > Move from freeing in error branch to goto scheme.
> >
> > Fixes: 95af467d9a4e ("idpf: configure resources for RX queues")
>
> Hi Michal,
>
> WRT leaking q_vector_indxs, that allocation is not present at
> the commit cited above, so I think the correct Fixes tag for
> that problem is the following, where that allocation was added:
>
> Fixes: d4d558718266 ("idpf: initialize interrupts and enable vport")
Thanks for checking that. I agree, my fixes is wrong.
>
> I do note that adapter->vport_config[idx] may be allocated but
> not freed on error in idpf_vport_alloc(). But I assume that this
> is not a leak as it will eventually be cleaned up by idpf_remove().
Right, it will be better to free it directly for better readable.
Probably candidate for net-next changes.
>
> So the Fixes tag not withstanding this looks good to me.
>
> Reviewed-by: Simon Horman <horms@kernel.org>
>
Thanks for review.
> > Reviewed-by: Pavan Kumar Linga <pavan.kumar.linga@intel.com>
> > Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
> > Suggested-by: Pavan Kumar Linga <pavan.kumar.linga@intel.com>
> > Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
>
> ...
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [Intel-wired-lan] [PATCH iwl-net v1] idpf: fix potential memory leak on kcalloc() failure
2025-04-10 22:04 ` [Intel-wired-lan] " Tony Nguyen
@ 2025-04-11 5:09 ` Michal Swiatkowski
0 siblings, 0 replies; 7+ messages in thread
From: Michal Swiatkowski @ 2025-04-11 5:09 UTC (permalink / raw)
To: Tony Nguyen
Cc: Simon Horman, Michal Swiatkowski, intel-wired-lan, netdev,
Pavan Kumar Linga, Aleksandr Loktionov
On Thu, Apr 10, 2025 at 03:04:16PM -0700, Tony Nguyen wrote:
> On 4/7/2025 3:43 AM, Simon Horman wrote:
> > On Fri, Apr 04, 2025 at 12:54:21PM +0200, Michal Swiatkowski wrote:
> > > In case of failing on rss_data->rss_key allocation the function is
> > > freeing vport without freeing earlier allocated q_vector_idxs. Fix it.
> > >
> > > Move from freeing in error branch to goto scheme.
> > >
> > > Fixes: 95af467d9a4e ("idpf: configure resources for RX queues")
> >
> > Hi Michal,
> >
> > WRT leaking q_vector_indxs, that allocation is not present at
> > the commit cited above, so I think the correct Fixes tag for
> > that problem is the following, where that allocation was added:
> >
> > Fixes: d4d558718266 ("idpf: initialize interrupts and enable vport")
>
> Patch applied. I do agree with Simon's assessment so plan to use this fixes.
>
Thanks Tony, I also agree.
> Thanks,
> Tony
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH iwl-net v1] idpf: fix potential memory leak on kcalloc() failure
2025-04-11 5:09 ` Michal Swiatkowski
@ 2025-04-11 15:51 ` Simon Horman
0 siblings, 0 replies; 7+ messages in thread
From: Simon Horman @ 2025-04-11 15:51 UTC (permalink / raw)
To: Michal Swiatkowski
Cc: intel-wired-lan, netdev, Pavan Kumar Linga, Aleksandr Loktionov
On Fri, Apr 11, 2025 at 07:09:12AM +0200, Michal Swiatkowski wrote:
> On Mon, Apr 07, 2025 at 11:43:50AM +0100, Simon Horman wrote:
> > On Fri, Apr 04, 2025 at 12:54:21PM +0200, Michal Swiatkowski wrote:
> > > In case of failing on rss_data->rss_key allocation the function is
> > > freeing vport without freeing earlier allocated q_vector_idxs. Fix it.
> > >
> > > Move from freeing in error branch to goto scheme.
> > >
> > > Fixes: 95af467d9a4e ("idpf: configure resources for RX queues")
> >
> > Hi Michal,
> >
> > WRT leaking q_vector_indxs, that allocation is not present at
> > the commit cited above, so I think the correct Fixes tag for
> > that problem is the following, where that allocation was added:
> >
> > Fixes: d4d558718266 ("idpf: initialize interrupts and enable vport")
>
> Thanks for checking that. I agree, my fixes is wrong.
>
> >
> > I do note that adapter->vport_config[idx] may be allocated but
> > not freed on error in idpf_vport_alloc(). But I assume that this
> > is not a leak as it will eventually be cleaned up by idpf_remove().
>
> Right, it will be better to free it directly for better readable.
> Probably candidate for net-next changes.
Thanks, that does sound like a nice idea.
...
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [Intel-wired-lan] [PATCH iwl-net v1] idpf: fix potential memory leak on kcalloc() failure
2025-04-04 10:54 [PATCH iwl-net v1] idpf: fix potential memory leak on kcalloc() failure Michal Swiatkowski
2025-04-07 10:43 ` Simon Horman
@ 2025-04-25 16:49 ` Salin, Samuel
1 sibling, 0 replies; 7+ messages in thread
From: Salin, Samuel @ 2025-04-25 16:49 UTC (permalink / raw)
To: Michal Swiatkowski, intel-wired-lan@lists.osuosl.org
Cc: netdev@vger.kernel.org, Linga, Pavan Kumar, Loktionov, Aleksandr
> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf Of
> Michal Swiatkowski
> Sent: Friday, April 4, 2025 3:54 AM
> To: intel-wired-lan@lists.osuosl.org
> Cc: netdev@vger.kernel.org; Michal Swiatkowski
> <michal.swiatkowski@linux.intel.com>; Linga, Pavan Kumar
> <pavan.kumar.linga@intel.com>; Loktionov, Aleksandr
> <aleksandr.loktionov@intel.com>
> Subject: [Intel-wired-lan] [PATCH iwl-net v1] idpf: fix potential memory leak
> on kcalloc() failure
>
> In case of failing on rss_data->rss_key allocation the function is freeing vport
> without freeing earlier allocated q_vector_idxs. Fix it.
>
> Move from freeing in error branch to goto scheme.
>
> Fixes: 95af467d9a4e ("idpf: configure resources for RX queues")
> Reviewed-by: Pavan Kumar Linga <pavan.kumar.linga@intel.com>
> Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>
> Suggested-by: Pavan Kumar Linga <pavan.kumar.linga@intel.com>
> Signed-off-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
> ---
> 2.42.0
Tested-by: Samuel Salin <Samuel.salin@intel.com>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-04-25 16:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-04 10:54 [PATCH iwl-net v1] idpf: fix potential memory leak on kcalloc() failure Michal Swiatkowski
2025-04-07 10:43 ` Simon Horman
2025-04-10 22:04 ` [Intel-wired-lan] " Tony Nguyen
2025-04-11 5:09 ` Michal Swiatkowski
2025-04-11 5:09 ` Michal Swiatkowski
2025-04-11 15:51 ` Simon Horman
2025-04-25 16:49 ` [Intel-wired-lan] " Salin, Samuel
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).