From: 黄高彬 <huanggaobin23@semi.ac.cn>
To: "Richard Cheng" <icheng@nvidia.com>
Cc: linux-cxl@vger.kernel.org, "Davidlohr Bueso" <dave@stgolabs.net>,
"Jonathan Cameron" <jic23@kernel.org>,
"Dave Jiang" <dave.jiang@intel.com>,
"Alison Schofield" <alison.schofield@intel.com>,
"Vishal Verma" <vishal.l.verma@intel.com>,
"Dan Williams" <djbw@kernel.org>,
"Li Ming" <ming.li@zohomail.com>,
linux-kernel@vger.kernel.org, "Anisa Su" <anisa.su887@gmail.com>
Subject: Re: Re: [PATCH v2] cxl/mbox: bound the Get Supported Logs entry count by the payload
Date: Tue, 29 Sep 2026 14:15:31 +0800 (GMT+08:00) [thread overview]
Message-ID: <7fe55f2c.2a158.1a0ebcdda1a.Coremail.huanggaobin23@semi.ac.cn> (raw)
In-Reply-To: <arDU-kTVCa4z8C8l@MWDK4CY14F>
Hi Richard,
Thank you, and sorry for the slow turn-around -- both suggestions are in v3,
and the spec pointer settles the clamping-versus-rejecting question rather
than just making rejecting safer.
> I would suggest to keep the signature and do the check here instead.
> cxl_get_gsl() issues the command, owns the buffer and already has the
> kvfree()/ERR_PTR error path. Then the caller doesn't need to know the header
> size or the entry size, and gsl->entries can be trusted by whoever uses the
> struct.
Agreed, and that is where v3 puts it. cxl_enumerate_cmds() is now unchanged
from mainline:
mbox_cmd = (struct cxl_mbox_cmd) {
.opcode = CXL_MBOX_OP_GET_SUPPORTED_LOGS,
.size_out = cxl_mbox->payload_size,
.payload_out = ret,
/* At least the header must be valid */
.min_out = struct_size(ret, entry, 0),
};
rc = cxl_internal_send_cmd(cxl_mbox, &mbox_cmd);
if (rc < 0) {
kvfree(ret);
return ERR_PTR(rc);
}
max_entries = (mbox_cmd.size_out - struct_size(ret, entry, 0)) /
sizeof(ret->entry[0]);
if (le16_to_cpu(ret->entries) > max_entries) {
dev_err(mds->cxlds.dev,
"GSL: device claimed %u entries but the payload holds %zu\n",
le16_to_cpu(ret->entries), max_entries);
kvfree(ret);
return ERR_PTR(-EIO);
}
> .min_out = 2 is the only min_out in the tree that's not a full header.
> Raising it to struct_size(ret, entry, 0) lets cxl_internal_send_cmd() reject
> the short response with -EIO, so the "too short for the header" part can
> go away.
Taken. The subtraction cannot underflow once min_out guarantees the header,
so the guard around it is gone too, and it matches the two users already in
this file (struct_size(payload, records, 0) and struct_size(po, record, 0)).
> The only kvfree() is at "out" section, directly return here would leak
> gsl.
That was mine, in v2. Moving the check into cxl_get_gsl() removes the path
instead of repairing it. sashiko reported the same leak on v2.
> Agree with Alison and Jonathan, don't clamp here.
> CXL r4.0 Section 8.2.10.5.1 Get Supported Logs, Table 8-249 ... defines
> "Number of Supported Logs Entries" as "the number of Supported Log Entries
> returned in the output payload".
> It's not total, so a counter larger than what arrived is a malformed
> response, not a partial list.
Thank you for the citation. It is in the commit message now, because it is
what makes rejecting the right answer rather than merely the safer one.
> About -EIO v.s. -ENXIO, I would go with -EIO.
-EIO it is, and it is now literally cxl_internal_send_cmd()'s payload size
mismatch error rather than a choice made here.
v3:
https://lore.kernel.org/all/20260929060610.3549718-1-huanggaobin23@semi.ac.cn/
Gaobin
prev parent reply other threads:[~2026-09-29 6:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-17 10:46 Gaobin Huang
2026-09-17 23:41 ` Alison Schofield
2026-09-18 19:32 ` Jonathan Cameron
2026-09-29 6:14 ` 黄高彬
2026-09-21 7:29 ` Richard Cheng
2026-09-29 6:15 ` 黄高彬 [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=7fe55f2c.2a158.1a0ebcdda1a.Coremail.huanggaobin23@semi.ac.cn \
--to=huanggaobin23@semi.ac.cn \
--cc=alison.schofield@intel.com \
--cc=anisa.su887@gmail.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=djbw@kernel.org \
--cc=icheng@nvidia.com \
--cc=jic23@kernel.org \
--cc=linux-cxl@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®