* [RESEND PATCH] cxl/features: Ensure that count is set before access to end[] __counted_by()
@ 2026-09-11 21:53 Ashok Raj
2026-09-11 21:58 ` Dave Jiang
2026-09-11 23:59 ` Dave Jiang
0 siblings, 2 replies; 4+ messages in thread
From: Ashok Raj @ 2026-09-11 21:53 UTC (permalink / raw)
To: Davidlohr Bueso, Jonathan Cameron, Dave Jiang, Alison Schofield,
Vishal Verma, Dan Williams, Ira Weiny, Li Ming, Kees Cook,
Gustavo A. R. Silva
Cc: linux-cxl, linux-kernel, linux-hardening, Ashok Raj
get_supported_features() assigns entries->num_features only after the
memcpy() loop that fills entries->ent[] has already run. Since ent[]
is __counted_by(num_features), the compiler's bounds instrumentation
sees a 0-length array during that loop and FORTIFY_SOURCE trips on
the memcpy. Set @num_features right after allocation, before any
write into ent[], so the bound is correct for the whole lifetime of
the array.
This was found via a fortify panic:
memcpy: detected buffer overflow: 384 byte write of buffer size 0
WARNING: lib/string_helpers.c:1035 at __fortify_report+0x54/0xa0
kernel BUG at lib/string_helpers.c:1043!
Call trace:
__fortify_panic+0x10/0x18
get_supported_features.isra.0+0x4a0/0x4d0 [cxl_core]
devm_cxl_setup_features+0x84/0x120 [cxl_core]
cxl_pci_probe+0x254/0x5e0 [cxl_pci]
Same class of bug, same fix shape as commit 6c9d2e87df40
("cxl/fwctl: Fix __fortify_panic"), which fixed the analogous issue
in cxlctl_get_supported_features() but missed this one.
Fixes: f0e6a2329bf9 ("cxl: Add Get Supported Features command for kernel usage")
Signed-off-by: Ashok Raj <ashok.raj@oss.qualcomm.com>
---
RESEND: Dropped the mailing lists (linux-cxl, linux-kernel) from Cc
by mistake on the first send. Resending with proper Cc.
drivers/cxl/core/features.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/cxl/core/features.c b/drivers/cxl/core/features.c
index ba6d2a5acb74..754fe5eb4b76 100644
--- a/drivers/cxl/core/features.c
+++ b/drivers/cxl/core/features.c
@@ -97,6 +97,7 @@ get_supported_features(struct cxl_features_state *cxlfs)
kvmalloc_flex(*entries, ent, count);
if (!entries)
return NULL;
+ entries->num_features = count;
struct cxl_mbox_get_sup_feats_out *mbox_out __free(kvfree) =
kvmalloc(cxl_mbox->payload_size, GFP_KERNEL);
@@ -174,7 +175,6 @@ get_supported_features(struct cxl_features_state *cxlfs)
start += num_entries;
} while (remain_feats);
- entries->num_features = count;
entries->num_user_features = user_feats;
return no_free_ptr(entries);
--
2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RESEND PATCH] cxl/features: Ensure that count is set before access to end[] __counted_by()
2026-09-11 21:53 [RESEND PATCH] cxl/features: Ensure that count is set before access to end[] __counted_by() Ashok Raj
@ 2026-09-11 21:58 ` Dave Jiang
2026-09-11 22:44 ` Jonathan Cameron
2026-09-11 23:59 ` Dave Jiang
1 sibling, 1 reply; 4+ messages in thread
From: Dave Jiang @ 2026-09-11 21:58 UTC (permalink / raw)
To: Ashok Raj, Davidlohr Bueso, Jonathan Cameron, Alison Schofield,
Vishal Verma, Dan Williams, Ira Weiny, Li Ming, Kees Cook,
Gustavo A. R. Silva
Cc: linux-cxl, linux-kernel, linux-hardening
On 9/11/26 2:53 PM, Ashok Raj wrote:
> get_supported_features() assigns entries->num_features only after the
> memcpy() loop that fills entries->ent[] has already run. Since ent[]
> is __counted_by(num_features), the compiler's bounds instrumentation
> sees a 0-length array during that loop and FORTIFY_SOURCE trips on
> the memcpy. Set @num_features right after allocation, before any
> write into ent[], so the bound is correct for the whole lifetime of
> the array.
>
> This was found via a fortify panic:
>
> memcpy: detected buffer overflow: 384 byte write of buffer size 0
> WARNING: lib/string_helpers.c:1035 at __fortify_report+0x54/0xa0
> kernel BUG at lib/string_helpers.c:1043!
> Call trace:
> __fortify_panic+0x10/0x18
> get_supported_features.isra.0+0x4a0/0x4d0 [cxl_core]
> devm_cxl_setup_features+0x84/0x120 [cxl_core]
> cxl_pci_probe+0x254/0x5e0 [cxl_pci]
>
> Same class of bug, same fix shape as commit 6c9d2e87df40
> ("cxl/fwctl: Fix __fortify_panic"), which fixed the analogous issue
> in cxlctl_get_supported_features() but missed this one.
>
> Fixes: f0e6a2329bf9 ("cxl: Add Get Supported Features command for kernel usage")
> Signed-off-by: Ashok Raj <ashok.raj@oss.qualcomm.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> RESEND: Dropped the mailing lists (linux-cxl, linux-kernel) from Cc
> by mistake on the first send. Resending with proper Cc.
>
> drivers/cxl/core/features.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cxl/core/features.c b/drivers/cxl/core/features.c
> index ba6d2a5acb74..754fe5eb4b76 100644
> --- a/drivers/cxl/core/features.c
> +++ b/drivers/cxl/core/features.c
> @@ -97,6 +97,7 @@ get_supported_features(struct cxl_features_state *cxlfs)
> kvmalloc_flex(*entries, ent, count);
> if (!entries)
> return NULL;
> + entries->num_features = count;
>
> struct cxl_mbox_get_sup_feats_out *mbox_out __free(kvfree) =
> kvmalloc(cxl_mbox->payload_size, GFP_KERNEL);
> @@ -174,7 +175,6 @@ get_supported_features(struct cxl_features_state *cxlfs)
> start += num_entries;
> } while (remain_feats);
>
> - entries->num_features = count;
> entries->num_user_features = user_feats;
>
> return no_free_ptr(entries);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RESEND PATCH] cxl/features: Ensure that count is set before access to end[] __counted_by()
2026-09-11 21:58 ` Dave Jiang
@ 2026-09-11 22:44 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2026-09-11 22:44 UTC (permalink / raw)
To: Dave Jiang
Cc: Ashok Raj, Davidlohr Bueso, Alison Schofield, Vishal Verma,
Dan Williams, Ira Weiny, Li Ming, Kees Cook, Gustavo A. R. Silva,
linux-cxl, linux-kernel, linux-hardening
On Fri, 11 Sep 2026 14:58:29 -0700
Dave Jiang <dave.jiang@intel.com> wrote:
Typo in patch title end/ent[]
(might be mine given I suggested a title to Ashok during internal review!)
Hopefully Dave won't mind fixing that whilst picking it up.
> On 9/11/26 2:53 PM, Ashok Raj wrote:
> > get_supported_features() assigns entries->num_features only after the
> > memcpy() loop that fills entries->ent[] has already run. Since ent[]
> > is __counted_by(num_features), the compiler's bounds instrumentation
> > sees a 0-length array during that loop and FORTIFY_SOURCE trips on
> > the memcpy. Set @num_features right after allocation, before any
> > write into ent[], so the bound is correct for the whole lifetime of
> > the array.
> >
> > This was found via a fortify panic:
> >
> > memcpy: detected buffer overflow: 384 byte write of buffer size 0
> > WARNING: lib/string_helpers.c:1035 at __fortify_report+0x54/0xa0
> > kernel BUG at lib/string_helpers.c:1043!
> > Call trace:
> > __fortify_panic+0x10/0x18
> > get_supported_features.isra.0+0x4a0/0x4d0 [cxl_core]
> > devm_cxl_setup_features+0x84/0x120 [cxl_core]
> > cxl_pci_probe+0x254/0x5e0 [cxl_pci]
> >
> > Same class of bug, same fix shape as commit 6c9d2e87df40
> > ("cxl/fwctl: Fix __fortify_panic"), which fixed the analogous issue
> > in cxlctl_get_supported_features() but missed this one.
> >
> > Fixes: f0e6a2329bf9 ("cxl: Add Get Supported Features command for kernel usage")
> > Signed-off-by: Ashok Raj <ashok.raj@oss.qualcomm.com>
>
> Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RESEND PATCH] cxl/features: Ensure that count is set before access to end[] __counted_by()
2026-09-11 21:53 [RESEND PATCH] cxl/features: Ensure that count is set before access to end[] __counted_by() Ashok Raj
2026-09-11 21:58 ` Dave Jiang
@ 2026-09-11 23:59 ` Dave Jiang
1 sibling, 0 replies; 4+ messages in thread
From: Dave Jiang @ 2026-09-11 23:59 UTC (permalink / raw)
To: Ashok Raj, Davidlohr Bueso, Jonathan Cameron, Alison Schofield,
Vishal Verma, Dan Williams, Ira Weiny, Li Ming, Kees Cook,
Gustavo A. R. Silva
Cc: linux-cxl, linux-kernel, linux-hardening
On 9/11/26 2:53 PM, Ashok Raj wrote:
> get_supported_features() assigns entries->num_features only after the
> memcpy() loop that fills entries->ent[] has already run. Since ent[]
> is __counted_by(num_features), the compiler's bounds instrumentation
> sees a 0-length array during that loop and FORTIFY_SOURCE trips on
> the memcpy. Set @num_features right after allocation, before any
> write into ent[], so the bound is correct for the whole lifetime of
> the array.
>
> This was found via a fortify panic:
>
> memcpy: detected buffer overflow: 384 byte write of buffer size 0
> WARNING: lib/string_helpers.c:1035 at __fortify_report+0x54/0xa0
> kernel BUG at lib/string_helpers.c:1043!
> Call trace:
> __fortify_panic+0x10/0x18
> get_supported_features.isra.0+0x4a0/0x4d0 [cxl_core]
> devm_cxl_setup_features+0x84/0x120 [cxl_core]
> cxl_pci_probe+0x254/0x5e0 [cxl_pci]
>
> Same class of bug, same fix shape as commit 6c9d2e87df40
> ("cxl/fwctl: Fix __fortify_panic"), which fixed the analogous issue
> in cxlctl_get_supported_features() but missed this one.
>
> Fixes: f0e6a2329bf9 ("cxl: Add Get Supported Features command for kernel usage")
> Signed-off-by: Ashok Raj <ashok.raj@oss.qualcomm.com>
Fixed title typo
Applied to cxl/next:
2cad1223081f
> ---
> RESEND: Dropped the mailing lists (linux-cxl, linux-kernel) from Cc
> by mistake on the first send. Resending with proper Cc.
>
> drivers/cxl/core/features.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cxl/core/features.c b/drivers/cxl/core/features.c
> index ba6d2a5acb74..754fe5eb4b76 100644
> --- a/drivers/cxl/core/features.c
> +++ b/drivers/cxl/core/features.c
> @@ -97,6 +97,7 @@ get_supported_features(struct cxl_features_state *cxlfs)
> kvmalloc_flex(*entries, ent, count);
> if (!entries)
> return NULL;
> + entries->num_features = count;
>
> struct cxl_mbox_get_sup_feats_out *mbox_out __free(kvfree) =
> kvmalloc(cxl_mbox->payload_size, GFP_KERNEL);
> @@ -174,7 +175,6 @@ get_supported_features(struct cxl_features_state *cxlfs)
> start += num_entries;
> } while (remain_feats);
>
> - entries->num_features = count;
> entries->num_user_features = user_feats;
>
> return no_free_ptr(entries);
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-11 23:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-11 21:53 [RESEND PATCH] cxl/features: Ensure that count is set before access to end[] __counted_by() Ashok Raj
2026-09-11 21:58 ` Dave Jiang
2026-09-11 22:44 ` Jonathan Cameron
2026-09-11 23:59 ` Dave Jiang
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®