]> git.ipfire.org Git - thirdparty/linux.git/commit
cxl: Check for invalid addresses returned from translation functions on errors
authorRobert Richter <rrichter@amd.com>
Wed, 7 Jan 2026 12:05:43 +0000 (13:05 +0100)
committerDave Jiang <dave.jiang@intel.com>
Tue, 13 Jan 2026 15:30:40 +0000 (08:30 -0700)
commit8441c7d3bd6c5a52ab2ecf77e43a5bf262004f5c
tree474b580b1e58bc4c009317b12b19bd913ab8f4ab
parentd4026a44626490dc4eca4dd2c4d0816338fa179b
cxl: Check for invalid addresses returned from translation functions on errors

Translation functions may return an invalid address in case of errors.
If the address is not checked the further use of the invalid value
will cause an address corruption.

Consistently check for a valid address returned by translation
functions. Use RESOURCE_SIZE_MAX to indicate an invalid address for
type resource_size_t. Depending on the type either RESOURCE_SIZE_MAX
or ULLONG_MAX is used to indicate an address error.

Propagating an invalid address from a failed translation may cause
userspace to think it has received a valid SPA, when in fact it is
wrong. The CXL userspace API, using trace events, expects ULLONG_MAX
to indicate a translation failure. If ULLONG_MAX is not returned
immediately, subsequent calculations can transform that bad address
into a different value (!ULLONG_MAX), and an invalid SPA may be
returned to userspace. This can lead to incorrect diagnostics and
erroneous corrective actions.

[ dj: Added user impact statement from Alison. ]
[ dj: Fixed checkpatch tab alignment issue. ]

Reviewed-by: Dave Jiang <dave.jiang@intel.com>
Signed-off-by: Robert Richter <rrichter@amd.com>
Fixes: c3dd67681c70 ("cxl/region: Add inject and clear poison by region offset")
Fixes: b78b9e7b7979 ("cxl/region: Refactor address translation funcs for testing")
Reviewed-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Link: https://patch.msgid.link/20260107120544.410993-1-rrichter@amd.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>
drivers/cxl/core/hdm.c
drivers/cxl/core/region.c
tools/testing/cxl/test/cxl_translate.c