Skip to content

cxl/features: Bounds-check the fwctl feature commands

Richard Cheng linux-cxl lkml sashiko-reviews 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 10 repliesIn review
  2. v21 patch 6 repliesSuperseded

Changes in v3 from the cover letter

- Expand the single Get Feature fix into a series that also covers the Set Feature output buffer and the Get Feature read loop.

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3cxl/features: Reject Get Feature count larger than the output bufferdrivers/cxl/core/features.c+4 -02 replies
2/3cxl/features: Reject Set Features output buffer smaller than the headerdrivers/cxl/core/features.c+3 -03 replies
3/3cxl/features: Clamp Get Feature output size to the remaining bufferdrivers/cxl/core/features.c+2 -33 replies

Reviews trailers per patch

All 3 patches have a Reviewed-by or Acked-by.

PatchKai-Heng FengKoba KoDave JiangAlison Schofield
1/3R-b R-b R-b R-b
2/3R-b R-b
3/3R-b R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 4 reviewers.

Read the v3 thread

Cover letter [PATCH v3 0/3] cxl/features: Bounds-check the fwctl feature commands

The CXL fwctl feature handlers take buffer sizes from userspace, which is out_len, and from the device without fully checking them. This series adds the missing bounds checks.

Patch 1: reject a Get Feature whose count is larger than the output
buffer.
Patch 2: reject a Set Feature whose output buffer is too small for the
reply header. A zero out_len makes kvzalloc() return ZERO_SIZE_PTR, and the header write then corrupts memory.
Patch 3: clamp the Get Feature read loop to the room left in the output
buffer, so a device that returns more than requested cannot write past it.

A related gap is fixed separately by Zhenhao Wan's patch [1].

Changes since v2:
- Expand the single Get Feature fix into a series that also covers the Set Feature output buffer and the Get Feature read loop.

[1]:
https://lore.kernel.org/all/[email protected]/

Richard Cheng (3):
cxl/features: Reject Get Feature count larger than the output buffer cxl/features: Reject Set Features output buffer smaller than the
header
cxl/features: Clamp Get Feature output size to the remaining buffer

 drivers/cxl/core/features.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

base-commit: ef0c9f75a19532d7675384708fc8621e10850104

Signature · 1 line
2.43.0