All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Richard Cheng" <icheng@nvidia.com>
Cc: linux-cxl@vger.kernel.org
Subject: Re: [PATCH v8 1/3] cxl/region: Simplify poison_by_decoder() error handling
Date: Fri, 31 Jul 2026 07:04:46 +0000	[thread overview]
Message-ID: <20260731070446.E01A81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260731064902.34127-2-icheng@nvidia.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Array out-of-bounds read when `cxled->part` is -1.
- [High] Silent error masking in `cxl_get_poison_by_memdev` overwrites earlier failures.
--

--- Patch [1]: [PATCH v8 1/3] cxl/region: Simplify poison_by_decoder() error handling ---
commit 091367d84a5db5147f3a65c244b70983d67217ac
Author: Richard Cheng <icheng@nvidia.com>

cxl/region: Simplify poison_by_decoder() error handling

"rc" carries both an error code and the loop control signal for
device_for_each_child(), so returning it bare is misleading, the early
guards mean "keep walking", not "no error". Zeroing "rc" to forgive an
-EFAULT on a RAM partition adds to that by discarding what the device
actually returned.

> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 1e211542b6b64..fabaad3469b1b 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -2950,14 +2950,14 @@ static int poison_by_decoder(struct device *dev, void *arg)
>  	struct cxl_dev_state *cxlds;
>  	struct cxl_memdev *cxlmd;
>  	u64 offset, length;
> -	int rc = 0;
> +	int rc;
>  
>  	if (!is_endpoint_decoder(dev))
> -		return rc;
> +		return 0;
>  
>  	cxled = to_cxl_endpoint_decoder(dev);
>  	if (!cxled->dpa_res)
> -		return rc;
> +		return 0;
>  
>  	cxlmd = cxled_to_memdev(cxled);
>  	cxlds = cxlmd->cxlds;

[Severity: High]
This isn't a bug introduced by this patch, but does the array access in
poison_by_decoder() risk an out-of-bounds read if cxled->part is -1?

If firmware provides misconfigured ACPI tables or CXL DPA resources,
cxl_dpa_alloc() might leave cxled->part as -1. A subsequent userspace read
of the trigger_poison_list sysfs attribute calls
cxl_get_poison_by_endpoint() which iterates over endpoint decoders and
evaluates:

drivers/cxl/core/region.c:poison_by_decoder() {
    ...
    cxlmd = cxled_to_memdev(cxled);
    cxlds = cxlmd->cxlds;
    mode = cxlds->part[cxled->part].mode;
    ...
}

Would this result in an invalid memory access of cxlds->part[-1]?


[Severity: High]
This is also a pre-existing issue, but does cxl_get_poison_by_memdev()
silently overwrite errors from earlier partitions?

Looking at cxl_get_poison_by_memdev() in drivers/cxl/core/memdev.c:

drivers/cxl/core/memdev.c:cxl_get_poison_by_memdev() {
    ...
    for (int i = 0; i < cxlds->nr_partitions; i++) {
        ...
        rc = cxl_mem_get_poison(cxlmd, offset, length, NULL);
        if (rc == -EFAULT && cxlds->part[i].mode == CXL_PARTMODE_RAM)
            rc = 0;
    }
    return rc;
}

If a device fails to retrieve poison for the first partition (e.g. PMEM,
returning -ENXIO) but succeeds on a subsequent partition (e.g. RAM, returning
0), rc is overwritten to 0.

Does this permanently mask failures of earlier partitions, potentially leaving
poisoned memory undetected?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260731064902.34127-1-icheng@nvidia.com?part=1

  reply	other threads:[~2026-07-31  7:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-31  6:48 [PATCH v8 0/3] Support zero-sized HDM decoders Richard Cheng
2026-07-31  6:49 ` [PATCH v8 1/3] cxl/region: Simplify poison_by_decoder() error handling Richard Cheng
2026-07-31  7:04   ` sashiko-bot [this message]
2026-07-31  6:49 ` [PATCH v8 2/3] cxl/hdm: Allow zero sized HDM decoders Richard Cheng
2026-07-31  7:01   ` sashiko-bot
2026-07-31  6:49 ` [PATCH v8 3/3] tools/testing/cxl: Enable zero sized decoders under hb0 Richard Cheng

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=20260731070446.E01A81F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=icheng@nvidia.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.