xserver/hw/xfree86/modes
Mario Kleiner b33f487a7c xfree86: Avoid crash in xf86RandR12CrtcSetGamma() memcpy path.
If randrp->palette_size is zero, the memcpy() path can read past the
end of the randr_crtc's gammaRed/Green/Blue tables if the hw crtc's
gamma_size is greater than the randr_crtc's gammaSize.

Avoid this by clamping the to-be-copied size to the smaller of both
sizes.

Note that during regular server startup, the memcpy() path is only
taken initially twice, but then a suitable palette is created for
use during a session. Therefore during an actual running X-Session,
the xf86RandR12CrtcComputeGamma() will be used, which makes sure that
data is properly up- or down-sampled for mismatching source and
target crtc gamma sizes.

This should avoid reading past randr_crtc gamma memory for gpu's
with big crtc->gamma_size, e.g., AMD/MALI/KOMEDA 4096 slots, or
Intel Icelake and later with 262145 slots.

Tested against modesetting-ddx and amdgpu-ddx under screen color
depth 24 (8 bpc) and 30 (10 bpc) to make sure that clamping happens
properly.

This is an alternative fix for the one attempted in commit
617f591fc4.

Signed-off-by: Mario Kleiner <mario.kleiner.de@gmail.com>
(cherry picked from commit 966f567432)
2021-10-08 21:37:53 +03:00
..
Makefile.am xfree86: Move xf86CVTMode() function 2021-08-06 11:29:29 +00:00
meson.build xfree86: Move xf86CVTMode() function 2021-08-06 11:29:29 +00:00
xf86Crtc.c hw/xfree86: Propagate physical dimensions from DRM connector 2021-06-15 13:21:11 +00:00
xf86Crtc.h Fix spelling/wording issues 2020-07-05 13:07:33 -07:00
xf86Cursors.c Add RandR leases with modesetting driver support [v6] 2018-02-27 12:39:50 -05:00
xf86DiDGA.c xserver: Unifdef HAVE_CONFIG_H 2017-03-23 13:19:51 -04:00
xf86EdidModes.c Fix spelling/wording issues 2020-07-05 13:07:33 -07:00
xf86Modes.c xfree86: Move xf86CVTMode() function 2021-08-06 11:29:29 +00:00
xf86Modes.h Eliminate the use of xf86Rename.h 2013-04-24 10:22:20 -07:00
xf86RandR12.c xfree86: Avoid crash in xf86RandR12CrtcSetGamma() memcpy path. 2021-10-08 21:37:53 +03:00
xf86RandR12.h xfree86: Hook up colormaps and RandR 1.2 gamma code v6 2016-07-28 10:12:05 +09:00
xf86Rotate.c xserver/output: rename some badly named variables/APIs. 2020-07-10 06:17:44 +10:00
xf86gtf.c xserver: Unifdef HAVE_CONFIG_H 2017-03-23 13:19:51 -04:00