Skip to content

media: uvcvideo: harden the frame buffer size computation

Natasha Klaus linux-media lkml stable 4 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest3 patches 0 repliesNew
  2. v33 patches 4 repliesSuperseded
  3. v23 patches 1 replySuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v13 patches3 repliesSuperseded

Changes in v4 from the cover letter

- 2/3: >> 3 instead of DIV_ROUND_UP_ULL. Per Laurent on v3 2/3, width * bpp is a multiple of 8 on real devices. Keeps the stable fix minimal.
- 2/3 and 3/3 changelogs say how each case was found.
- No Assisted-by tag: removed from the docs in 1e035297ffda. Tool use is in this cover letter instead.
- Rebased onto d135ab453a74.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3media: uvcvideo: Let uvc_parse_frame() report a skipped framedrivers/media/usb/uvc/uvc_driver.c+10 -100 replies
2/3media: uvcvideo: Fix integer overflow in frame buffer size calculationdrivers/media/usb/uvc/uvc_driver.c+15 -30 replies
3/3media: uvcvideo: Skip frame descriptors with a zero computed sizedrivers/media/usb/uvc/uvc_driver.c+14 -00 replies

Reviews trailers per patch

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

PatchRicardo RibaldaNoam Ben Shimon
1/3R-b T-b
2/3R-b T-b
3/3R-b T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v4 thread

Cover letter [PATCH v4 0/3] media: uvcvideo: harden the frame buffer size computation

uvc_parse_frame() computes dwMaxVideoFrameBufferSize as bpp * wWidth * wHeight / 8 in int, from unvalidated descriptor fields. The product wraps; the stored size is wrong and can be zero.

1/3 lets uvc_parse_frame() skip one frame descriptor instead of failing the whole streaming interface (Ricardo's suggestion). 2/3 is Noam's overflow fix, adapted to skip.
3/3 skips a frame whose computed size is zero.

Stable: 1/3 carries Cc: stable without Fixes: because 2/3 needs it. Both or neither.

Testing: Noam, UVC gadget over dummy_hcd, on v3 code; the >> 3 in 2/3 does not change the result for his inputs. No physical camera. -ENODATA path not exercised. Builds W=1 on x86_64 and i386 allmodconfig.

Tools: prepared with Claude Code. It applied Ricardo's design in 1/3 and fixed the build, wrote the code and comment in 3/3 and found that case, drafted the commit messages and notes from my outline, and did the call path analysis. I reviewed and built everything. 2/3 is Noam's; he found the overflow with Claude's help and wrote the fix by hand (confirmed off-list).

v3: https://lore.kernel.org/linux-media/[email protected]/

Changes in v4:
- 2/3: >> 3 instead of DIV_ROUND_UP_ULL. Per Laurent on v3 2/3, width * bpp is a multiple of 8 on real devices. Keeps the stable fix minimal.
- 2/3 and 3/3 changelogs say how each case was found.
- No Assisted-by tag: removed from the docs in 1e035297ffda. Tool use is in this cover letter instead.
- Rebased onto d135ab453a74.

Changes in v3:
- Tested-by from Noam on all three.

Changes in v2:
- 1/3: check -ENODATA before counting the frame (Ricardo).
- 2/3: DIV_ROUND_UP -> DIV_ROUND_UP_ULL (Ricardo).
- Reviewed-by from Ricardo on all three.

Natasha Klaus (2):
media: uvcvideo: Let uvc_parse_frame() report a skipped frame
media: uvcvideo: Skip frame descriptors with a zero computed size

Noam Ben Shimon (1):
media: uvcvideo: Fix integer overflow in frame buffer size calculation

 drivers/media/usb/uvc/uvc_driver.c | 52 ++++++++++++++++++++++--------
 1 file changed, 39 insertions(+), 13 deletions(-)

base-commit: d135ab453a7400a34930bdda1ef4bdc8acfac80e

Signature · 1 line
2.34.1