From: Alison Schofield <alison.schofield@intel.com>
To: Yili Zhang <zhangyili01@baidu.com>
Cc: <linux-cxl@vger.kernel.org>, <djbw@kernel.org>,
<dave.jiang@intel.com>, <dave@stgolabs.net>, <jic23@kernel.org>,
<linux-kernel@vger.kernel.org>, <shiju.jose@huawei.com>,
<vishal.l.verma@intel.com>
Subject: Re: [PATCH v2] cxl/edac: Fail ECS threshold read for reserved encodings
Date: Wed, 21 Oct 2026 08:58:57 -0700 [thread overview]
Message-ID: <atjhQTk4k6On7Fcm@aschofie-mobl2.lan> (raw)
In-Reply-To: <20260930095627.32616-1-zhangyili01@baidu.com>
On Wed, Sep 30, 2026 at 05:56:27PM +0800, Yili Zhang wrote:
> cxl_get_ecs_threshold() extracts a 3-bit index (0-7) from the
> device-supplied ECS config word and uses it to index
> ecs_supp_threshold[], which only has 6 elements. A device reporting
> index 6 or 7 causes an out-of-bounds read of adjacent .rodata, whose
> value is then returned to userspace via the EDAC 'threshold' sysfs
> attribute (small info leak and wrong reported threshold).
>
> The threshold count field also has reserved encodings 0-2, which
> currently read as 0 from the sparse lookup table. That behavior is
> not intentional; it is just an artifact of the array's implicit
> zero-fill. The ABI documentation only lists 256, 1024 and 4096 as
> supported values, so rather than documenting 0 as well, make the
> read fail for all reserved encodings and only ever report the
> documented values.
>
> Convert the cxl_get_ecs_*() helpers to return an int and write the
> attribute value through an output parameter (u32 * to match the
> macro), so that errors propagate through the shared
> CXL_ECS_GET_ATTR() macro to the sysfs read.
>
> Fixes: 85fb6a16ad14 ("cxl/edac: Add CXL memory device ECS control feature")
> Suggested-by: Alison Schofield <alison.schofield@intel.com>
> Signed-off-by: Yili Zhang <zhangyili01@baidu.com>
Hi Yili,
Thanks for the updates from v1.
Just a couple of process things for v3. Drop my Suggested-by tag.
That is usually reserved for folks who suggest the actual patch,
not folks who suggest changes on v1, like I did. And, send v3 as
a new email thread, not in reply to this thread, as you did here.
-- Alison
> ---
> v2: Per review feedback, fail the read with -EINVAL for all reserved
> encodings instead of returning 0, converting the cxl_get_ecs_*()
> getters to an int return with an output parameter so the error
> reaches the sysfs read.
> ---
> drivers/cxl/core/edac.c | 26 +++++++++++++++++---------
> 1 file changed, 17 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/cxl/core/edac.c b/drivers/cxl/core/edac.c
> index b321971fef58..fd6612dde7f1 100644
> --- a/drivers/cxl/core/edac.c
> +++ b/drivers/cxl/core/edac.c
> @@ -624,21 +624,31 @@ static int cxl_mem_ecs_set_attrbs(struct device *dev,
> 0, NULL);
> }
>
> -static u8 cxl_get_ecs_log_entry_type(u8 log_cap, u16 config)
> +static int cxl_get_ecs_log_entry_type(u8 log_cap, u16 config, u32 *val)
> {
> - return FIELD_GET(CXL_ECS_LOG_ENTRY_TYPE_MASK, log_cap);
> + *val = FIELD_GET(CXL_ECS_LOG_ENTRY_TYPE_MASK, log_cap);
> +
> + return 0;
> }
>
> -static u16 cxl_get_ecs_threshold(u8 log_cap, u16 config)
> +static int cxl_get_ecs_threshold(u8 log_cap, u16 config, u32 *val)
> {
> u8 index = FIELD_GET(CXL_ECS_THRESHOLD_COUNT_MASK, config);
>
> - return ecs_supp_threshold[index];
> + if (index >= ARRAY_SIZE(ecs_supp_threshold) ||
> + !ecs_supp_threshold[index])
> + return -EINVAL;
> +
> + *val = ecs_supp_threshold[index];
> +
> + return 0;
> }
>
> -static u8 cxl_get_ecs_count_mode(u8 log_cap, u16 config)
> +static int cxl_get_ecs_count_mode(u8 log_cap, u16 config, u32 *val)
> {
> - return FIELD_GET(CXL_ECS_COUNT_MODE_MASK, config);
> + *val = FIELD_GET(CXL_ECS_COUNT_MODE_MASK, config);
> +
> + return 0;
> }
>
> #define CXL_ECS_GET_ATTR(attrb) \
> @@ -655,9 +665,7 @@ static u8 cxl_get_ecs_count_mode(u8 log_cap, u16 config)
> if (ret) \
> return ret; \
> \
> - *val = cxl_get_ecs_##attrb(log_cap, config); \
> - \
> - return 0; \
> + return cxl_get_ecs_##attrb(log_cap, config, val); \
> }
>
> CXL_ECS_GET_ATTR(log_entry_type)
> --
> 2.27.0
>
prev parent reply other threads:[~2026-10-21 15:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-28 7:35 [PATCH] cxl/edac: Bounds-check ECS threshold index from device Yili Zhang
2026-09-28 18:21 ` Dave Jiang
2026-09-29 3:17 ` Yili Zhang
2026-09-29 17:53 ` Alison Schofield
2026-09-30 9:09 ` Yili Zhang
2026-09-30 9:56 ` [PATCH v2] cxl/edac: Fail ECS threshold read for reserved encodings Yili Zhang
2026-10-20 21:27 ` Jonathan Cameron
2026-10-21 13:14 ` Yili Zhang
2026-10-21 15:58 ` Alison Schofield [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=atjhQTk4k6On7Fcm@aschofie-mobl2.lan \
--to=alison.schofield@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=djbw@kernel.org \
--cc=jic23@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shiju.jose@huawei.com \
--cc=vishal.l.verma@intel.com \
--cc=zhangyili01@baidu.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®