FAILED: patch "[PATCH] qed: fix double free in qed_cxt_tables_alloc()" failed to apply to 5.15-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x 2bccfb8476ca5f3548afbd623dc7a6980d4e77de
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026052808-multitask-shelf-9b39@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 2bccfb8476ca5f3548afbd623dc7a6980d4e77de Mon Sep 17 00:00:00 2001
From: Dawei Feng <[email protected]>
Date: Wed, 20 May 2026 15:03:23 +0800
Subject: [PATCH] qed: fix double free in qed_cxt_tables_alloc()
If one of the later PF or VF CID bitmap allocations fails, qed_cid_map_alloc() jumps to cid_map_fail and frees the previously allocated CID bitmaps before returning an error. qed_cxt_tables_alloc() then calls qed_cxt_mngr_free(), which invokes qed_cid_map_free() again.
Fix this by setting each CID bitmap pointer to NULL after bitmap_free() to avoid double free.
The bug was first flagged by an experimental analysis tool we are developing for kernel memory-management bugs while analyzing v6.13-rc1. The tool is still under development and is not yet publicly available. Manual inspection confirms that the bug is still present in v7.1-rc3.
Runtime reproduction was not attempted because exercising the failing allocation path requires device-specific setup.
drivers/net/ethernet/qlogic/qed/qed_cxt.c +2 -0
@@ -1036,11 +1036,13 @@ static void qed_cid_map_free(struct qed_hwfn *p_hwfn)for (type =0 ; type <MAX_CONN_TYPES ; type++) {bitmap_free (p_mngr->acquired[type].cid_map); + p_mngr->acquired[type].cid_map =NULL ; p_mngr->acquired[type].max_count =0 ; p_mngr->acquired[type].start_cid =0 ;for (vf =0 ; vf <MAX_NUM_VFS ; vf++) {bitmap_free (p_mngr->acquired_vf[type][vf].cid_map); + p_mngr->acquired_vf[type][vf].cid_map =NULL ; p_mngr->acquired_vf[type][vf].max_count =0 ; p_mngr->acquired_vf[type][vf].start_cid =0 ; }
Sasha Levin
maintainerPATCH 1/2 qed: Use the bitmap API to simplify some functions
From: Christophe JAILLET <[email protected]>
[ Upstream commit 5e6c7ccd3ea4b25dd6b4b0363859913f315deacb ]
'cid_map' is a bitmap. So use 'bitmap_zalloc()' to simplify code, improve the semantic and avoid some open-coded arithmetic in allocator arguments.
Also change the corresponding 'kfree()' into 'bitmap_free()' to keep consistency.
Also change some 'memset()' into 'bitmap_zero()' to keep consistency. This is also much less verbose.
Stable-dep-of: 2bccfb8476ca ("qed: fix double free in qed_cxt_tables_alloc()")
--- drivers/net/ethernet/qlogic/qed/qed_cxt.c | 24 +++++------------------ 1 file changed, 5 insertions(+), 19 deletions(-)
drivers/net/ethernet/qlogic/qed/qed_cxt.c +5 -19
@@ -1037,12 +1037,12 @@ static void qed_cid_map_free(struct qed_hwfn *p_hwfn)u32 type, vf;for (type =0 ; type <MAX_CONN_TYPES ; type++) { -kfree (p_mngr->acquired[type].cid_map); +bitmap_free (p_mngr->acquired[type].cid_map); p_mngr->acquired[type].max_count =0 ; p_mngr->acquired[type].start_cid =0 ;for (vf =0 ; vf <MAX_NUM_VFS ; vf++) { -kfree (p_mngr->acquired_vf[type][vf].cid_map); +bitmap_free (p_mngr->acquired_vf[type][vf].cid_map); p_mngr->acquired_vf[type][vf].max_count =0 ; p_mngr->acquired_vf[type][vf].start_cid =0 ; }
@@ -1055,15 +1055,10 @@ qed_cid_map_alloc_single(struct qed_hwfn *p_hwfn,u32 cid_start, u32 cid_count, struct qed_cid_acquired_map *p_map) { - u32 size; - if (!cid_count) return 0; - size =DIV_ROUND_UP (cid_count, -sizeof (unsigned long ) *BITS_PER_BYTE ) * -sizeof (unsigned long ); - p_map->cid_map =kzalloc (size,GFP_KERNEL ); + p_map->cid_map = bitmap_zalloc(cid_count, GFP_KERNEL);if (!p_map->cid_map)return -ENOMEM ;
@@ -1217,7 +1212,6 @@ void qed_cxt_mngr_setup(struct qed_hwfn *p_hwfn)struct qed_cid_acquired_map *p_map;struct qed_conn_type_cfg *p_cfg;int type; -u32 len;/* Reset acquired cids */ for (type =0 ; type <MAX_CONN_TYPES ; type++) {
@@ -1226,11 +1220,7 @@ void qed_cxt_mngr_setup(struct qed_hwfn *p_hwfn) p_cfg = &p_mngr->conn_cfg[type];if (p_cfg->cid_count) { p_map = &p_mngr->acquired[type]; - len =DIV_ROUND_UP (p_map->max_count, -sizeof (unsigned long ) * -BITS_PER_BYTE ) * -sizeof (unsigned long ); -memset (p_map->cid_map,0 , len); +bitmap_zero (p_map->cid_map, p_map->max_count); }if (!p_cfg->cids_per_vf)
@@ -1238,11 +1228,7 @@ void qed_cxt_mngr_setup(struct qed_hwfn *p_hwfn)for (vf =0 ; vf <MAX_NUM_VFS ; vf++) { p_map = &p_mngr->acquired_vf[type][vf]; - len =DIV_ROUND_UP (p_map->max_count, -sizeof (unsigned long ) * -BITS_PER_BYTE ) * -sizeof (unsigned long ); -memset (p_map->cid_map,0 , len); +bitmap_zero (p_map->cid_map, p_map->max_count); } } }
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/2 qed: fix double free in qed_cxt_tables_alloc()
From: Dawei Feng <[email protected]>
[ Upstream commit 2bccfb8476ca5f3548afbd623dc7a6980d4e77de ]
If one of the later PF or VF CID bitmap allocations fails, qed_cid_map_alloc() jumps to cid_map_fail and frees the previously allocated CID bitmaps before returning an error. qed_cxt_tables_alloc() then calls qed_cxt_mngr_free(), which invokes qed_cid_map_free() again.
Fix this by setting each CID bitmap pointer to NULL after bitmap_free() to avoid double free.
The bug was first flagged by an experimental analysis tool we are developing for kernel memory-management bugs while analyzing v6.13-rc1. The tool is still under development and is not yet publicly available. Manual inspection confirms that the bug is still present in v7.1-rc3.
Runtime reproduction was not attempted because exercising the failing allocation path requires device-specific setup.
--- drivers/net/ethernet/qlogic/qed/qed_cxt.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/ethernet/qlogic/qed/qed_cxt.c +2 -0
@@ -1038,11 +1038,13 @@ static void qed_cid_map_free(struct qed_hwfn *p_hwfn)for (type =0 ; type <MAX_CONN_TYPES ; type++) {bitmap_free (p_mngr->acquired[type].cid_map); + p_mngr->acquired[type].cid_map =NULL ; p_mngr->acquired[type].max_count =0 ; p_mngr->acquired[type].start_cid =0 ;for (vf =0 ; vf <MAX_NUM_VFS ; vf++) {bitmap_free (p_mngr->acquired_vf[type][vf].cid_map); + p_mngr->acquired_vf[type][vf].cid_map =NULL ; p_mngr->acquired_vf[type][vf].max_count =0 ; p_mngr->acquired_vf[type][vf].start_cid =0 ; }
Signature · 1 line
2.53.0