From: Dave Jiang <dave.jiang@intel.com>
To: Ashok Raj <ashok.raj@oss.qualcomm.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Jonathan Cameron <jic23@kernel.org>,
Alison Schofield <alison.schofield@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Dan Williams <djbw@kernel.org>, Ira Weiny <iweiny@kernel.org>,
Li Ming <ming.li@zohomail.com>, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [RESEND PATCH] cxl/features: Ensure that count is set before access to end[] __counted_by()
Date: Fri, 11 Sep 2026 16:59:41 -0700 [thread overview]
Message-ID: <753afbb6-c236-47e9-b48f-d7f9567deb2c@intel.com> (raw)
In-Reply-To: <20260911215304.1816467-1-ashok.raj@oss.qualcomm.com>
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);
prev parent reply other threads:[~2026-09-11 23:59 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-11 21:53 Ashok Raj
2026-09-11 21:58 ` Dave Jiang
2026-09-11 22:44 ` Jonathan Cameron
2026-09-11 23:59 ` Dave Jiang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=753afbb6-c236-47e9-b48f-d7f9567deb2c@intel.com \
--to=dave.jiang@intel.com \
--cc=alison.schofield@intel.com \
--cc=ashok.raj@oss.qualcomm.com \
--cc=dave@stgolabs.net \
--cc=djbw@kernel.org \
--cc=gustavoars@kernel.org \
--cc=iweiny@kernel.org \
--cc=jic23@kernel.org \
--cc=kees@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.li@zohomail.com \
--cc=vishal.l.verma@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®